Day 23: Part 2
Rewrite with a linked list and pointer cache because array allocation was optimistic at best Signed-off-by: James Griffin <james@unsupervised.ca>
This commit is contained in:
@@ -6,13 +6,8 @@ func Test_load_input(t *testing.T) {
|
||||
g := game{}
|
||||
g.load("32415")
|
||||
|
||||
if len(g.cups) != 5 {
|
||||
t.Logf("Expected 5 cups. Got %d", len(g.cups))
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if g.highestCup != 5 {
|
||||
t.Logf("Expected highest cup to be 5, found %d", g.highestCup)
|
||||
if g.cups != 5 {
|
||||
t.Logf("Expected 5 cups. Got %d", g.cups)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
@@ -21,17 +16,12 @@ func Test_10_moves(t *testing.T) {
|
||||
g := game{}
|
||||
g.load("389125467")
|
||||
|
||||
if len(g.cups) != 9 {
|
||||
t.Logf("Expected 9 cups. Got %d", len(g.cups))
|
||||
if g.cups != 9 {
|
||||
t.Logf("Expected 9 cups. Got %d", g.cups)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if g.highestCup != 9 {
|
||||
t.Logf("Expected highest cup to be 9, found %d", g.highestCup)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
tenMoves := g.play(10)
|
||||
tenMoves := g.play(10, true)
|
||||
if tenMoves != "92658374" {
|
||||
t.Logf("Expected \"92658374\" but found %q", tenMoves)
|
||||
t.FailNow()
|
||||
@@ -42,19 +32,31 @@ func Test_100_moves(t *testing.T) {
|
||||
g := game{}
|
||||
g.load("389125467")
|
||||
|
||||
if len(g.cups) != 9 {
|
||||
t.Logf("Expected 9 cups. Got %d", len(g.cups))
|
||||
if g.cups != 9 {
|
||||
t.Logf("Expected 9 cups. Got %d", g.cups)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if g.highestCup != 9 {
|
||||
t.Logf("Expected highest cup to be 9, found %d", g.highestCup)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
hundredMoves := g.play(100)
|
||||
hundredMoves := g.play(100, true)
|
||||
if hundredMoves != "67384529" {
|
||||
t.Logf("Expected \"67384529\" but found %q", hundredMoves)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_10million_moves(t *testing.T) {
|
||||
g := game{}
|
||||
g.milliload("389125467")
|
||||
|
||||
if g.cups != 1000000 {
|
||||
t.Logf("Expected 1000000 cups. Got %d", g.cups)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
g.play(10000000, false)
|
||||
starProduct := g.starProduct()
|
||||
if starProduct != 149245887792 {
|
||||
t.Logf("Expected 149245887792 but got produc %q", 149245887792)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user