Day 8 solution

This commit is contained in:
2021-12-08 14:51:00 +00:00
parent f2e471f2a4
commit b62022ff07
7 changed files with 503 additions and 0 deletions

58
eight/display_test.go Normal file
View File

@@ -0,0 +1,58 @@
package eight
import "testing"
func Test_read(t *testing.T) {
d := display{}
if err := d.load("test_input.txt"); err != nil {
t.Log(err)
t.FailNow()
}
if len(d.outputs) != 10 {
t.Logf("Expected 10 input sets, found %d", len(d.outputs))
t.Fail()
}
if len(d.outputs[0].signals) != 10 {
t.Logf("Expected 10 inputs, found %d", len(d.outputs[0].signals))
t.Fail()
}
if len(d.outputs[0].outputs) != 4 {
t.Logf("Expected 4 outputs, found %d", len(d.outputs[0].outputs))
t.Fail()
}
}
func Test_uniqueOutputs(t *testing.T) {
d := display{}
d.load("test_input.txt")
if count := d.uniqueOuputs(); count != 26 {
t.Logf("Expected 26 unique output digits, found %d", count)
t.Fail()
}
}
func Test_decode(t *testing.T) {
d := display{}
d.load("test_input.txt")
o := d.outputs[0]
if decoded := o.decode(); decoded != 8394 {
t.Logf("Expected output of 8394, decoded %d", decoded)
t.Fail()
}
}
func Test_outputSum(t *testing.T) {
d := display{}
d.load("test_input.txt")
if sum := d.outputSum(); sum != 61229 {
t.Logf("Expected outputs to sum to 61229, calculated %d", sum)
t.Fail()
}
}