|
| 1 | +package book_store |
| 2 | + |
| 3 | +import "core:testing" |
| 4 | + |
| 5 | +@(test) |
| 6 | +test_only_a_single_book :: proc(t: ^testing.T) { |
| 7 | + basket := [?]u32{1} |
| 8 | + result := total(basket[:]) |
| 9 | + expected: u32 = 800 |
| 10 | + testing.expect_value(t, result, expected) |
| 11 | +} |
| 12 | + |
| 13 | +@(test) |
| 14 | +test_two_of_the_same_book :: proc(t: ^testing.T) { |
| 15 | + basket := [?]u32{2, 2} |
| 16 | + result := total(basket[:]) |
| 17 | + expected: u32 = 1600 |
| 18 | + testing.expect_value(t, result, expected) |
| 19 | +} |
| 20 | + |
| 21 | +@(test) |
| 22 | +test_empty_basket :: proc(t: ^testing.T) { |
| 23 | + basket := [?]u32{} |
| 24 | + result := total(basket[:]) |
| 25 | + expected: u32 = 0 |
| 26 | + testing.expect_value(t, result, expected) |
| 27 | +} |
| 28 | + |
| 29 | +@(test) |
| 30 | +test_two_different_books :: proc(t: ^testing.T) { |
| 31 | + basket := [?]u32{1, 2} |
| 32 | + result := total(basket[:]) |
| 33 | + expected: u32 = 1520 |
| 34 | + testing.expect_value(t, result, expected) |
| 35 | +} |
| 36 | + |
| 37 | +@(test) |
| 38 | +test_three_different_books :: proc(t: ^testing.T) { |
| 39 | + basket := [?]u32{1, 2, 3} |
| 40 | + result := total(basket[:]) |
| 41 | + expected: u32 = 2160 |
| 42 | + testing.expect_value(t, result, expected) |
| 43 | +} |
| 44 | + |
| 45 | +@(test) |
| 46 | +test_four_different_books :: proc(t: ^testing.T) { |
| 47 | + basket := [?]u32{1, 2, 3, 4} |
| 48 | + result := total(basket[:]) |
| 49 | + expected: u32 = 2560 |
| 50 | + testing.expect_value(t, result, expected) |
| 51 | +} |
| 52 | + |
| 53 | +@(test) |
| 54 | +test_five_different_books :: proc(t: ^testing.T) { |
| 55 | + basket := [?]u32{1, 2, 3, 4, 5} |
| 56 | + result := total(basket[:]) |
| 57 | + expected: u32 = 3000 |
| 58 | + testing.expect_value(t, result, expected) |
| 59 | +} |
| 60 | + |
| 61 | +@(test) |
| 62 | +test_two_groups_of_four_is_cheaper_than_group_of_five_plus_group_of_three :: proc(t: ^testing.T) { |
| 63 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 5} |
| 64 | + result := total(basket[:]) |
| 65 | + expected: u32 = 5120 |
| 66 | + testing.expect_value(t, result, expected) |
| 67 | +} |
| 68 | + |
| 69 | +@(test) |
| 70 | +test_two_groups_of_four_is_cheaper_than_groups_of_five_and_three :: proc(t: ^testing.T) { |
| 71 | + basket := [?]u32{1, 1, 2, 3, 4, 4, 5, 5} |
| 72 | + result := total(basket[:]) |
| 73 | + expected: u32 = 5120 |
| 74 | + testing.expect_value(t, result, expected) |
| 75 | +} |
| 76 | + |
| 77 | +@(test) |
| 78 | +test_group_of_four_plus_group_of_two_is_cheaper_than_two_groups_of_three :: proc(t: ^testing.T) { |
| 79 | + basket := [?]u32{1, 1, 2, 2, 3, 4} |
| 80 | + result := total(basket[:]) |
| 81 | + expected: u32 = 4080 |
| 82 | + testing.expect_value(t, result, expected) |
| 83 | +} |
| 84 | + |
| 85 | +@(test) |
| 86 | +test_two_each_of_first_four_books_and_one_copy_each_of_rest :: proc(t: ^testing.T) { |
| 87 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 4, 5} |
| 88 | + result := total(basket[:]) |
| 89 | + expected: u32 = 5560 |
| 90 | + testing.expect_value(t, result, expected) |
| 91 | +} |
| 92 | + |
| 93 | +@(test) |
| 94 | +test_two_copies_of_each_book :: proc(t: ^testing.T) { |
| 95 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 4, 5, 5} |
| 96 | + result := total(basket[:]) |
| 97 | + expected: u32 = 6000 |
| 98 | + testing.expect_value(t, result, expected) |
| 99 | +} |
| 100 | + |
| 101 | +@(test) |
| 102 | +test_three_copies_of_first_book_and_two_each_of_remaining :: proc(t: ^testing.T) { |
| 103 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1} |
| 104 | + result := total(basket[:]) |
| 105 | + expected: u32 = 6800 |
| 106 | + testing.expect_value(t, result, expected) |
| 107 | +} |
| 108 | + |
| 109 | +@(test) |
| 110 | +test_three_each_of_first_two_books_and_two_each_of_remaining_books :: proc(t: ^testing.T) { |
| 111 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2} |
| 112 | + result := total(basket[:]) |
| 113 | + expected: u32 = 7520 |
| 114 | + testing.expect_value(t, result, expected) |
| 115 | +} |
| 116 | + |
| 117 | +@(test) |
| 118 | +test_four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three :: proc( |
| 119 | + t: ^testing.T, |
| 120 | +) { |
| 121 | + basket := [?]u32{1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5} |
| 122 | + result := total(basket[:]) |
| 123 | + expected: u32 = 10240 |
| 124 | + testing.expect_value(t, result, expected) |
| 125 | +} |
| 126 | + |
| 127 | +@(test) |
| 128 | +test_check_that_groups_of_four_are_created_properly_even_when_there_are_more_groups_of_three_than_groups_of_five :: proc( |
| 129 | + t: ^testing.T, |
| 130 | +) { |
| 131 | + basket := [?]u32{1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5} |
| 132 | + result := total(basket[:]) |
| 133 | + expected: u32 = 14560 |
| 134 | + testing.expect_value(t, result, expected) |
| 135 | +} |
| 136 | + |
| 137 | +@(test) |
| 138 | +test_one_group_of_one_and_four_is_cheaper_than_one_group_of_two_and_three :: proc(t: ^testing.T) { |
| 139 | + basket := [?]u32{1, 1, 2, 3, 4} |
| 140 | + result := total(basket[:]) |
| 141 | + expected: u32 = 3360 |
| 142 | + testing.expect_value(t, result, expected) |
| 143 | +} |
| 144 | + |
| 145 | +@(test) |
| 146 | +test_one_group_of_one_and_two_plus_three_groups_of_four_is_cheaper_than_one_group_of_each_size :: proc( |
| 147 | + t: ^testing.T, |
| 148 | +) { |
| 149 | + basket := [?]u32{1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5} |
| 150 | + result := total(basket[:]) |
| 151 | + expected: u32 = 10000 |
| 152 | + testing.expect_value(t, result, expected) |
| 153 | +} |
0 commit comments