forked from dcs-liberation/dcs_liberation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_daytimemap.py
107 lines (93 loc) · 3.77 KB
/
test_daytimemap.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from datetime import time
import pytest
from game.theater.daytimemap import DaytimeMap
from game.timeofday import TimeOfDay
def test_range_of() -> None:
m = DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=0), time(hour=5)),
)
assert m.range_of(TimeOfDay.Dawn) == (time(hour=6), time(hour=9))
assert m.range_of(TimeOfDay.Day) == (time(hour=9), time(hour=18))
assert m.range_of(TimeOfDay.Dusk) == (time(hour=18), time(hour=20))
assert m.range_of(TimeOfDay.Night) == (time(hour=0), time(hour=5))
def test_best_guess_time_of_day_at() -> None:
night_at_midnight = DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=0), time(hour=5)),
)
assert night_at_midnight.best_guess_time_of_day_at(time(hour=0)) == TimeOfDay.Night
assert night_at_midnight.best_guess_time_of_day_at(time(hour=5)) == TimeOfDay.Night
assert night_at_midnight.best_guess_time_of_day_at(time(hour=6)) == TimeOfDay.Dawn
assert night_at_midnight.best_guess_time_of_day_at(time(hour=7)) == TimeOfDay.Dawn
assert night_at_midnight.best_guess_time_of_day_at(time(hour=9)) == TimeOfDay.Day
assert night_at_midnight.best_guess_time_of_day_at(time(hour=10)) == TimeOfDay.Day
assert night_at_midnight.best_guess_time_of_day_at(time(hour=18)) == TimeOfDay.Dusk
assert night_at_midnight.best_guess_time_of_day_at(time(hour=19)) == TimeOfDay.Dusk
night_before_midnight = DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=22), time(hour=5)),
)
assert (
night_before_midnight.best_guess_time_of_day_at(time(hour=0)) == TimeOfDay.Night
)
assert (
night_before_midnight.best_guess_time_of_day_at(time(hour=1)) == TimeOfDay.Night
)
assert (
night_before_midnight.best_guess_time_of_day_at(time(hour=22))
== TimeOfDay.Night
)
assert (
night_before_midnight.best_guess_time_of_day_at(time(hour=23))
== TimeOfDay.Night
)
assert (
night_before_midnight.best_guess_time_of_day_at(time(hour=6)) == TimeOfDay.Dawn
)
night_after_midnight = DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=2), time(hour=5)),
)
assert (
night_after_midnight.best_guess_time_of_day_at(time(hour=0)) == TimeOfDay.Dusk
)
assert (
night_after_midnight.best_guess_time_of_day_at(time(hour=23)) == TimeOfDay.Dusk
)
assert (
night_after_midnight.best_guess_time_of_day_at(time(hour=2)) == TimeOfDay.Night
)
assert (
night_after_midnight.best_guess_time_of_day_at(time(hour=6)) == TimeOfDay.Dawn
)
def test_whole_hours_only() -> None:
with pytest.raises(ValueError):
DaytimeMap(
dawn=(time(minute=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=2), time(hour=5)),
)
with pytest.raises(ValueError):
DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(second=9), time(hour=18)),
dusk=(time(hour=18), time(hour=20)),
night=(time(hour=2), time(hour=5)),
)
with pytest.raises(ValueError):
DaytimeMap(
dawn=(time(hour=6), time(hour=9)),
day=(time(hour=9), time(hour=18)),
dusk=(time(hour=18), time(microsecond=20)),
night=(time(hour=2), time(hour=5)),
)