split-quality-measure-test.scm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. (use-modules
  2. ;; SRFI 64 for unit testing facilities
  3. (srfi srfi-64)
  4. ;; utils - the code to be tested
  5. (split-quality-measure)
  6. ;; Utilities for testing
  7. (utils test))
  8. (define PRECISION (expt 10 -9) #;(exact->inexact (expt 10 -9)))
  9. (test-begin "split-quality-measure-test")
  10. (test-group
  11. "gini-index"
  12. ;; if this test fails, then the gini index of perfect split is not 0.0
  13. (test-equal "gini-index-1"
  14. 0.0
  15. (gini-index
  16. (list
  17. (list #(0.5 2.2 3.3 4.4 0)
  18. #(0.5 2.2 3.3 4.4 0))
  19. (list #(1.1 2.2 3.3 4.4 1)
  20. #(1.1 2.2 3.3 4.4 1)))
  21. 4))
  22. ;; "gini index of worst split is not 1.0"
  23. (test-equal "gini-index-2"
  24. 1.0
  25. (gini-index (list
  26. (list #(1.1 2.2 3.3 4.4 0)
  27. #(1.1 2.2 3.3 4.4 1))
  28. (list #(1.1 2.2 3.3 4.4 0)
  29. #(1.1 2.2 3.3 4.4 1)))
  30. 4))
  31. ;; "gini index of split is not 0.888888888"
  32. (test-approximate "test for gini index calculation precision - 2"
  33. 0.888888888
  34. (gini-index (list
  35. (list #(1.1 2.2 3.3 4.4 0)
  36. #(1.1 2.2 3.3 4.4 1)
  37. #(1.1 2.2 3.3 4.4 1))
  38. (list #(1.1 2.2 3.3 4.4 0)
  39. #(1.1 2.2 3.3 4.4 0)
  40. #(1.1 2.2 3.3 4.4 1)))
  41. 4)
  42. PRECISION))
  43. (test-group
  44. "calc-proportion"
  45. (test-approximate "calc-proportion-1"
  46. 0.1875
  47. (calc-proportion
  48. (list
  49. #(2.3 1.2 7.2 1)
  50. #(213.1 34.6 786.1 0)
  51. #(1 1 1 1)
  52. #(4.0 -1.1 6.8 1))
  53. 0
  54. 3)
  55. PRECISION))
  56. (test-end "split-quality-measure-test")