e18e1b6db827ec93100484dd1bf081abee33d8f4
[scilab.git] / scilab / modules / ast / tests / unit_tests / divide.tst
1 // ============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // ============================================================================
7
8 // <-- JVM NOT MANDATORY -->
9
10 r = 2;
11 R = [1,2;3,4];
12 R3(:,:,1) = R;
13 R3(:,:,2) = R';
14 c = 1 + 2*%i;
15 C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
16 C3(:,:,1) = C;
17 C3(:,:,2) = C';
18
19 //double / double
20
21 //r / r
22 assert_checkalmostequal(r / r, 1);
23 //r / c
24 assert_checkalmostequal(r / c, 0.4-0.8*%i);
25 //c / r
26 assert_checkalmostequal(c / r, 0.5+%i);
27 //c / c
28 assert_checkalmostequal(c / c, 1);
29
30
31
32 //double / DOUBLE
33
34 //r / R
35 assert_checkalmostequal(r / R, [-4,2;3,-1]);
36 //r / C
37 assert_checkalmostequal(r / C, [-0.8+1.6*%i,0.4-0.8*%i;0.6-1.2*%i,-0.2+0.4*%i]);
38 //c / R
39 assert_checkalmostequal(c / R, [-2-4*%i,1+2*%i;1.5+3*%i,-0.5-1*%i]);
40 //c / C
41 assert_checkalmostequal(c / C, [-2,1;1.5,-0.5]);
42
43
44 //DOUBLE / double
45
46 //R / r
47 assert_checkalmostequal(R / r, [0.5,1;1.5,2]);
48 R3rref(:,:,1) = [0.5,1;1.5,2];
49 R3rref(:,:,2) = [0.5,1.5;1,2];
50 assert_checkalmostequal(R3 / r, R3rref);
51 //R / c
52 assert_checkalmostequal(R / c, [0.2-0.4*%i,0.4-0.8*%i;0.6-1.2*%i,0.8-1.6*%i]);
53 R3cref(:,:,1) = [0.2-0.4*%i,0.4-0.8*%i;0.6-1.2*%i,0.8-1.6*%i];
54 R3cref(:,:,2) = [0.2-0.4*%i,0.6-1.2*%i;0.4-0.8*%i,0.8-1.6*%i];
55 assert_checkalmostequal(R3 / c, R3cref);
56 //C / r
57 assert_checkalmostequal(C / r, [0.5+1*%i,1+2*%i;1.5+3*%i,2+4*%i]);
58 C3rref(:,:,1) = [0.5+1*%i,1+2*%i;1.5+3*%i,2+4*%i];
59 C3rref(:,:,2) = [0.5-1*%i,1.5-3*%i;1-2*%i,2-4*%i];
60 assert_checkalmostequal(C3 / r, C3rref);
61 //C / c
62 assert_checkalmostequal(C / c, [1,2;3,4]);
63 C3cref(:,:,1) = [1,2;3,4];
64 C3cref(:,:,2) = [-0.6-0.8*%i,-1.8-2.4*%i;-1.2-1.6*%i,-2.4-3.2*%i];
65 assert_checkalmostequal(C3 / c, C3cref);
66
67
68 //DOUBLE / DOUBLE
69
70 //R / R
71 assert_checkalmostequal(R / R, [1,0;0,1]);
72 //R / C
73 assert_checkalmostequal(R / C, [0.2-0.4*%i,0;0,0.2-0.4*%i]);
74 //C / R
75 assert_checkalmostequal(C / R, [1+2*%i,0;0,1+2*%i]);
76 //C / C
77 assert_checkalmostequal(C / C, [1,0;0,1]);