test-set.scm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (use-modules
  2. ;; for unit testing forms
  3. (srfi srfi-64))
  4. (use-modules
  5. ;; import the module to test
  6. (set))
  7. (test-begin "set-test")
  8. (test-group
  9. "set-test-group"
  10. (test-assert "set contains added items"
  11. (let* ([my-set (make-set '())]
  12. [added-item 'bla])
  13. (set-add! my-set added-item)
  14. (set-in? my-set added-item)))
  15. (test-assert "set contains multiple added items"
  16. (let ([my-set (make-set '())])
  17. (set-add! my-set 1)
  18. (set-add! my-set 2)
  19. (set-add! my-set 3)
  20. (and (set-in? my-set 1)
  21. (set-in? my-set 2)
  22. (set-in? my-set 3))))
  23. (test-assert "set does not contain removed items"
  24. (let ([my-set (make-set '())])
  25. (set-add! my-set 1)
  26. (set-add! my-set 2)
  27. (set-add! my-set 3)
  28. (set-remove! my-set 2)
  29. (and (set-in? my-set 1)
  30. (not (set-in? my-set 2))
  31. (set-in? my-set 3))))
  32. (test-assert "set union contains elements of all merged sets"
  33. (let ([my-set-1 (make-set '())]
  34. [my-set-2 (make-set '())])
  35. (set-add! my-set-1 1)
  36. (set-add! my-set-1 2)
  37. (set-add! my-set-1 3)
  38. (set-add! my-set-2 1)
  39. (set-add! my-set-2 5)
  40. (set-add! my-set-2 6)
  41. (let ([uni (set-union my-set-1 my-set-2)])
  42. (and (set-in? uni 1)
  43. (set-in? uni 2)
  44. (set-in? uni 3)
  45. (set-in? uni 5)
  46. (set-in? uni 6)))))
  47. (test-assert "set union of more than 2 sets contains elements of all merged sets"
  48. (let ([my-set-1 (make-set '())]
  49. [my-set-2 (make-set '())]
  50. [my-set-3 (make-set '())])
  51. (set-add! my-set-1 1)
  52. (set-add! my-set-1 2)
  53. (set-add! my-set-1 3)
  54. (set-add! my-set-2 1)
  55. (set-add! my-set-2 5)
  56. (set-add! my-set-2 6)
  57. (set-add! my-set-3 4)
  58. (let ([uni (set-union my-set-1 my-set-2 my-set-3)])
  59. (and (set-in? uni 1)
  60. (set-in? uni 2)
  61. (set-in? uni 3)
  62. (set-in? uni 4)
  63. (set-in? uni 5)
  64. (set-in? uni 6))))))
  65. (test-end "set-test")