common-list.test 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. ;;;; common-list.test --- tests guile's common list functions -*- scheme -*-
  2. ;;;; Copyright (C) 2000, 2001, 2004, 2006 Free Software Foundation, Inc.
  3. ;;;;
  4. ;;;; This library is free software; you can redistribute it and/or
  5. ;;;; modify it under the terms of the GNU Lesser General Public
  6. ;;;; License as published by the Free Software Foundation; either
  7. ;;;; version 3 of the License, or (at your option) any later version.
  8. ;;;;
  9. ;;;; This library is distributed in the hope that it will be useful,
  10. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;;;; Lesser General Public License for more details.
  13. ;;;;
  14. ;;;; You should have received a copy of the GNU Lesser General Public
  15. ;;;; License along with this library; if not, write to the Free Software
  16. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. (define-module (test-suite test-common-list)
  18. #:use-module (test-suite lib)
  19. #:use-module (ice-9 documentation)
  20. #:use-module (ice-9 common-list))
  21. ;;;
  22. ;;; miscellaneous
  23. ;;;
  24. (define (documented? object)
  25. (not (not (object-documentation object))))
  26. ;;;
  27. ;;; intersection
  28. ;;;
  29. (with-test-prefix "intersection"
  30. (pass-if "documented?"
  31. (documented? intersection))
  32. (pass-if "both arguments empty"
  33. (eq? (intersection '() '()) '()))
  34. (pass-if "first argument empty"
  35. (eq? (intersection '() '(1)) '()))
  36. (pass-if "second argument empty"
  37. (eq? (intersection '(1) '()) '()))
  38. (pass-if "disjoint arguments"
  39. (eq? (intersection '(1) '(2)) '()))
  40. (pass-if "equal arguments"
  41. (equal? (intersection '(1) '(1)) '(1)))
  42. (pass-if "reverse argument order"
  43. (equal? (intersection '(1 2 3) '(3 2 1)) '(1 2 3)))
  44. (pass-if "multiple matches in first list"
  45. (equal? (intersection '(1 1 2 2 3) '(3 2 1)) '(1 1 2 2 3)))
  46. (pass-if "multiple matches in second list"
  47. (equal? (intersection '(1 2 3) '(3 3 2 2 1)) '(1 2 3)))
  48. (pass-if "mixed arguments"
  49. (equal? (intersection '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(1 3 7 8)))
  50. )
  51. ;;;
  52. ;;; set-difference
  53. ;;;
  54. (with-test-prefix "set-difference"
  55. (pass-if "documented?"
  56. (documented? set-difference))
  57. (pass-if "both arguments empty"
  58. (eq? (set-difference '() '()) '()))
  59. (pass-if "first argument empty"
  60. (eq? (set-difference '() '(1)) '()))
  61. (pass-if "second argument empty"
  62. (equal? (set-difference '(1) '()) '(1)))
  63. (pass-if "disjoint arguments"
  64. (equal? (set-difference '(1) '(2)) '(1)))
  65. (pass-if "equal arguments"
  66. (eq? (set-difference '(1) '(1)) '()))
  67. (pass-if "reverse argument order"
  68. (eq? (set-difference '(1 2 3) '(3 2 1)) '()))
  69. (pass-if "multiple matches in first list"
  70. (eq? (set-difference '(1 1 2 2 3) '(3 2 1)) '()))
  71. (pass-if "multiple matches in second list"
  72. (eq? (set-difference '(1 2 3) '(3 3 2 2 1)) '()))
  73. (pass-if "mixed arguments"
  74. (equal? (set-difference '(1 2 3 5 7 8 10) '(1 3 4 7 8 9)) '(2 5 10)))
  75. )
  76. ;;;
  77. ;;; remove-if
  78. ;;;
  79. (with-test-prefix "remove-if"
  80. (pass-if "documented?"
  81. (documented? remove-if))
  82. (pass-if "empty list, remove all"
  83. (eq? (remove-if (lambda (x) #t) '()) '()))
  84. (pass-if "empty list, remove none"
  85. (eq? (remove-if (lambda (x) #f) '()) '()))
  86. (pass-if "non-empty list, remove all"
  87. (eq? (remove-if (lambda (x) #t) '(1 2 3 4)) '()))
  88. (pass-if "non-empty list, remove none"
  89. (equal? (remove-if (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
  90. (pass-if "non-empty list, remove some"
  91. (equal? (remove-if odd? '(1 2 3 4)) '(2 4)))
  92. )
  93. ;;;
  94. ;;; remove-if-not
  95. ;;;
  96. (with-test-prefix "remove-if-not"
  97. (pass-if "documented?"
  98. (documented? remove-if-not))
  99. (pass-if "empty list, remove all"
  100. (eq? (remove-if-not (lambda (x) #f) '()) '()))
  101. (pass-if "empty list, remove none"
  102. (eq? (remove-if-not (lambda (x) #t) '()) '()))
  103. (pass-if "non-empty list, remove all"
  104. (eq? (remove-if-not (lambda (x) #f) '(1 2 3 4)) '()))
  105. (pass-if "non-empty list, remove none"
  106. (equal? (remove-if-not (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
  107. (pass-if "non-empty list, remove some"
  108. (equal? (remove-if-not odd? '(1 2 3 4)) '(1 3)))
  109. )
  110. ;;;
  111. ;;; delete-if!
  112. ;;;
  113. (with-test-prefix "delete-if!"
  114. (pass-if "documented?"
  115. (documented? delete-if!))
  116. (pass-if "empty list, remove all"
  117. (eq? (delete-if! (lambda (x) #t) '()) '()))
  118. (pass-if "empty list, remove none"
  119. (eq? (delete-if! (lambda (x) #f) '()) '()))
  120. (pass-if "non-empty list, remove all"
  121. (eq? (delete-if! (lambda (x) #t) '(1 2 3 4)) '()))
  122. (pass-if "non-empty list, remove none"
  123. (equal? (delete-if! (lambda (x) #f) '(1 2 3 4)) '(1 2 3 4)))
  124. (pass-if "non-empty list, remove some"
  125. (equal? (delete-if! odd? '(1 2 3 4)) '(2 4)))
  126. )
  127. ;;;
  128. ;;; delete-if-not!
  129. ;;;
  130. (with-test-prefix "delete-if-not!"
  131. (pass-if "documented?"
  132. (documented? delete-if-not!))
  133. (pass-if "empty list, remove all"
  134. (eq? (delete-if-not! (lambda (x) #f) '()) '()))
  135. (pass-if "empty list, remove none"
  136. (eq? (delete-if-not! (lambda (x) #t) '()) '()))
  137. (pass-if "non-empty list, remove all"
  138. (eq? (delete-if-not! (lambda (x) #f) '(1 2 3 4)) '()))
  139. (pass-if "non-empty list, remove none"
  140. (equal? (delete-if-not! (lambda (x) #t) '(1 2 3 4)) '(1 2 3 4)))
  141. (pass-if "non-empty list, remove some"
  142. (equal? (delete-if-not! odd? '(1 2 3 4)) '(1 3)))
  143. )