Day 20: Part 1 and 2

Signed-off-by: James Griffin <james@unsupervised.ca>
This commit is contained in:
2020-12-20 14:09:14 -04:00
parent 34c05492c5
commit 85cfd4b736
6 changed files with 2518 additions and 3 deletions

75
twenty/day_twenty_test.go Normal file
View File

@@ -0,0 +1,75 @@
package twenty
import "testing"
func Test_tile_load(t *testing.T) {
m := message{}
m.load("sample.txt")
if len(m.tiles) != 9 {
t.Logf("Expected 9 tiles to be loaded, got %d", len(m.tiles))
t.FailNow()
}
if len(m.grid) != 3 && len(m.grid[0]) != 3 {
t.Logf("Expected a 3x3 grid, got %dx%d", len(m.grid), len(m.grid[0]))
t.FailNow()
}
}
func Test_arrange_tile(t *testing.T) {
m := message{}
m.load("sample.txt")
result := m.cornerProduct()
if result != 20899048083289 {
t.Logf("Expected a result of 20899048083289, got %d", result)
t.FailNow()
}
}
func Test_arrange_input(t *testing.T) {
m := message{}
m.load("input.txt")
result := m.cornerProduct()
if result == -1 {
t.Logf("Expected a result other than -1, got %d", result)
t.FailNow()
}
}
func Test_count_monsters(t *testing.T) {
m := message{}
m.load("sample.txt")
grid := m.layout()
if !grid {
t.Log("Expected a grid")
t.FailNow()
}
m.combineTiles()
m.alignMonsters()
result := m.seaMonsters()
if result != 2 {
t.Logf("Expected 2 monsters, found %d", result)
t.FailNow()
}
}
func Test_count_roughness(t *testing.T) {
m := message{}
m.load("sample.txt")
m.layout()
m.combineTiles()
m.alignMonsters()
result := m.countRoughness()
if result != 273 {
t.Logf("Expected 273 # not part of a monster, found %d", result)
t.FailNow()
}
}