62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
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)
|
|
moduleAsExpected := module.Name != "inv" || slices.Equal(module.OutputNames, []string{"b"})
|
|
if !moduleAsExpected {
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
func TestReadManyModules(t *testing.T) {
|
|
filename := "example1"
|
|
modules := ReadModules(filename)
|
|
t.Logf("> read example1:\n%+v", modules)
|
|
|
|
filename2 := "example2"
|
|
modules2 := ReadModules(filename2)
|
|
t.Logf("> read example2:\n%+v", modules2)
|
|
}
|
|
|
|
func TestConjunctionRegisterInputs(t *testing.T) {
|
|
filename := "example2"
|
|
modules := ReadModules(filename)
|
|
|
|
conjunctionInv := modules["inv"].(*Conjunction)
|
|
conjunctionInv.RegisterInputs(modules)
|
|
|
|
t.Logf("after registering inputs on $inv : %+v", conjunctionInv.MostRecentPulseFromInputIsHigh)
|
|
}
|