PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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--
 4class TEST_COMPLEX
 5
 6insert
 7   EIFFELTEST_TOOLS
 8   COMPLEX_CONSTANTS
 9   PLATFORM
10   REAL_PRECISION
11
12create {}
13   make
14
15feature {ANY}
16   make
17      do
18         set_precision(5);
19
20         a := a.one; b.set(-1.0, 0.0)
21         --("i=#(1), i^1=#(2), i^2=#(3)%N" # &i # &(i^1) # &(i^2)).print_on(std_output)
22         assert (i^1 = i)
23         assert (i^2 = complex(-1.0,0.0)) --b)
24
25         a.set(1.2, 1.1)
26         b.set(1.2, 2.1)
27         assert(a+i-i = a)
28         assert(a+i = b)
29
30         c.set(2.1, 3.3)
31         d.set(3.1, 3.3)
32         assert (b*c = complex(-4.41,8.37))
33
34         test_further
35      end
36
37   test_further
38      do
39         a.set(156.5, 17.0)
40         b.set(1.6E4, 9.4E-8)
41         c.set(17.0, 23.9) 
42         --("Testing with a="| &a | ", b=" | &b | ", c=" | &c|"%N").print_on(std_error);
43         test_plus
44         test_times
45         test_plus_and_times
46      end
47
48   test_plus
49      local
50         tmp1, tmp2: COMPLEX_64
51      do
52         label_assert ("c+0=c",   c + zero = c)
53         label_assert ("c+d=d+c", (c+d) = (d+c))
54         label_assert ("a+b+c=a+(b+c)", (a+b+c) ~= (a+(b+c)))
55         tmp1 := a+b+c
56         tmp2 := (a+(b+c))
57         label_assert ("tmp1=tmp2",tmp1 ~= tmp2)
58      end
59
60   test_times
61      do
62         label_assert ("a*1=a",a*one = a)
63         label_assert ("a*1~=a",(a*one) ~= a)
64         label_assert ("c*d ~= d*c)", (c*d) ~= (d*c))
65         label_assert ("a*b*c ~ a*(b*c)", (a*b*c) ~= (a*(b*c)))
66      end
67
68   test_plus_and_times
69      do
70         label_assert ("(a+b)*c = a*c + b*c", ((a+b)*c) ~= (a*c + b*c))
71      end
72
73   a,b,c,d: COMPLEX_64
74
75end -- class TEST_COMPLEX