units.scm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (use-modules (grump units si)
  2. (srfi srfi-64))
  3. (test-begin "units")
  4. (test-group "dimension-arithmetic"
  5. (test-equal area (* length length))
  6. (test-equal length (/ area length))
  7. (test-equal length (* velocity time))
  8. (test-equal force (* mass acceleration))
  9. (test-equal pressure (/ force area))
  10. (test-error (+ length length))
  11. (test-error (- time area)))
  12. (test-group "dimensions-of"
  13. (test-assert (length? m))
  14. (test-assert (mass? kg))
  15. (test-assert (velocity? (/ m s)))
  16. (test-assert (electric-current? (/ C s)))
  17. (test-assert (energy? (* N m)))
  18. (test-assert (pressure? (/ N (* m m))))
  19. (test-assert (compatible? (/ energy volume) (/ J (* m m m)))))
  20. (test-group "quantity-arithmetic"
  21. (test-equal (* m 50) (+ (* m 20) (* m 30)))
  22. (test-equal (* m 5025) (+ (* km 5) (* m 25)))
  23. (test-equal (* J 2) (* (* N 3) (* m 2/3)))
  24. (test-equal (* 2 J) (* 2 N m))
  25. (test-equal (* Hz 2) (+ (* Hz 1) (/ 1 s)))
  26. (test-equal (* Bq 2) (+ (* Bq 1) (/ 1 s)))
  27. (test-error (+ (* m -3) (* s 5)))
  28. (test-error (- (* kg 4) (* J 3)))
  29. (test-error (+ (* Bq 2) (* Hz 3))))
  30. (test-group "quantity-comparison"
  31. (test-assert (> (* m 20) (* m 10)))
  32. (test-assert (>= (* m 20) (* m 10)))
  33. (test-assert (< (* s 5) (* h 1)))
  34. (test-assert (<= (* kg 2) (* kg 2)))
  35. (test-assert (positive? (* s 3)))
  36. (test-assert (negative? (* s -3)))
  37. (test-assert (zero? (* s 0)))
  38. (test-error (< (* m -3) (* s 5)))
  39. (test-error (> (* kg 4) (* J 3))))
  40. (test-group "math-functions"
  41. (test-equal 1 (sin (* deg 90)))
  42. (test-equal (* m 2) (abs (* m 2)))
  43. (test-equal (* m 3) (abs (* m -3)))
  44. ;(test-equal 1 (sgn (* s 2)))
  45. ;(test-equal 0 (sgn (* s 0)))
  46. ;(test-equal -1 (sgn (* s -1)))
  47. (test-equal (* 8 m m m) (expt (* m 2) 3))
  48. (test-equal (* m 1) (sqrt (* m m)))
  49. (test-equal (/ pi 4) (atan (* m 3) (* m 3))))
  50. (test-end)