2018 day10 - gross 2D grid with moving objects

This commit is contained in:
alexchao26
2020-11-30 23:08:33 -05:00
parent a8b9389aad
commit 579d197a76
3 changed files with 601 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
/*
NOTE This is not an easily testable problem, these tests are for helper functions
*/
package main
import (
"testing"
)
func TestHasLoneIsland(t *testing.T) {
tests := []struct {
name string
grid [][2]int
want bool
}{
{"simple_all_one_island", [][2]int{
{1, 1},
{1, 2},
{2, 2},
{2, 1},
}, false},
{"simple_has_lone_cell", [][2]int{
{1, 1},
{1, 2},
{2, 2},
{2, 1},
{4, 1},
}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hasLoneIsland(tt.grid); got != tt.want {
t.Errorf("hasLoneIsland() = %v, want %v", got, tt.want)
}
})
}
}
func TestPrintGrid(t *testing.T) {
tests := []struct {
name string
positions [][2]int
want string
}{
{"horizontal line", [][2]int{
{0, 0},
{0, 1},
{0, 2},
{0, -1},
}, "0000\n"},
{"horizontal line with gap", [][2]int{
{0, 0},
{0, 1},
{0, 2},
{0, -1},
{0, -4},
{0, -5},
}, "00 0000\n"},
{"box", [][2]int{
{0, 0},
{0, 1},
{0, 2},
{1, 0},
{2, 0},
{2, 1},
{2, 2},
{1, 2},
}, "000\n0 0\n000\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := printGrid(tt.positions); got != tt.want {
t.Errorf("printGrid() = %q, want %q", got, tt.want)
}
})
}
}