day20, starting to read in data

with using tests as entry points for checking things
This commit is contained in:
efim
2023-12-20 07:35:51 +00:00
parent e771ac9d9b
commit 9dbc2ca205
4 changed files with 179 additions and 15 deletions

44
day20/modules_test.go Normal file
View File

@@ -0,0 +1,44 @@
package day20
import (
"slices"
"testing"
)
func TestParseFlipFlop(t *testing.T) {
flipFlopLine := "%a -> inv, con"
if !IsLineFlipFlop(flipFlopLine) {
t.Errorf("line '%s' should be flip flop\n", flipFlopLine)
}
module := ParseFlipFlop(flipFlopLine)
t.Logf("got module %+v\n", module)
}
func TestParseBroadcast(t *testing.T) {
broadcastLine := "broadcaster -> a, b, c"
if !isLineBroadcast(broadcastLine) {
t.Error("expected line to pass broadcast check")
}
module := ParseBroadcast(broadcastLine)
t.Logf("got module %+v\n", module)
if !slices.Equal(module.OutputNames, []string{"a", "b", "c"}) {
t.Errorf("got unexpected outputs: %+v\n", module.OutputNames)
}
}
func TestParseConjunction(t *testing.T) {
conjunctionLine := "&inv -> b"
if !isLineConjunction(conjunctionLine) {
t.Errorf("line '%s' should be flip flop\n", conjunctionLine)
}
module := ParseConjunction(conjunctionLine)
t.Logf("got module %+v\n", module)
if module.Name != "inv" || slices.Equal(module.OutputNames, []string{"b"}) {
t.Fail()
}
}
func TestPanic(t *testing.T) {
panic("hehe")
}