|
| 1 | +const std = @import("std"); |
| 2 | +const testing = std.testing; |
| 3 | + |
| 4 | +const raindrops = @import("raindrops.zig"); |
| 5 | + |
| 6 | +fn testConvert(comptime n: u32, expected: []const u8) !void { |
| 7 | + const buffer_size = 15; // The maximum length is for PlingPlangPlong |
| 8 | + var buffer: [buffer_size]u8 = undefined; |
| 9 | + const actual = raindrops.convert(&buffer, n); |
| 10 | + try testing.expectEqualStrings(expected, actual); |
| 11 | +} |
| 12 | + |
| 13 | +test "the sound for 1 is 1" { |
| 14 | + try testConvert(1, "1"); |
| 15 | +} |
| 16 | + |
| 17 | +test "the sound for 3 is Pling" { |
| 18 | + try testConvert(3, "Pling"); |
| 19 | +} |
| 20 | + |
| 21 | +test "the sound for 5 is Plang" { |
| 22 | + try testConvert(5, "Plang"); |
| 23 | +} |
| 24 | + |
| 25 | +test "the sound for 7 is Plong" { |
| 26 | + try testConvert(7, "Plong"); |
| 27 | +} |
| 28 | + |
| 29 | +test "the sound for 6 is Pling as it has a factor 3" { |
| 30 | + try testConvert(6, "Pling"); |
| 31 | +} |
| 32 | + |
| 33 | +test "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base" { |
| 34 | + try testConvert(8, "8"); |
| 35 | +} |
| 36 | + |
| 37 | +test "the sound for 9 is Pling as it has a factor 3" { |
| 38 | + try testConvert(9, "Pling"); |
| 39 | +} |
| 40 | + |
| 41 | +test "the sound for 10 is Plang as it has a factor 5" { |
| 42 | + try testConvert(10, "Plang"); |
| 43 | +} |
| 44 | + |
| 45 | +test "the sound for 14 is Plong as it has a factor of 7" { |
| 46 | + try testConvert(14, "Plong"); |
| 47 | +} |
| 48 | + |
| 49 | +test "the sound for 15 is PlingPlang as it has factors 3 and 5" { |
| 50 | + try testConvert(15, "PlingPlang"); |
| 51 | +} |
| 52 | + |
| 53 | +test "the sound for 21 is PlingPlong as it has factors 3 and 7" { |
| 54 | + try testConvert(21, "PlingPlong"); |
| 55 | +} |
| 56 | + |
| 57 | +test "the sound for 25 is Plang as it has a factor 5" { |
| 58 | + try testConvert(25, "Plang"); |
| 59 | +} |
| 60 | + |
| 61 | +test "the sound for 27 is Pling as it has a factor 3" { |
| 62 | + try testConvert(27, "Pling"); |
| 63 | +} |
| 64 | + |
| 65 | +test "the sound for 35 is PlangPlong as it has factors 5 and 7" { |
| 66 | + try testConvert(35, "PlangPlong"); |
| 67 | +} |
| 68 | + |
| 69 | +test "the sound for 49 is Plong as it has a factor 7" { |
| 70 | + try testConvert(49, "Plong"); |
| 71 | +} |
| 72 | + |
| 73 | +test "the sound for 52 is 52" { |
| 74 | + try testConvert(52, "52"); |
| 75 | +} |
| 76 | + |
| 77 | +test "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" { |
| 78 | + try testConvert(105, "PlingPlangPlong"); |
| 79 | +} |
| 80 | + |
| 81 | +test "the sound for 3125 is Plang as it has a factor 5" { |
| 82 | + try testConvert(3125, "Plang"); |
| 83 | +} |
0 commit comments