package main import ( "sort" "testing" ) // A combiner sums two amplifiers and commands nothing, so "combined" operation // is really two amplifiers that must be kept in the same state. Leaving one in // OPERATE while the other sits in STANDBY is exactly what must not happen — // the combiner would then see power on one input only. func TestAmpTargets(t *testing.T) { a := &App{} a.ampInsts = map[string]*ampInst{"left": {}, "right": {}, "third": {}} // Unlinked: only the amplifier that was clicked. if got := a.ampTargets("left", false); len(got) != 1 || got[0] != "left" { t.Errorf("unlinked = %v, want just [left]", got) } // Linked: every running amplifier, and the one clicked FIRST — a partial // failure should still have done what the operator asked before it stopped. got := a.ampTargets("right", true) if len(got) != 3 { t.Fatalf("linked = %v, want all three", got) } if got[0] != "right" { t.Errorf("clicked amplifier is %q, want it first", got[0]) } rest := append([]string{}, got[1:]...) sort.Strings(rest) if rest[0] != "left" || rest[1] != "third" { t.Errorf("rest = %v, want the other two", rest) } }