numbers.glisp 837 B

123456789101112131415161718192021222324252627282930
  1. ; test different ways of writing an integer
  2. (assert (= 24 0x18))
  3. (assert (= 63 0o77))
  4. (assert (= 13 0b1101))
  5. ; test shift operations
  6. (assert (= 4 (sll 1 2)))
  7. (assert (= -1 (sra -4 2)))
  8. (assert (= 2 (srl 4 1)))
  9. ; bitwise operations
  10. (assert (= 0b0001 (bit-and 0b0011 0b0101)))
  11. (assert (= 0b0111 (bit-or 0b0011 0b0101)))
  12. (assert (= 0b0110 (bit-xor 0b0011 0b0101)))
  13. (assert (= 0b1100 (bit-and (bit-not 0b0011) 0b1111)))
  14. ; arithmetic
  15. (assert (= 5 (+ 3 2)))
  16. (assert (= 2.4 (* 2 1.2)))
  17. (assert (= 2 (mod 5 3)))
  18. (assert (= 1.5 (/ 3 2)))
  19. (assert (= 1.2e3 (* 1.2e2 10)))
  20. (def selection '(1 1.0 0 0.0))
  21. (assert (= '(true true true true) (map number? selection)))
  22. (assert (= '(true false true false) (map int? selection)))
  23. (assert (= '(false true false true) (map float? selection)))
  24. (assert (= '(false false true true) (map zero? selection)))