package day20 import ( "log" "testing" ) func TestPropagateButtonPressExample1(t *testing.T) { filename := "example1" modules := ReadModules(filename) t.Log("got modules:\n", modules) low, high := PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("modules after single button press:\n", modules) success := low == 8 && high == 4 if !success { t.Errorf("expected low 8 got %d, high 4 got %d", low, high) } } func TestPropagateButtonPressExample2(t *testing.T) { filename := "example2" modules := ReadModules(filename) t.Log("got modules:\n", modules) InitStuffs(modules) low, high := PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("modules after single button press:\n", modules) success := low == 4 && high == 4 if !success { t.Errorf("expected low 4 got %d, high 4 got %d", low, high) } } func TestPropagateButtonPressExample2FourSteps(t *testing.T) { filename := "example2" modules := ReadModules(filename) t.Log("got modules:\n", modules) InitStuffs(modules) initialModulesState := ModulesState(modules) low, high := PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("#1 button press:\n", modules) success := low == 4 && high == 4 if !success { t.Errorf("expected low 4 got %d, high 4 got %d", low, high) } low, high = PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("#2 button press:\n", modules) success = low == 4 && high == 2 if !success { t.Errorf("expected low 4 got %d, high 2 got %d", low, high) } secondState := ModulesState(modules) if initialModulesState == secondState { t.Error("initial state should be different from second") } low, high = PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("#3 button press:\n", modules) success = low == 5 && high == 3 if !success { t.Errorf("expected low 5 got %d, high 3 got %d", low, high) } thirdState := ModulesState(modules) if initialModulesState == thirdState { t.Error("initial state should be different from third") } low, high = PropagateButtonPress(modules, 0) t.Logf("got low %d and high %d\n", low, high) t.Log("#4 button press:\n", modules) success = low == 4 && high == 2 if !success { t.Errorf("expected low 4 got %d, high 2 got %d", low, high) } lastState := ModulesState(modules) log.Print("initial modules state:\n", initialModulesState) log.Print("after 4 steps modules state:\n", lastState) if initialModulesState != lastState { t.Error("expected state to be same after 4 steps for example 2") } } func TestExample1TheQuestion(t *testing.T) { filename := "example1" modules := ReadModules(filename) InitStuffs(modules) low, high := Count10000ButtonPresses(modules) t.Log("got low and high: ", low, high) t.Log("response is: ", low * high) }