-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprt1_spec.rb
105 lines (78 loc) · 2.06 KB
/
prt1_spec.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
102
103
104
105
require_relative '../solve'
RSpec.describe Main do
describe '#lower' do
it 'selects lower half' do
rows = (0..127).to_a
result = Main.lower(rows)
expect(result).to eq((0..63).to_a)
end
it 'is a closure' do
rows = (0..127).to_a
result = Main.lower(Main.lower(rows))
expect(result).to eq((0..31).to_a)
end
end
describe '#upper' do
it 'selects upper half' do
rows = (0..127).to_a
result = Main.upper(rows)
expect(result).to eq((64..127).to_a)
end
end
describe '#translate_ticket_subset' do
it 'translates F to lower' do
ticket = 'F'
result = Main.translate_ticket_subset(ticket)
expect(result).to eq([Main.method(:lower)])
end
it 'translates L to lower' do
ticket = 'L'
result = Main.translate_ticket_subset(ticket)
expect(result).to eq([Main.method(:lower)])
end
it 'translates B to upper' do
ticket = 'B'
result = Main.translate_ticket_subset(ticket)
expect(result).to eq([Main.method(:upper)])
end
it 'translates R to upper' do
ticket = 'R'
result = Main.translate_ticket_subset(ticket)
expect(result).to eq([Main.method(:upper)])
end
it 'translates multiple' do
ticket = 'BFLR'
result = Main.translate_ticket_subset(ticket)
expected = [
Main.method(:upper),
Main.method(:lower),
Main.method(:lower),
Main.method(:upper),
]
expect(result).to eq(expected)
end
end
describe '#translate_ticket' do
it 'works' do
ticket = 'FBFBBFFRLR'
result = Main.translate_ticket(ticket)
expected = [
[
Main.method(:lower),
Main.method(:upper),
Main.method(:lower),
Main.method(:upper),
Main.method(:upper),
Main.method(:lower),
Main.method(:lower),
],
[
Main.method(:upper),
Main.method(:lower),
Main.method(:upper),
]
]
expect(result).to eq(expected)
end
end
end