|
1 | 1 | package raindrops |
2 | 2 |
|
3 | | -import "core:mem" |
4 | 3 | import "core:testing" |
5 | 4 |
|
6 | 5 | @(test) |
7 | 6 | /// description = the sound for 1 is 1 |
8 | 7 | test_the_sound_for_1_is_1 :: proc(t: ^testing.T) { |
9 | | - testing.expect_value(t, convert(1), "1") |
| 8 | + converted := convert(1) |
| 9 | + defer delete(converted) |
| 10 | + testing.expect_value(t, converted, "1") |
10 | 11 | } |
11 | 12 |
|
12 | 13 | @(test) |
13 | 14 | /// description = the sound for 3 is Pling |
14 | 15 | test_the_sound_for_3_is_pling :: proc(t: ^testing.T) { |
15 | | - testing.expect_value(t, convert(3), "Pling") |
| 16 | + converted := convert(3) |
| 17 | + defer delete(converted) |
| 18 | + testing.expect_value(t, converted, "Pling") |
16 | 19 | } |
17 | 20 |
|
18 | 21 | @(test) |
19 | 22 | /// description = the sound for 5 is Plang |
20 | 23 | test_the_sound_for_5_is_plang :: proc(t: ^testing.T) { |
21 | | - testing.expect_value(t, convert(5), "Plang") |
| 24 | + converted := convert(5) |
| 25 | + defer delete(converted) |
| 26 | + testing.expect_value(t, converted, "Plang") |
22 | 27 | } |
23 | 28 |
|
24 | 29 | @(test) |
25 | 30 | /// description = the sound for 7 is Plong |
26 | 31 | test_the_sound_for_7_is_plong :: proc(t: ^testing.T) { |
27 | | - testing.expect_value(t, convert(7), "Plong") |
| 32 | + converted := convert(7) |
| 33 | + defer delete(converted) |
| 34 | + testing.expect_value(t, converted, "Plong") |
28 | 35 | } |
29 | 36 |
|
30 | 37 | @(test) |
31 | 38 | /// description = the sound for 6 is Pling as it has a factor 3 |
32 | 39 | test_the_sound_for_6_is_pling_as_it_has_a_factor_3 :: proc(t: ^testing.T) { |
33 | | - testing.expect_value(t, convert(6), "Pling") |
| 40 | + converted := convert(6) |
| 41 | + defer delete(converted) |
| 42 | + testing.expect_value(t, converted, "Pling") |
34 | 43 | } |
35 | 44 |
|
36 | 45 | @(test) |
37 | 46 | /// description = 2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base |
38 | 47 | test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base :: proc( |
39 | 48 | t: ^testing.T, |
40 | 49 | ) { |
41 | | - testing.expect_value(t, convert(8), "8") |
| 50 | + converted := convert(8) |
| 51 | + defer delete(converted) |
| 52 | + testing.expect_value(t, converted, "8") |
42 | 53 | } |
43 | 54 |
|
44 | 55 | @(test) |
45 | 56 | /// description = the sound for 9 is Pling as it has a factor 3 |
46 | 57 | test_the_sound_for_9_is_pling_as_it_has_a_factor_3 :: proc(t: ^testing.T) { |
47 | | - testing.expect_value(t, convert(9), "Pling") |
| 58 | + converted := convert(9) |
| 59 | + defer delete(converted) |
| 60 | + testing.expect_value(t, converted, "Pling") |
48 | 61 | } |
49 | 62 |
|
50 | 63 | @(test) |
51 | 64 | /// description = the sound for 10 is Plang as it has a factor 5 |
52 | 65 | test_the_sound_for_10_is_plang_as_it_has_a_factor_5 :: proc(t: ^testing.T) { |
53 | | - testing.expect_value(t, convert(10), "Plang") |
| 66 | + converted := convert(10) |
| 67 | + defer delete(converted) |
| 68 | + testing.expect_value(t, converted, "Plang") |
54 | 69 | } |
55 | 70 |
|
56 | 71 | @(test) |
57 | 72 | /// description = the sound for 14 is Plong as it has a factor of 7 |
58 | 73 | test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7 :: proc(t: ^testing.T) { |
59 | | - testing.expect_value(t, convert(14), "Plong") |
| 74 | + converted := convert(14) |
| 75 | + defer delete(converted) |
| 76 | + testing.expect_value(t, converted, "Plong") |
60 | 77 | } |
61 | 78 |
|
62 | 79 | @(test) |
63 | 80 | /// description = the sound for 15 is PlingPlang as it has factors 3 and 5 |
64 | 81 | test_the_sound_for_15_is_pling_plang_as_it_has_factors_3_and_5 :: proc(t: ^testing.T) { |
65 | | - testing.expect_value(t, convert(15), "PlingPlang") |
| 82 | + converted := convert(15) |
| 83 | + defer delete(converted) |
| 84 | + testing.expect_value(t, converted, "PlingPlang") |
66 | 85 | } |
67 | 86 |
|
68 | 87 | @(test) |
69 | 88 | /// description = the sound for 21 is PlingPlong as it has factors 3 and 7 |
70 | 89 | test_the_sound_for_21_is_pling_plong_as_it_has_factors_3_and_7 :: proc(t: ^testing.T) { |
71 | | - testing.expect_value(t, convert(21), "PlingPlong") |
| 90 | + converted := convert(21) |
| 91 | + defer delete(converted) |
| 92 | + testing.expect_value(t, converted, "PlingPlong") |
72 | 93 | } |
73 | 94 |
|
74 | 95 | @(test) |
75 | 96 | /// description = the sound for 25 is Plang as it has a factor 5 |
76 | 97 | test_the_sound_for_25_is_plang_as_it_has_a_factor_5 :: proc(t: ^testing.T) { |
77 | | - testing.expect_value(t, convert(25), "Plang") |
| 98 | + converted := convert(25) |
| 99 | + defer delete(converted) |
| 100 | + testing.expect_value(t, converted, "Plang") |
78 | 101 | } |
79 | 102 |
|
80 | 103 | @(test) |
81 | 104 | /// description = the sound for 27 is Pling as it has a factor 3 |
82 | 105 | test_the_sound_for_27_is_pling_as_it_has_a_factor_3 :: proc(t: ^testing.T) { |
83 | | - testing.expect_value(t, convert(27), "Pling") |
| 106 | + converted := convert(27) |
| 107 | + defer delete(converted) |
| 108 | + testing.expect_value(t, converted, "Pling") |
84 | 109 | } |
85 | 110 |
|
86 | 111 | @(test) |
87 | 112 | /// description = the sound for 35 is PlangPlong as it has factors 5 and 7 |
88 | 113 | test_the_sound_for_35_is_plang_plong_as_it_has_factors_5_and_7 :: proc(t: ^testing.T) { |
89 | | - testing.expect_value(t, convert(35), "PlangPlong") |
| 114 | + converted := convert(35) |
| 115 | + defer delete(converted) |
| 116 | + testing.expect_value(t, converted, "PlangPlong") |
90 | 117 | } |
91 | 118 |
|
92 | 119 | @(test) |
93 | 120 | /// description = the sound for 49 is Plong as it has a factor 7 |
94 | 121 | test_the_sound_for_49_is_plong_as_it_has_a_factor_7 :: proc(t: ^testing.T) { |
95 | | - testing.expect_value(t, convert(49), "Plong") |
| 122 | + converted := convert(49) |
| 123 | + defer delete(converted) |
| 124 | + testing.expect_value(t, converted, "Plong") |
96 | 125 | } |
97 | 126 |
|
98 | 127 | @(test) |
99 | 128 | /// description = the sound for 52 is 52 |
100 | 129 | test_the_sound_for_52_is_52 :: proc(t: ^testing.T) { |
101 | | - testing.expect_value(t, convert(52), "52") |
| 130 | + converted := convert(52) |
| 131 | + defer delete(converted) |
| 132 | + testing.expect_value(t, converted, "52") |
102 | 133 | } |
103 | 134 |
|
104 | 135 | @(test) |
105 | 136 | /// description = the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7 |
106 | 137 | test_the_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7 :: proc(t: ^testing.T) { |
107 | | - testing.expect_value(t, convert(105), "PlingPlangPlong") |
| 138 | + converted := convert(105) |
| 139 | + defer delete(converted) |
| 140 | + testing.expect_value(t, converted, "PlingPlangPlong") |
108 | 141 | } |
109 | 142 |
|
110 | 143 | @(test) |
111 | 144 | /// description = the sound for 3125 is Plang as it has a factor 5 |
112 | 145 | test_the_sound_for_3125_is_plang_as_it_has_a_factor_5 :: proc(t: ^testing.T) { |
113 | | - testing.expect_value(t, convert(3125), "Plang") |
114 | | -} |
115 | | - |
116 | | -// This test is optional. If you are on the command line |
117 | | -// and want to check that your solution has no memory |
118 | | -// leak, uncomment this test. |
119 | | -// If you want to learn more about Odin's tracking |
120 | | -// allocator, you may watch this YouTube video: |
121 | | -// https://www.youtube.com/watch?v=dg6qogN8kIE |
122 | | -// @(test) |
123 | | -test_no_memory_leaks :: proc(t: ^testing.T) { |
124 | | - track: mem.Tracking_Allocator |
125 | | - mem.tracking_allocator_init(&track, context.allocator) |
126 | | - defer mem.tracking_allocator_destroy(&track) |
127 | | - context.allocator = mem.tracking_allocator(&track) |
128 | | - test_the_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7(t) |
129 | | - testing.expect_value(t, len(track.allocation_map), 0) |
130 | | - testing.expect_value(t, len(track.bad_free_array), 0) |
| 146 | + converted := convert(3125) |
| 147 | + defer delete(converted) |
| 148 | + testing.expect_value(t, converted, "Plang") |
131 | 149 | } |
0 commit comments