package main import "testing" type invalidTest struct { arg1, arg2 int expected []int } var invalidTests = []invalidTest{ {11, 22, []int{11, 22}}, {95, 115, []int{111, 99}}, {998, 1012, []int{999, 1010}}, {1188511880, 1188511890, []int{1188511885}}, {222220, 222224, []int{222222}}, {1698522, 1698528, []int{}}, {446443, 446449, []int{446446}}, {38593856, 38593862, []int{38593859}}, {565653, 565659, []int{565656}}, {824824821, 824824827, []int{824824824}}, {2121212118, 2121212124, []int{2121212121}}, } func TestGetInvalids(t *testing.T) { for _, test := range invalidTests { out := getInvalidsForRange(test.arg1, test.arg2) if len(out) != len(test.expected) { t.Errorf("Output %q not equal to expected %q", out, test.expected) } for i, got := range out { want := test.expected[i] if got != want { t.Errorf("Expected %d to be %d at position %d in %q", got, want, i, out) } } } } func TestIntPow(t *testing.T) { val := intPow(10, 1) if val != 10 { t.Errorf("Was expecting 10, not %d", val) } val = intPow(10, 2) if val != 100 { t.Errorf("Was expecting 100, not %d", val) } val = intPow(10, 3) if val != 1000 { t.Errorf("Was expecting 1000, not %d", val) } } func TestLargestPrefix(t *testing.T) { prefix, _ := largestPrefix("4444") if prefix != 44 { t.Errorf("Should have return prefix 44, not %d", prefix) } prefix, _ = largestPrefix("44444") if prefix != 99 { t.Errorf("Should have returned prefix 99, not %d", prefix) } }