77 solve_day_6 ,
88)
99
10+
1011@pytest .fixture
1112def day_6_test_input ():
1213 return [
1314 "Time: 7 15 30" ,
1415 "Distance: 9 40 200" ,
1516 ]
1617
18+
1719@pytest .fixture
1820def sample_race ():
1921 return Race (time = 7 , distance_to_beat = 9 )
2022
2123
24+ @pytest .fixture
25+ def sample_race_part_2 ():
26+ return Race (time = 71530 , distance_to_beat = 940200 )
27+
28+
2229@pytest .fixture
2330def sample_races ():
2431 return Races (
2532 Race (time = 7 , distance_to_beat = 9 ),
2633 Race (time = 15 , distance_to_beat = 40 ),
2734 Race (time = 30 , distance_to_beat = 200 ),
2835 )
29-
36+
3037
3138def test_race_initialization (sample_race ):
3239 assert sample_race .time == 7
3340 assert sample_race .distance_to_beat == 9
3441 assert sample_race .ways_to_win == 4
3542
43+
3644def test_race_compute_ways_to_win (sample_race ):
3745 sample_race ._compute_ways_to_win ()
3846 assert sample_race .ways_to_win == 4
3947
48+
4049def test_races_initialisation ():
4150 races = Races ()
4251 for race in races .races :
4352 print (race )
4453 assert races .races == []
4554
55+
4656def test_races_add_race (sample_race ):
4757 races = Races ()
4858 races .add_race (sample_race )
4959 assert races .races == [sample_race ]
5060
61+
5162def test_races_solve (sample_races ):
52- assert sample_races .solve () == math .prod ([4 ,8 , 9 ])
63+ assert sample_races .solve () == math .prod ([4 , 8 , 9 ])
5364
5465
55- def test_create_races (day_6_test_input , sample_races ):
56- test_races = create_races (day_6_test_input )
66+ def test_create_races_part_1 (day_6_test_input , sample_races ):
67+ test_races = create_races (day_6_test_input , part = 1 )
5768 assert test_races .n_races () == 3
58- for race , expected_race in zip (test_races .races ,sample_races .races ):
69+ for race , expected_race in zip (test_races .races , sample_races .races ):
5970 assert race .time == expected_race .time
6071 assert race .distance_to_beat == expected_race .distance_to_beat
6172 assert race .ways_to_win == expected_race .ways_to_win
6273
74+
75+ def test_create_races_part_2 (day_6_test_input , sample_race_part_2 ):
76+ test_races = create_races (day_6_test_input , part = 2 )
77+ assert test_races .n_races () == 1
78+ test_race = test_races .races [0 ]
79+ assert test_race .time == sample_race_part_2 .time
80+ assert test_race .distance_to_beat == sample_race_part_2 .distance_to_beat
81+ assert test_race .ways_to_win == sample_race_part_2 .ways_to_win
82+
83+
6384def test_solve_day_6 (day_6_test_input ):
64- assert solve_day_6 (day_6_test_input ) == 288
85+ assert solve_day_6 (day_6_test_input ) == ( 288 , 71503 )
0 commit comments