-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
test_secret_handshake.zig
81 lines (69 loc) · 3.41 KB
/
test_secret_handshake.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const std = @import("std");
const testing = std.testing;
const secret_handshake = @import("secret_handshake.zig");
test "wink for 1" {
const expected = &[_]secret_handshake.Signal{.wink};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 1);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "double blink for 10" {
const expected = &[_]secret_handshake.Signal{.double_blink};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 2);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "close your eyes for 100" {
const expected = &[_]secret_handshake.Signal{.close_your_eyes};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 4);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "jump for 1000" {
const expected = &[_]secret_handshake.Signal{.jump};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 8);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "combine two actions" {
const expected = &[_]secret_handshake.Signal{ .wink, .double_blink };
const actual = try secret_handshake.calculateHandshake(testing.allocator, 3);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "reverse two actions" {
const expected = &[_]secret_handshake.Signal{ .double_blink, .wink };
const actual = try secret_handshake.calculateHandshake(testing.allocator, 19);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "reversing one action gives the same action" {
const expected = &[_]secret_handshake.Signal{.jump};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 24);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "reversing no actions still gives no actions" {
const expected = &[_]secret_handshake.Signal{};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 16);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "all possible actions" {
const expected = &[_]secret_handshake.Signal{ .wink, .double_blink, .close_your_eyes, .jump };
const actual = try secret_handshake.calculateHandshake(testing.allocator, 15);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "reverse all possible actions" {
const expected = &[_]secret_handshake.Signal{ .jump, .close_your_eyes, .double_blink, .wink };
const actual = try secret_handshake.calculateHandshake(testing.allocator, 31);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}
test "do nothing for zero" {
const expected = &[_]secret_handshake.Signal{};
const actual = try secret_handshake.calculateHandshake(testing.allocator, 0);
defer testing.allocator.free(actual);
try testing.expectEqualSlices(secret_handshake.Signal, expected, actual);
}