package main import ( "reflect" "testing" ) type Cases struct { list []any oldPosition int newPosition int want []any } var cases = []Cases{ { list: []any{1, 2, 3, 4, 5, 6, 7, 8}, oldPosition: 5, newPosition: 2, want: []any{1, 2, 6, 3, 4, 5, 7, 8}, }, { list: []any{1, 2, 3, 4, 5, 6, 7, 8}, oldPosition: 7, newPosition: 0, want: []any{8, 1, 2, 3, 4, 5, 6, 7}, }, { list: []any{"zero", "one", "two", "three", "four", "five"}, oldPosition: 0, newPosition: 5, want: []any{"one", "two", "three", "four", "five", "zero"}, }, { list: []any{"zero", "one", "two", "three", "four", "five"}, oldPosition: 2, newPosition: 3, want: []any{"zero", "one", "three", "two", "four", "five"}, }, } func TestShuffleFuncOne(t *testing.T) { for i := range cases { t.Logf("Input list: %v", cases[i].list) t.Logf("We want '%v' to move to position %d", cases[i].list[cases[i].oldPosition], cases[i].newPosition) got := shuffleFuncOne(cases[i].list, cases[i].oldPosition, cases[i].newPosition) if !reflect.DeepEqual(cases[i].want, got) { t.Errorf("TEST FAILED: want: %v, got %v", cases[i].want, got) } else { t.Logf("TEST PASSED: got %v", got) } } } func TestShuffleFuncTwo(t *testing.T) { for i := range cases { t.Logf("Input list: %v", cases[i].list) t.Logf("We want '%v' to move to position %d", cases[i].list[cases[i].oldPosition], cases[i].newPosition) got := shuffleFuncTwo(cases[i].list, cases[i].oldPosition, cases[i].newPosition) if !reflect.DeepEqual(cases[i].want, got) { t.Errorf("TEST FAILED: want: %v, got %v", cases[i].want, got) } else { t.Logf("TEST PASSED: got %v", got) } } }