package year25 import ( "testing" ) func TestMod(t *testing.T) { a := -100 b := 100 t.Log(a % b) } func TestDial(t *testing.T) { type Args struct { From int Step int NextDial int Count int } type TestCase struct { Name string Args } args := func(from, step int) Args { a := Args{ From: from, Step: step, } a.NextDial, a.Count = simulateDial(from, step) return a } cases := []TestCase{ { Name: "from 50 add 10", Args: args(50, 10), }, { Name: "from 50 add -10", Args: args(50, -10), }, { Name: "from 50 add 50", Args: args(50, 50), }, { Name: "from 50 add 70", Args: args(50, 70), }, { Name: "from 50 add 150", Args: args(50, 150), }, { Name: "from 50 add 155", Args: args(50, 155), }, { Name: "from 50 add 10_000", Args: args(50, 10_000), }, { Name: "from 50 add -1", Args: args(50, -1), }, { Name: "from 50 add -10", Args: args(50, -10), }, { Name: "from 50 add -50", Args: args(50, -50), }, { Name: "from 50 add -70", Args: args(50, -70), }, { Name: "from 50 add -100", Args: args(50, -100), }, { Name: "from 50 add -150", Args: args(50, -150), }, { Name: "from 50 add -10_000", Args: args(50, -10_000), }, { Name: "from 50 add 10_000", Args: args(50, 10_000), }, { Name: "from 0 add 50", Args: args(0, 50), }, { Name: "from 0 add -50", Args: args(0, -50), }, { Name: "from 0 add 100", Args: args(0, 100), }, { Name: "from 0 add -100", Args: args(0, -100), }, { Name: "from 0 add 10_000", Args: args(0, 10_000), }, { Name: "from 0 add -10_000", Args: args(0, -10_000), }, { Name: "from 22 add -34", Args: args(22, -34), }, } for _, tc := range cases { t.Run(tc.Name, func(t *testing.T) { next, count := day1Advance(tc.From, tc.Step) if next != tc.NextDial { t.Errorf("next do not match got %d, want %d", next, tc.NextDial) } if count != tc.Count { t.Errorf("count do not match got %d, want %d", count, tc.Count) } if !t.Failed() { t.Log(tc.Name, "ok", "want:", count, "got:", count) } }) } } func simulateDial(dial int, value int) (int, int) { solution := int(0) for value < 0 { value += 1 dial -= 1 if dial == 0 { solution += 1 } if dial == -1 { dial = 99 } } for value > 0 { value -= 1 dial += 1 if dial == 100 { dial = 0 solution += 1 } } return dial, solution }