File: test_stopwatch.py

package info (click to toggle)
dart 6.13.2%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56,948 kB
  • sloc: cpp: 274,310; python: 3,973; xml: 1,272; sh: 404; makefile: 31
file content (50 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest
import dartpy as dart


def test_basics():
    sw = dart.common.Stopwatch()

    # Stopwatch is started by default
    assert sw.isStarted()
    assert dart.common.Stopwatch(True).isStarted()
    assert not dart.common.Stopwatch(False).isStarted()

    # Stop the stopwatch
    sw.stop()
    assert not sw.isStarted()

    # Elapsed time should be the same
    elapsed1 = sw.elapsedS()
    assert elapsed1 == sw.elapsedS()
    assert elapsed1 == sw.elapsedS()

    # Elapsed time monotonically increase while the stopwatch is running
    sw.start()
    assert sw.elapsedS() >= elapsed1
    assert sw.elapsedS() >= elapsed1

    # Starting a stopwatch already started doesn't have any effect
    sw.start()
    assert sw.isStarted()

    # Restting a started stopwatch resets the elapsed time but doesn't stop the
    # stopwatch
    sw.start()
    sw.reset()
    assert sw.isStarted()
    assert sw.elapsedS() >= 0.0
    assert sw.elapsedS() >= 0.0

    # Restting a stopped stopwatch resets the elapsed time but doesn't start the
    # stopwatch
    sw.stop()
    sw.reset()
    assert not sw.isStarted()
    assert sw.elapsedS() == pytest.approx(0.0)

    sw.print()


if __name__ == "__main__":
    pytest.main()