test-search.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. (import
  2. (except (rnrs base) map)
  3. (only (guile)
  4. lambda* λ
  5. ;; ports
  6. current-output-port
  7. simple-format)
  8. ;; SRFI 64 - unit testing forms
  9. (srfi srfi-64)
  10. ;; SRFI 43 - vector procs
  11. (srfi srfi-43)
  12. ;; SRFI 1 - list procs
  13. (srfi srfi-1)
  14. ;; custom libs
  15. (fslib)
  16. ;; tested module
  17. (search))
  18. (test-begin "search-test")
  19. (test-group
  20. "default comparators"
  21. (test-assert "default-string-comparator - 01"
  22. (not
  23. (equal? #f
  24. (default-string-comparator "I am a happy string!" "happy"))))
  25. (test-assert "default-string-comparator - 02"
  26. (not
  27. (equal? #f
  28. (default-string-comparator "hsk" "hsk"))))
  29. (test-assert "default-string-comparator - 03"
  30. (equal? #f (default-string-comparator "hsk" "hk")))
  31. (test-assert "default-number-comparator - 01"
  32. (default-number-comparator 3 3))
  33. (test-assert "default-number-comparator - 02"
  34. (default-number-comparator 2 2))
  35. (test-assert "default-number-comparator - 03"
  36. (not
  37. (default-number-comparator 1 3)))
  38. (test-assert "default-boolean-comparator - 01"
  39. (default-boolean-comparator #t "true"))
  40. (test-assert "default-boolean-comparator - 02"
  41. (default-boolean-comparator #t "#t"))
  42. (test-assert "default-boolean-comparator - 03"
  43. (not
  44. (default-boolean-comparator #t "false")))
  45. (test-assert "default-boolean-comparator - 04"
  46. (not
  47. (default-boolean-comparator #t "#f")))
  48. (test-assert "default-vector-comparator - 01"
  49. (default-vector-comparator #("a" "b" "c") "a"))
  50. (test-assert "default-vector-comparator - 02"
  51. (default-vector-comparator #("a" "b" "c") "c"))
  52. (test-assert "default-vector-comparator - 03"
  53. (default-vector-comparator #(#t #t #f) #f))
  54. (test-assert "default-vector-comparator - 04"
  55. (default-vector-comparator #(1 2 3) 2))
  56. (test-assert "default-vector-comparator - 05"
  57. (not
  58. (default-vector-comparator #(1 2 3) 4)))
  59. (test-assert "default-vector-comparator - 06"
  60. (not
  61. (default-vector-comparator #(#f #f #f) #t)))
  62. (test-assert "default-vector-comparator - 07"
  63. (not
  64. (default-vector-comparator #("a" "b" "c") "d")))
  65. (test-assert "make-general-comparator - 01"
  66. ((make-general-comparator) #(1 2 3) 2))
  67. (test-assert "make-general-comparator - 02"
  68. ((make-general-comparator) "a b c" "b"))
  69. (test-assert "make-general-comparator - 03"
  70. ((make-general-comparator) "a" "a"))
  71. (test-assert "make-general-comparator - 04"
  72. ((make-general-comparator) 3 3))
  73. (test-assert "make-general-comparator - 05"
  74. ((make-general-comparator) #(1 2 3) 2))
  75. (test-assert "make-general-comparator - 06"
  76. ((make-general-comparator) #(#f #t #f) #t))
  77. (test-assert "make-general-comparator - 07"
  78. (not
  79. ((make-general-comparator) #(#f #f #f) #t)))
  80. (test-assert "make-general-comparator - 08"
  81. (not
  82. ((make-general-comparator) #(1 2 3) 4)))
  83. (test-assert "make-general-comparator - 09"
  84. (not
  85. ((make-general-comparator) "hello world" "hallo")))
  86. (test-assert "make-general-comparator - 10"
  87. ((make-general-comparator) 1 "1"))
  88. (test-assert "default-fallback-comparator - 01"
  89. (default-fallback-comparator "hsk1" "hsk1"))
  90. (test-assert "default-fallback-comparator - 02"
  91. (default-fallback-comparator 1 1))
  92. (test-assert "default-fallback-comparator - 02"
  93. (default-fallback-comparator 2 2))
  94. (test-assert "default-fallback-comparator - 03"
  95. (not
  96. (default-fallback-comparator #(1 2) #(1 3)))))
  97. ;; Finish the testsuite, and report results.
  98. (test-end "search-test")