-
Notifications
You must be signed in to change notification settings - Fork 0
/
bombe_spec.rb
77 lines (64 loc) · 2 KB
/
bombe_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
require './bombe.rb'
describe Bombe do
it 'does shit' do
b = Bombe.testConfig
end
end
#this is a lot of work to test not very much...
describe PlugHalf do
context 'given some fake surroundings' do
let(:enigma) { double :enigma, :encipher_without_step => 7 }
let(:t_bank) { double :t_bank }
let(:d_board) { double :d_board }
it 'sends a letter through the enigma to the diagonal board' do
enigma.should_receive(:encipher_without_step).with(4)
d_board.should_receive(:set_diagonal_pair).with(t_bank, 7)
ph = PlugHalf.new(enigma, t_bank, d_board)
ph.encipher_and_set_diagonal_pair(4)
end
end
end
#again feels like I'm just testing implementation details
describe Bank do
context 'given some fake surroundings' do
let(:ph1) { double :plug_half }
let(:ph2) { double :plug_half }
it 'sends a letter to its connected plug halves' do
ph1.should_receive(:encipher_and_set_diagonal_pair).with(4)
ph2.should_receive(:encipher_and_set_diagonal_pair).with(4)
b = Bank.new
b.plug_halves << ph1
b.plug_halves << ph2
b.set_register(4)
end
it 'counts the number of live registers' do
b = Bank.new
expect(b.num_of_live_wires).to eq(0)
b.registers[1] = true
b.registers[4] = true
expect(b.num_of_live_wires).to eq(2)
end
end
end
describe DiagonalBoard do
before :each do
@db = DiagonalBoard.new
@db.add_plugs( [[1, 2, 16], [3, 4, 12], [2, 5, 8]] )
end
it 'has 26 banks' do
expect( @db.banks.count ).to eq(26)
end
it 'makes enigmas for plugs' do
expect(@db.enigmas[0].positions).to eq([16,0,0])
expect(@db.enigmas[1].positions).to eq([12,0,0])
end
it 'makes plug halves correctly' do
expect(@db.banks[1].plug_halves.count).to eq(1)
expect(@db.banks[2].plug_halves.count).to eq(2)
end
it 'sets diagonal pairs' do
@db.set_diagonal_pair(1, 5)
expect(@db.banks[1].registers[5]).to be_true
expect(@db.banks[5].registers[1]).to be_true
end
end