Skip to content

Commit

Permalink
IDE-151 Refactor Stopwatch.java to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayush2111 committed Mar 30, 2023
1 parent c17bd87 commit e246a02
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.test.utils

import junit.framework.TestCase.assertTrue
import org.catrobat.catroid.utils.Stopwatch
import org.junit.Test

class StopwatchTest {
@Test
fun getElapsedMilliseconds() {
val stopwatch = Stopwatch()
stopwatch.start()
Thread.sleep(100L)
val elapsed = stopwatch.getElapsedMilliseconds()
assertTrue(elapsed in 100L..199)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2023 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -20,17 +20,15 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.utils;
package org.catrobat.catroid.utils

public class Stopwatch {
class Stopwatch {
private var start: Long = 0
fun start() {
start = System.currentTimeMillis()
}

private long start;

public void start() {
start = System.currentTimeMillis();
}

public long getElapsedMilliseconds() {
return (System.currentTimeMillis() - start);
}
fun getElapsedMilliseconds(): Long {
return System.currentTimeMillis() - start
}
}

0 comments on commit e246a02

Please sign in to comment.