history_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package history
  2. import (
  3. "testing"
  4. )
  5. func TestCurrent(t *testing.T) {
  6. h := History[int]{}
  7. h.Add(1)
  8. current := h.Current()
  9. if current != 1 {
  10. t.Fatalf("current should be 1 but is %v", current)
  11. }
  12. }
  13. func TestBackForward(t *testing.T) {
  14. h := History[int]{}
  15. h.Add(1)
  16. h.Add(2)
  17. h.Back()
  18. back := h.Current()
  19. h.Forward()
  20. forward := h.Current()
  21. if back != 1 || forward != 2 {
  22. t.Fatalf("back should be 1 not %v, forward should be 2 not %v", back, forward)
  23. }
  24. }
  25. func TestIsEmpty(t *testing.T) {
  26. h := History[int]{}
  27. if !h.IsEmpty() {
  28. t.Fatalf("history should report empty when empty")
  29. }
  30. h.Add(1)
  31. if h.IsEmpty() {
  32. t.Fatalf("history is purporting to be empty when it shouldn't be")
  33. }
  34. }
  35. func TestBackSaturation(t *testing.T) {
  36. h := History[int]{}
  37. h.Add(1)
  38. h.Add(2)
  39. h.Back()
  40. h.Back()
  41. h.Back()
  42. current := h.Current()
  43. if current != 1 {
  44. t.Fatalf("current should be 1 not %v after back saturation", current)
  45. }
  46. }
  47. func TestForwardSaturation(t *testing.T) {
  48. h := History[int]{}
  49. h.Add(1)
  50. h.Add(2)
  51. h.Forward()
  52. h.Forward()
  53. current := h.Current()
  54. if current != 2 {
  55. t.Fatalf("current should be 2 not %v after forward saturation", current)
  56. }
  57. }
  58. func TestForwardDestruction(t *testing.T) {
  59. h := History[int]{}
  60. h.Add(1)
  61. h.Add(2)
  62. h.Back()
  63. h.Add(3)
  64. h.Forward()
  65. h.Forward()
  66. current := h.Current()
  67. if current != 3 {
  68. t.Fatalf("current should be 3 not %v after forward destruction", current)
  69. }
  70. }