package soko import ( "bytes" "testing" "github.com/stretchr/testify/assert" ) var levelBenchmark = `level: ._._._._._._._._._._._._._._._._._._._._ ._._._._._#_#_#_._._._._._._._._._._._._ ._._._._._#_#_#_._._._._._._._._._._._._ ._._._._._#_#_#_._._._._._._._._._._._._ ._._._#_#_#_#_#_#_._._._._._._._._._._._ ._._._#_._#_._._#_._._._._#X#_#_~_#_#_._ ._#_#_#_._#_._._#_._._._._._._._~_#_#_._ ._#_#B#_#_#B#_#_#_#_#_#_#_#_#_#_#_#_#_._ ._._._._._#_._._._#_._#@._._._._#_#_._._ ._._._._._#_#_#_#_#_._._._._._._._._._._ ._._._._._._._._._._._._._._._._._._._._ :level` var levelEasy = `level: ._._._._._._._._._._ ._#@#_#_#B#_~_#_#X._ ._._._._._._._._._._ :level` var level1 = `level: ._._._._._._._._._._ ._#_#_#_#_~_~_~_#_._ ._#_#_._#B~_~_#_#_._ ._#_#_#_#_~_~_~_#_._ ._#_#_._#B~_~_#_#_._ ._#@#_#_#_~_~_#_#X._ ._#_#_~_~_~_#_#_#_._ ._#_#_~_~_~_#_#_#_._ ._._._._._._._._._._ :level` var level2 = `level: ._._._._._._._._._._._._._._._._._._._._ ._._._._._#_#_#_._._._._._._._._._._._._ ._._._._._#B#_#_._._._._._._._._._._._._ ._._._._._#_#_#B._._._._._._._._._._._._ ._._._#_#_#B#_#B#_._._._._._._._._._._._ ._._._#_._#_._._#_._._._._#X#_~_~_~_#_._ ._#_#_#_._#_._._#_._._._._._._._~_~_#_._ ._#_#B#_#_#B#_#_#_#_#_#_#_#_#_#_~_#_#_._ ._._._._._#_._._._#_._#@._._._._#_#_._._ ._._._._._#_#_#_#_#_._._._._._._._._._._ ._._._._._._._._._._._._._._._._._._._._ :level` var level3 = `level: ._._._._._._._._._._ ._._._._._._._._._._ ._~_#_#_#_#B#_._._._ ._~_#B#_#_._#_._._._ ._~_._#_~_#_#_._._._ ._#X._#_~_#_._._._._ ._._#_#B#_#_._._._._ ._._#@#_._._._._._._ ._._._._._._._._._._ :level` var level4 = `level: ._._._._._._._._._._._._ ._._#_#_._._._._._._._._ ._._#_#B#_#B#@#_#_._._._ ._._#_#_#_#_#B#_#_._._._ ._._._._._._#_._._._._._ ._._._._._._#_._._._._._ ._._._._._._#B._._._._._ ._._._#_#_._#_._#_#_._._ ._#_#_#_#_~_#_#_#_#_#_._ ._#_._._#_._#_._#_._#_._ ._#_._#X~_._~_._~_._#_._ ._#_._._#_._#_._#_._#_._ ._#_#_#_#_#_~_#_#_#_#_._ ._._._._._._._._._._._._ :level` func mustParseLevel(s string) Level { l, err := ParseLevel(bytes.NewBufferString(s)) if err != nil { panic("couldn't parse level") } return l } func TestSolver(t *testing.T) { solve := func(s string) int { l := mustParseLevel(s) steps := Solve(l) return steps } assert.Equal(t, 7, solve(levelEasy)) assert.Equal(t, 35, solve(level1)) // assert.Equal(t, -1, solve(level2)) assert.Equal(t, 49, solve(level3)) // assert.Equal(t, -1, solve(level4)) } func BenchmarkSolver(b *testing.B) { l := mustParseLevel(levelBenchmark) for n := 0; n < b.N; n++ { Solve(l) } }