A simple polynomial calculator in lisp

tests.cl 1.5KB

1234567891011121314151617181920212223242526272829303132333435
  1. (require "poly.cl")
  2. (defun run-tests ()
  3. (if (equal
  4. (poly+ '(((x 2) 5)) '(((x 2) 3)))
  5. '(((x 2) 8)))
  6. (format t "5x^2 + 3x^2 ... passed - simple addition~%")
  7. (format t "5x^2 + 3x^2 ... failed - simple addition~%"))
  8. (if (equal
  9. (poly+ '(((x 2) 5) ((y 2) 6)) '(((x 2) 3) ((y 2) 3) ((z 3) 4)))
  10. '(((z 3) 4) ((x 2) 8) ((y 2) 9)))
  11. (format t "5x^2+6y^2 + 3x^2+3y^2+4z^3 ... passed - complex addition~%")
  12. (format t "5x^2+6y^2 + 3x^2+3y^2+4z^3 ... failed - complex addition~%"))
  13. (if (equal
  14. (poly- '(((x 2) 5)) '(((x 2) 3)))
  15. '(((x 2) 2)))
  16. (format t "5x^2 - 3x^2 ... passed - simple subtraction~%")
  17. (format t "5x^2 - 3x^2 ... failed - simple subtraction~%"))
  18. (if (equal
  19. (poly- '(((x 2) 5) ((y 2) 6)) '(((x 2) 3) ((y 2) 3) ((z 3) 4)))
  20. '(((z 3) -4) ((x 2) 2) ((y 2) 3)))
  21. (format t "5x^2+6y^2 - 3x^2+3y^2+4z^3 ... passed - complex subtraction~%")
  22. (format t "5x^2+6y^2 - 3x^2+3y^2+4z^3 ... failed - complex subtraction~%"))
  23. (if (equal
  24. (poly* '(((x 2) 5)) '(((x 2) 5)))
  25. '(((x 4) 25)))
  26. (format t "5x^2 * 5x^2 ... passed - simple multiplication~%")
  27. (format t "5x^2 * 5x^2 ... failed - simple multiplication~%"))
  28. (if (equal
  29. (poly* '(((x 2) 5) ((y 2) 1)) '(((x 1) 3) ((y 1) 1)))
  30. '(((X 3) 15) (((X Y) (2 1)) 5) (((Y X) (2 1)) 3) ((Y 3) 1)))
  31. (format t "(5x^2+y^2) * (3x + y) ... passed - complex multiplication~%")
  32. (format t "(5x^2+y^2) * (3x + y) ... failed - complex multiplication~%"))
  33. )