/test/lib/numeric/complex/test_complex.e

http://github.com/tybor/Liberty · Specman e · 75 lines · 57 code · 13 blank · 5 comment · 0 complexity · 3313ffb63dc7e232b80b60327d766fe4 MD5 · raw file

  1. -- This file is part of Liberty Eiffel Compiler Tools and Libraries.
  2. -- See the Copyright notice at the end of this file.
  3. --
  4. class TEST_COMPLEX
  5. insert
  6. EIFFELTEST_TOOLS
  7. COMPLEX_CONSTANTS
  8. PLATFORM
  9. REAL_PRECISION
  10. create {}
  11. make
  12. feature {ANY}
  13. make
  14. do
  15. set_precision(5);
  16. a := a.one; b.set(-1.0, 0.0)
  17. --("i=#(1), i^1=#(2), i^2=#(3)%N" # &i # &(i^1) # &(i^2)).print_on(std_output)
  18. assert (i^1 = i)
  19. assert (i^2 = complex(-1.0,0.0)) --b)
  20. a.set(1.2, 1.1)
  21. b.set(1.2, 2.1)
  22. assert(a+i-i = a)
  23. assert(a+i = b)
  24. c.set(2.1, 3.3)
  25. d.set(3.1, 3.3)
  26. assert (b*c = complex(-4.41,8.37))
  27. test_further
  28. end
  29. test_further
  30. do
  31. a.set(156.5, 17.0)
  32. b.set(1.6E4, 9.4E-8)
  33. c.set(17.0, 23.9)
  34. --("Testing with a="| &a | ", b=" | &b | ", c=" | &c|"%N").print_on(std_error);
  35. test_plus
  36. test_times
  37. test_plus_and_times
  38. end
  39. test_plus
  40. local
  41. tmp1, tmp2: COMPLEX_64
  42. do
  43. label_assert ("c+0=c", c + zero = c)
  44. label_assert ("c+d=d+c", (c+d) = (d+c))
  45. label_assert ("a+b+c=a+(b+c)", (a+b+c) ~= (a+(b+c)))
  46. tmp1 := a+b+c
  47. tmp2 := (a+(b+c))
  48. label_assert ("tmp1=tmp2",tmp1 ~= tmp2)
  49. end
  50. test_times
  51. do
  52. label_assert ("a*1=a",a*one = a)
  53. label_assert ("a*1~=a",(a*one) ~= a)
  54. label_assert ("c*d ~= d*c)", (c*d) ~= (d*c))
  55. label_assert ("a*b*c ~ a*(b*c)", (a*b*c) ~= (a*(b*c)))
  56. end
  57. test_plus_and_times
  58. do
  59. label_assert ("(a+b)*c = a*c + b*c", ((a+b)*c) ~= (a*c + b*c))
  60. end
  61. a,b,c,d: COMPLEX_64
  62. end -- class TEST_COMPLEX