aretheythesame_test.go 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package aretheythesame
  2. import "testing"
  3. type check struct {
  4. name string
  5. one, two []int
  6. expected bool
  7. }
  8. func TestComp(t *testing.T) {
  9. checks := []check{
  10. {
  11. "Good",
  12. []int{121, 144, 19, 161, 19, 144, 19, 11},
  13. []int{121, 14641, 20736, 361, 25921, 361, 20736, 361},
  14. true,
  15. },
  16. {
  17. "132 is not 11^2",
  18. []int{121, 144, 19, 161, 19, 144, 19, 11},
  19. []int{132, 14641, 20736, 361, 25921, 361, 20736, 361},
  20. false,
  21. },
  22. {
  23. "36100 is not the square of any member of a",
  24. []int{121, 144, 19, 161, 19, 144, 19, 11},
  25. []int{121, 14641, 20736, 36100, 25921, 361, 20736, 361},
  26. false,
  27. },
  28. {
  29. "Bad pair",
  30. []int{4, 4},
  31. []int{1, 31},
  32. false,
  33. },
  34. {
  35. "Empty and null",
  36. []int{},
  37. nil,
  38. false,
  39. },
  40. }
  41. for _, check := range checks {
  42. actual := Comp(check.one, check.two);
  43. if actual != check.expected {
  44. t.Errorf("%s: expected %v got %v", check.name, check.expected, actual)
  45. }
  46. }
  47. }