-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_8_tests.rb
101 lines (92 loc) · 2.13 KB
/
day_8_tests.rb
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'minitest/autorun'
require './day_8'
class Day8Test < Minitest::Test
def test_rect
starting_screen = create_screen(7,3)
expected = [
["#","#","#",".",".",".","."],
["#","#","#",".",".",".","."],
[".",".",".",".",".",".","."]
]
assert_equal expected, rect(3, 2, starting_screen)
end
def test_rotate_row
starting_screen = [
["#",".","#",".",".",".","."],
["#","#","#",".",".",".","."],
[".","#",".",".",".",".","."]
]
expected = [
[".",".",".",".","#",".","#"],
["#","#","#",".",".",".","."],
[".","#",".",".",".",".","."]
]
assert_equal expected, rotate_row(0, 4, starting_screen)
end
def test_rotate_column
test_cases = [
{
starting_screen: [
["#","#","#",".",".",".","."],
["#","#","#",".",".",".","."],
[".",".",".",".",".",".","."]
],
a: 1,
b: 1,
expected: [
["#",".","#",".",".",".","."],
["#","#","#",".",".",".","."],
[".","#",".",".",".",".","."]
]
},
{
starting_screen: [
[".",".",".",".","#",".","#"],
["#","#","#",".",".",".","."],
[".","#",".",".",".",".","."]
],
a: 1,
b: 1,
expected: [
[".","#",".",".","#",".","#"],
["#",".","#",".",".",".","."],
[".","#",".",".",".",".","."]
]
}
]
test_cases.each do |ex|
assert_equal ex[:expected], rotate_column(ex[:a], ex[:b], ex[:starting_screen])
end
end
def test_parse_instructions
test_cases = [
{
line: "rect 1x1",
expected: {
command: :rect,
a: 1,
b: 1
}
},
{
line: "rotate row y=0 by 2",
expected: {
command: :rotate_row,
a: 0,
b: 2
}
},
{
line: "rotate column x=32 by 1",
expected: {
command: :rotate_column,
a: 32,
b: 1
}
}
]
test_cases.each do |ex|
assert_equal ex[:expected], parse_instruction(ex[:line])
end
end
end