-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday-19-test.rb
58 lines (51 loc) · 1.67 KB
/
day-19-test.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
require 'minitest/autorun'
require './day-19-helper'
describe "TestCase" do
describe "Array\#custom_replace" do
it "should replace" do
x = [1, 2, 3, 4]
expected_x = [1, 'asdf', 4]
x.custom_replace(1,2, 'asdf').must_equal(expected_x)
end
end
describe "String\#get_all_indices" do
it "should do it!!" do
"asdfasdf".get_all_indices('as').must_equal([0,4])
end
it "should yield results when given block" do
"asdfasdf".get_all_indices('as') do |value|
assert([0, 4].include?(value), "Yielded values must be 0 or 4")
end
end
end
describe "Day19\#results" do
it "should work for simple input production" do
productions = {"H" => ["OH"]}
start = "HOH"
result = Day19.new(productions, start).results()
result.must_equal(["OHOH", "HOOH"])
end
it "should work for complex input productions" do
productions = {"H" => ["OH", "HO"], "O" => ["HH"]}
start = "HOH"
result = Day19.new(productions, start).results()
result.must_equal(["OHOH", "HOOH", "HOHO", "HHHH"])
end
end
describe "Day19\#smallest_production_length" do
it "should return length of smallest production starting from 'e' to reach 'HOH'" do
productions = {"H" => ["OH", "HO"], "O" => ["HH"], "e" => ["H", "O"]}
start = "HOH"
result = Day19.new(productions, start).smallest_production_length
result.must_equal(3)
end
end
describe "Day19\#smallest_production_length_by_reduction" do
it "should return length of smallest reduction from 'HOH' -> 'e'" do
productions = {"H" => ["OH", "HO"], "O" => ["HH"], "e" => ["H", "O"]}
start = "HOH"
result = Day19.new(productions, start).smallest_production_length_by_reduction
result.must_equal(3)
end
end
end