Exercism: Go version of the 'Secret Handshake' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
873 B

9 years ago
  1. package secret
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. var tests = []struct {
  7. code int
  8. h []string
  9. }{
  10. {1, []string{"wink"}},
  11. {2, []string{"double blink"}},
  12. {4, []string{"close your eyes"}},
  13. {8, []string{"jump"}},
  14. {3, []string{"wink", "double blink"}},
  15. {19, []string{"double blink", "wink"}},
  16. {31, []string{"jump", "close your eyes", "double blink", "wink"}},
  17. {0, nil},
  18. {-1, nil},
  19. {32, nil},
  20. {33, []string{"wink"}},
  21. }
  22. func TestHandshake(t *testing.T) {
  23. for _, test := range tests {
  24. h := Handshake(test.code)
  25. // use len() to allow either nil or empty list, because
  26. // they are not equal by DeepEqual
  27. if len(h) == 0 && len(test.h) == 0 {
  28. continue
  29. }
  30. if !reflect.DeepEqual(h, test.h) {
  31. t.Fatalf("Handshake(%d) = %v, want %v.", test.code, h, test.h)
  32. }
  33. }
  34. }
  35. func BenchmarkHandshake(b *testing.B) {
  36. for i := 0; i < b.N; i++ {
  37. Handshake(31)
  38. }
  39. }