mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 12:45:10 +02:00
2018 day10 - gross 2D grid with moving objects
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user