vec.scm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (use-modules (basket))
  2. (define (test-vec name)
  3. (test-group
  4. name
  5. (test-group
  6. "vec?"
  7. (test-func "" (vec? '(1 . 0)) #t)
  8. (test-func "" (vec? '(420.69 . 4/3)) #t)
  9. (test-func "" (vec? '(1 . a)) #f)
  10. (test-func "" (vec? 0) #f)
  11. (test-func "" (vec? 'a) #f))
  12. (test-group
  13. "vec-add"
  14. (test-func "" (vec-add) '(0 . 0))
  15. (test-func "" (vec-add '(1 . 3)) '(1 . 3))
  16. (test-func "" (vec-add '(1 . 3) '(-3 . 2)) '(-2 . 5))
  17. (test-func "" (vec-add '(1 . 3) '(-3 . 2) '(1 . 1)) '(-1 . 6)))
  18. (test-group
  19. "vec-sub"
  20. (test-func "" (vec-sub) '(0 . 0))
  21. (test-func "" (vec-sub '(1 . 3)) '(-1 . -3))
  22. (test-func "" (vec-sub '(1 . 3) '(-3 . 2)) '(4 . 1))
  23. (test-func "" (vec-sub '(1 . 3) '(-3 . 2) '(1 . 1)) '(3 . 0)))
  24. (test-group
  25. "vec-mult"
  26. (test-func "" (vec-mult '(0 . 0) 1) '(0 . 0))
  27. (test-func "" (vec-mult '(1 . 2) 1) '(1 . 2))
  28. (test-func "" (vec-mult '(1 . 2) 0) '(0 . 0))
  29. (test-func "" (vec-mult '(1 . 2) -1) '(-1 . -2))
  30. (test-func "" (vec-mult '(1 . 2) 2) '(2 . 4))
  31. (test-func "" (vec-mult '(1 . 2) 1/2) '(1/2 . 1)))
  32. (test-group
  33. "vec-div"
  34. (test-func "" (vec-div '(0 . 0) 1) '(0 . 0))
  35. (test-func "" (vec-div '(1 . 2) 1) '(1 . 2))
  36. (test-func "" (vec-div '(1 . 2) -1) '(-1 . -2))
  37. (test-func "" (vec-div '(1 . 2) 2) '(1/2 . 1))
  38. (test-func "" (vec-div '(1 . 2) 1/2) '(2 . 4)))
  39. (test-group
  40. "vec-dot"
  41. (test-func "" (vec-dot '(0 . 0) '(1 . 1)) 0)
  42. (test-func "" (vec-dot '(4 . 4) '(1 . 1)) 8))))