|
| 1 | +const std = @import("std"); |
| 2 | +const testing = std.testing; |
| 3 | + |
| 4 | +const etl = @import("etl.zig"); |
| 5 | +const transform = etl.transform; |
| 6 | + |
| 7 | +test "single letter" { |
| 8 | + var legacy = std.AutoHashMap(i5, []const u8).init(testing.allocator); |
| 9 | + try legacy.put(1, "A"); |
| 10 | + var actual = try transform(testing.allocator, legacy); |
| 11 | + legacy.deinit(); |
| 12 | + |
| 13 | + try testing.expectEqual(1, actual.count()); |
| 14 | + try testing.expectEqual(1, actual.get('a')); |
| 15 | + actual.deinit(); |
| 16 | +} |
| 17 | + |
| 18 | +test "single score with multiple letters" { |
| 19 | + var legacy = std.AutoHashMap(i5, []const u8).init(testing.allocator); |
| 20 | + try legacy.put(1, "AEIOU"); |
| 21 | + var actual = try transform(testing.allocator, legacy); |
| 22 | + legacy.deinit(); |
| 23 | + |
| 24 | + try testing.expectEqual(5, actual.count()); |
| 25 | + try testing.expectEqual(1, actual.get('a')); |
| 26 | + try testing.expectEqual(1, actual.get('e')); |
| 27 | + try testing.expectEqual(1, actual.get('i')); |
| 28 | + try testing.expectEqual(1, actual.get('o')); |
| 29 | + try testing.expectEqual(1, actual.get('u')); |
| 30 | + actual.deinit(); |
| 31 | +} |
| 32 | + |
| 33 | +test "multiple scores with multiple letters" { |
| 34 | + var legacy = std.AutoHashMap(i5, []const u8).init(testing.allocator); |
| 35 | + try legacy.put(1, "AE"); |
| 36 | + try legacy.put(2, "DG"); |
| 37 | + var actual = try transform(testing.allocator, legacy); |
| 38 | + legacy.deinit(); |
| 39 | + |
| 40 | + try testing.expectEqual(4, actual.count()); |
| 41 | + try testing.expectEqual(1, actual.get('a')); |
| 42 | + try testing.expectEqual(2, actual.get('d')); |
| 43 | + try testing.expectEqual(1, actual.get('e')); |
| 44 | + try testing.expectEqual(2, actual.get('g')); |
| 45 | + actual.deinit(); |
| 46 | +} |
| 47 | + |
| 48 | +test "multiple scores with differing numbers of letters" { |
| 49 | + var legacy = std.AutoHashMap(i5, []const u8).init(testing.allocator); |
| 50 | + try legacy.put(1, "AEIOULNRST"); |
| 51 | + try legacy.put(10, "QZ"); |
| 52 | + try legacy.put(2, "DG"); |
| 53 | + try legacy.put(3, "BCMP"); |
| 54 | + try legacy.put(4, "FHVWY"); |
| 55 | + try legacy.put(5, "K"); |
| 56 | + try legacy.put(8, "JX"); |
| 57 | + var actual = try transform(testing.allocator, legacy); |
| 58 | + legacy.deinit(); |
| 59 | + |
| 60 | + try testing.expectEqual(26, actual.count()); |
| 61 | + try testing.expectEqual(1, actual.get('a')); |
| 62 | + try testing.expectEqual(3, actual.get('b')); |
| 63 | + try testing.expectEqual(3, actual.get('c')); |
| 64 | + try testing.expectEqual(2, actual.get('d')); |
| 65 | + try testing.expectEqual(1, actual.get('e')); |
| 66 | + try testing.expectEqual(4, actual.get('f')); |
| 67 | + try testing.expectEqual(2, actual.get('g')); |
| 68 | + try testing.expectEqual(4, actual.get('h')); |
| 69 | + try testing.expectEqual(1, actual.get('i')); |
| 70 | + try testing.expectEqual(8, actual.get('j')); |
| 71 | + try testing.expectEqual(5, actual.get('k')); |
| 72 | + try testing.expectEqual(1, actual.get('l')); |
| 73 | + try testing.expectEqual(3, actual.get('m')); |
| 74 | + try testing.expectEqual(1, actual.get('n')); |
| 75 | + try testing.expectEqual(1, actual.get('o')); |
| 76 | + try testing.expectEqual(3, actual.get('p')); |
| 77 | + try testing.expectEqual(10, actual.get('q')); |
| 78 | + try testing.expectEqual(1, actual.get('r')); |
| 79 | + try testing.expectEqual(1, actual.get('s')); |
| 80 | + try testing.expectEqual(1, actual.get('t')); |
| 81 | + try testing.expectEqual(1, actual.get('u')); |
| 82 | + try testing.expectEqual(4, actual.get('v')); |
| 83 | + try testing.expectEqual(4, actual.get('w')); |
| 84 | + try testing.expectEqual(8, actual.get('x')); |
| 85 | + try testing.expectEqual(4, actual.get('y')); |
| 86 | + try testing.expectEqual(10, actual.get('z')); |
| 87 | + actual.deinit(); |
| 88 | +} |
0 commit comments