Skip to content

Commit

Permalink
Add benchmark to day8 part one
Browse files Browse the repository at this point in the history
  • Loading branch information
qselle committed Dec 9, 2023
1 parent b48c28e commit 90ad6bb
Showing 1 changed file with 79 additions and 4 deletions.
83 changes: 79 additions & 4 deletions day8/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"reflect"
"testing"
)
Expand Down Expand Up @@ -121,9 +122,83 @@ func TestStepsToReachEnd(t *testing.T) {
},
}
for _, test := range input {
actual := test.Maps.StepsToReachEnd()
if actual != test.Expected {
t.Errorf("Expected %v, got %v", test.Expected, actual)
}
t.Run(fmt.Sprintf("expected_steps_%d", test.Expected), func(t *testing.T) {
actual := test.Maps.StepsToReachEnd()
if actual != test.Expected {
t.Errorf("Expected %v, got %v", test.Expected, actual)
}
})
}
}

func BenchmarkStepsToReachEnd(b *testing.B) {

input := []struct {
Expected int
Maps Maps
}{
{
Expected: 2,
Maps: Maps{
Directions: []string{"R", "L"},
Nodes: map[string]Node{
"AAA": {
Left: "BBB",
Right: "CCC",
},
"BBB": {
Left: "DDD",
Right: "EEE",
},
"CCC": {
Left: "ZZZ",
Right: "GGG",
},
"DDD": {
Left: "DDD",
Right: "DDD",
},
"EEE": {
Left: "EEE",
Right: "EEE",
},
"GGG": {
Left: "GGG",
Right: "GGG",
},
"ZZZ": {
Left: "ZZZ",
Right: "ZZZ",
},
},
},
},
{
Expected: 6,
Maps: Maps{
Directions: []string{"L", "L", "R"},
Nodes: map[string]Node{
"AAA": {
Left: "BBB",
Right: "BBB",
},
"BBB": {
Left: "AAA",
Right: "ZZZ",
},
"ZZZ": {
Left: "ZZZ",
Right: "ZZZ",
},
},
},
},
}
for _, test := range input {
b.Run(fmt.Sprintf("expected_steps_%d", test.Expected), func(b *testing.B) {
for i := 0; i < b.N; i++ {
test.Maps.StepsToReachEnd()
}
})
}
}

0 comments on commit 90ad6bb

Please sign in to comment.