tree-test.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. (use-modules
  2. ;; SRFI 64 for unit testing facilities
  3. (srfi srfi-64)
  4. ;; utils - the code to be tested
  5. (tree)
  6. (dataset))
  7. (test-begin "tree-test")
  8. (test-group
  9. "make-leaf-node"
  10. (test-equal "make-leaf-node-1"
  11. (make-leaf-node (list #(3.771244718 1.784783929 0)
  12. #(2.728571309 1.169761413 0)
  13. #(4.678319846 2.81281357 0)))
  14. (make-node (list #(3.771244718 1.784783929 0)
  15. #(2.728571309 1.169761413 0)
  16. #(4.678319846 2.81281357 0))
  17. 'none
  18. 'none
  19. empty-dataset
  20. empty-dataset)))
  21. (test-group
  22. "make-leaf-node-from-split-node"
  23. (test-equal "make-leaf-node-from-split-node-1"
  24. (make-leaf-node-from-split-node
  25. (make-node (list #(2.3 1.0 4.0 0)
  26. #(2.0 1.0 3.0 1)
  27. #(2.3 1.0 3.0 1)
  28. #(2.0 1.0 3.0 1)
  29. #(2.4 1.0 3.0 1))
  30. 2
  31. 4.0
  32. (make-leaf-node (list #(2.0 1.0 3.0 1)
  33. #(2.3 1.0 3.0 1)
  34. #(2.0 1.0 3.0 1)
  35. #(2.4 1.0 3.0 1)))
  36. (make-leaf-node (list #(2.3 1.0 4.0 0)))))
  37. (make-leaf-node (list #(2.3 1.0 4.0 0)
  38. #(2.0 1.0 3.0 1)
  39. #(2.3 1.0 3.0 1)
  40. #(2.0 1.0 3.0 1)
  41. #(2.4 1.0 3.0 1)))))
  42. (test-group
  43. "leaf-node?"
  44. (test-assert "leaf-node?-1"
  45. (leaf-node? (make-leaf-node (list #(5.0 6.0 0)
  46. #(7.0 8.0 1)))))
  47. (test-assert "leaf-node?-2"
  48. (not
  49. (leaf-node? (make-node (list #(5.0 6.0 0)
  50. #(7.0 8.0 1))
  51. 0
  52. 5.0
  53. (make-leaf-node (list #(5.0 6.0 0)))
  54. (make-leaf-node (list #(7.0 8.0 1)))))))
  55. (test-assert "leaf-node?-3"
  56. (let ([node (make-node (list #(3.771244718 1.784783929 0)
  57. #(2.728571309 1.169761413 0)
  58. #(4.678319846 2.81281357 1))
  59. 0
  60. 4.678319846
  61. (make-leaf-node (list #(3.771244718 1.784783929 0)
  62. #(2.728571309 1.169761413 0)))
  63. (make-leaf-node (list #(4.678319846 2.81281357 1))))])
  64. (and (leaf-node? (node-left node))
  65. (leaf-node? (node-right node))))))
  66. (test-group
  67. "last-split-node?"
  68. (test-assert "last-split-node?-1"
  69. (not (last-split-node? (make-leaf-node (list #(3.771244718 1.784783929 0)
  70. #(2.728571309 1.169761413 0)
  71. #(4.678319846 2.81281357 1))))))
  72. (test-assert "last-split-node?-2"
  73. (last-split-node? (make-node (list #(3.771244718 1.784783929 0)
  74. #(2.728571309 1.169761413 0)
  75. #(4.678319846 2.81281357 1))
  76. 0
  77. 4.678319846
  78. (make-leaf-node (list #(3.771244718 1.784783929 0)
  79. #(2.728571309 1.169761413 0)))
  80. (make-leaf-node (list #(4.678319846 2.81281357 1)))))))
  81. (test-end "tree-test")