FunctionRacerProblemsRace

Stopwatch in Ticks

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Stopwatch that measures time in whole ticks. The methods that take now receive the current time, and now never decreases from one call to the next. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor and for clear.

Example 1

Stopwatch()
press_start(2) returns true
read_ticks(5) returns 3
press_stop(9) returns 7
press_start(9) returns true
press_start(10) returns false
read_ticks(12) returns 10
press_stop(15) returns 6
read_ticks(20) returns 13

The first run lasts from 2 to 9, so 7 ticks; at time 5 it had run 3. The second start at 10 is ignored because the watch is running. The second run lasts 6, for a total of 13.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems