main_test.go 684 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestReportSafety(t *testing.T) {
  6. safe := []struct {
  7. Name string
  8. Report []int
  9. }{
  10. {"Safe 1", []int{7, 6, 4, 2, 1}},
  11. {"Safe 2", []int{1, 3, 6, 7, 9}},
  12. }
  13. unsafe := []struct {
  14. Name string
  15. Report []int
  16. }{
  17. {"Exceeds local bound 1", []int{1, 2, 7, 8, 9}},
  18. {"Exceeds local bound 2", []int{9, 7, 6, 2, 1}},
  19. {"Not monotonic", []int{1, 3, 2, 4, 5}},
  20. {"Not strict monotonic", []int{8, 6, 4, 4, 1}},
  21. }
  22. for _, s := range safe {
  23. if !isSafe(s.Report) {
  24. t.Errorf("Safe report %#v found unsafe", s.Name)
  25. }
  26. }
  27. for _, u := range unsafe {
  28. if isSafe(u.Report) {
  29. t.Errorf("Unsafe report %#v found safe", u.Name)
  30. }
  31. }
  32. }