-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day03Test.groovy
85 lines (67 loc) · 2.45 KB
/
Day03Test.groovy
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
package be.vreijsenj.aoc.days
import kotlin.ranges.IntRange
import spock.lang.Specification
class Day03Test extends Specification {
def "returns the sum of part numbers"() {
given: "the engine schematic"
def input = [
"467..114..",
"...*......",
"..35..633.",
"......#...",
"617*......",
".....+.58.",
"..592.....",
"......755.",
"...\$.*....",
".664.598.."
]
when: "the part numbers are identified"
def result = new Day03().runPartOne(input)
then: "the sum matches the example answer"
result == 4361
}
def "returns the sum of all gear ratios"() {
given: "the engine schematic"
def input = [
"467..114..",
"...*......",
"..35..633.",
"......#...",
"617*......",
".....+.58.",
"..592.....",
"......755.",
"...\$.*....",
".664.598.."
]
when: "the gear ratios are identified"
def result = new Day03().runPartTwo(input)
then: "the sum matches the example answer"
result == 467835
}
def "reads numbers from schematic line"() {
given: "an engine schematic line"
def line = "467..114.."
when: "numbers are read"
def result = EngineSchematicLine.parse(line)
then: "the numbers and ranges are returned"
result.numbers.size() == 2
result.numbers.first.value == 467
result.numbers.first.location.equals new IntRange(0, 2)
result.numbers.last.value == 114
result.numbers.last.location.equals new IntRange(5, 7)
}
def "reads symbols from schematic line"() {
given: "an engine schematic line"
def line = "...\$.*...."
when: "numbers are read"
def result = EngineSchematicLine.parse(line)
then: "the numbers and ranges are returned"
result.symbols.size() == 2
result.symbols.first.value == "\$"
result.symbols.first.location.equals 3
result.symbols.last.value == "*"
result.symbols.last.location.equals 5
}
}