csv-utils-test.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (use-modules
  2. ;; SRFI 64 for unit testing facilities
  3. (srfi srfi-64)
  4. ;; csv-utils - the code to be tested
  5. (utils csv)
  6. (utils os))
  7. (test-begin "csv-utils")
  8. (test-group
  9. "all-rows"
  10. (test-equal "all-rows-1"
  11. (list #("2.771244718" "1.784783929" "0")
  12. #("1.728571309" "1.169761413" "0")
  13. #("3.678319846" "2.81281357" "0")
  14. #("3.961043357" "2.61995032" "0")
  15. #("2.999208922" "2.209014212" "0")
  16. #("7.497545867" "3.162953546" "1")
  17. #("9.00220326" "3.339047188" "1")
  18. #("7.444542326" "0.476683375" "1")
  19. #("10.12493903" "3.234550982" "1")
  20. #("6.642287351" "3.319983761" "1"))
  21. (all-rows
  22. (path-join "test" "resources" "csv-with-leading-and-trailing-whitespace.csv")
  23. #:converters
  24. (list (list (lambda (val) (string-trim-both val char-set:whitespace)))
  25. (list (lambda (val) (string-trim-both val char-set:whitespace)))
  26. (list (lambda (val) (string-trim-both val char-set:whitespace))))))
  27. (test-equal "all-rows-2"
  28. (list #(-2.771244718 "1.784783929" "0")
  29. #(-1.728571309 "1.169761413" "0")
  30. #(-3.678319846 "2.81281357" "0")
  31. #(-3.961043357 "2.61995032" "0")
  32. #(-2.999208922 "2.209014212" "0")
  33. #(-7.497545867 "3.162953546" "1")
  34. #(-9.00220326 "3.339047188" "1")
  35. #(-7.444542326 "0.476683375" "1")
  36. #(-10.12493903 "3.234550982" "1")
  37. #(-6.642287351 "3.319983761" "1"))
  38. (all-rows
  39. (path-join "test" "resources" "csv-with-leading-and-trailing-whitespace.csv")
  40. #:converters
  41. (list (list (lambda (val) (string-trim-both val char-set:whitespace))
  42. string->number
  43. (lambda (num) (* -1 num)))
  44. (list (lambda (val) (string-trim-both val char-set:whitespace)))
  45. (list (lambda (val) (string-trim-both val char-set:whitespace)))))))
  46. (test-group
  47. "read-dsv-from-file"
  48. (test-equal "read-dsv-from-file-1"
  49. '((" 2.771244718" "1.784783929" "0")
  50. ("1.728571309" "1.169761413" "0 ")
  51. ("3.678319846" "2.81281357" "0")
  52. (" 3.961043357" "2.61995032" "0")
  53. ("2.999208922" "2.209014212" "0 ")
  54. ("7.497545867" "3.162953546" "1")
  55. (" 9.00220326" "3.339047188" "1")
  56. ("7.444542326" "0.476683375" "1 ")
  57. ("10.12493903" "3.234550982" "1")
  58. (" 6.642287351" "3.319983761" "1"))
  59. (read-dsv-from-file "test/resources/csv-with-leading-and-trailing-whitespace.csv")))
  60. (test-end "csv-utils")