-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay02Test.groovy
57 lines (46 loc) · 2.19 KB
/
Day02Test.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
package be.vreijsenj.aoc.days
import spock.lang.Specification
class Day02Test extends Specification {
def "parses the game input correctly"() {
given: "the game input"
def input = "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"
when: "parsing"
def game = Game.parse(input)
then: "the result is stored in a Game object"
game instanceof Game
game.id == "1"
game.sets.size() == 3
game.sets.first.blue == 3
game.sets.first.red == 4
game.sets.first.green == 0
}
def "returns the possible games given the bag contents"() {
given: "the game sets, and bag content"
def bagContent = new Bag(12, 13, 14)
def games = [
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green",
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue",
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red",
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red",
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
]
when: "the games are played"
def result = new Day02().runPartOne(games, bagContent)
then: "the sum of the possible game ids matches the example answer"
result == 8
}
def "returns the sum of the power of the minimum set of cubes"() {
given: "the game sets"
def games = [
"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green",
"Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue",
"Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red",
"Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red",
"Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
]
when: "the games are played"
def result = new Day02().runPartTwo(games)
then: "the sum of the power of the minimum set of cubes matches the example answer"
result == 2286
}
}