Opened 10 months ago
Closed 9 months ago
#6 closed enhancement (fixed)
unit tests needed for class Phase.py
Reported by: | Enrico Schwass | Owned by: | frankl |
---|---|---|---|
Priority: | major | Milestone: | Version 1.0 |
Component: | Testing | Version: | 1.0 |
Keywords: | Cc: |
Description
Below are possiblepytest
tests for the Phase
class:
Autogenerated by ChatGPT
`python
import pytest
from phase import Phase
def test_phase_initialization():
phase = Phase("Warm-up", 300)
assert phase.title == "Warm-up"
assert phase.duration == 300
assert phase.state == "initial"
assert phase.time_left == 300
def test_phase_str_representation():
phase = Phase("Warm-up", 300)
expected_str = "-->Warm-up\nDuration=300\n"
assert str(phase) == expected_str
def test_phase_start():
phase = Phase("Warm-up", 300)
phase.start()
assert phase.state == "running"
assert phase.running() is True
def test_phase_pause():
phase = Phase("Warm-up", 300)
phase.start()
phase.pause()
assert phase.state == "paused"
assert phase.paused() is True
def test_phase_abort():
phase = Phase("Warm-up", 300)
phase.abort()
assert phase.state == "finished"
assert phase.finished() is True
def test_phase_tick():
phase = Phase("Warm-up", 300)
phase.start()
phase.tick(60)
assert phase.time_left == 240
assert phase.state == "running"
def test_phase_tick_to_completion():
phase = Phase("Warm-up", 300)
phase.start()
phase.tick(300)
assert phase.time_left == 0
assert phase.finished() is True
def test_phase_tick_beyond_completion():
phase = Phase("Warm-up", 300)
phase.start()
phase.tick(350)
assert phase.time_left == 0
assert phase.finished() is True
`
### Explanation:
- Initialization Test (
test_phase_initialization
): This checks that when aPhase
object is created, all the attributes are correctly initialized. - String Representation Test (
test_phase_str_representation
): Verifies that the__str__
method returns the expected string format. - State Transition Tests (
test_phase_start
,test_phase_pause
,test_phase_abort
): These tests check that thestart
,pause
, andabort
methods correctly change the state of the phase. - Running and Finished State Tests (
test_phase_running
,test_phase_finished
): Ensure the boolean methods for checking state work correctly. - Tick Tests (
test_phase_tick
,test_phase_tick_to_completion
,test_phase_tick_beyond_completion
): These tests validate that thetick
method correctly decrements thetime_left
and appropriately changes the state when the timer reaches zero.
You can run these tests using pytest
to ensure the correctness of the Phase
class.
Change History (2)
comment:1 by , 10 months ago
Milestone: | → Version 1.0 |
---|---|
Version: | → 1.0 |
comment:2 by , 9 months ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
tests added