fix divide Sparse by Double
[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 SP = sparse([1,2;4,5;3,10],[1,2,3]);
19 SPC = sparse([1,2;4,5;3,10],[1,2,3]) * ( 1 + 4*%i);
20
21 //double / double
22
23 //r / r
24 assert_checkalmostequal(r / r, 1);
25 //r / c
26 assert_checkalmostequal(r / c, 0.4-0.8*%i);
27 //c / r
28 assert_checkalmostequal(c / r, 0.5+%i);
29 //c / c
30 assert_checkalmostequal(c / c, 1);
31
32
33
34 //double / DOUBLE
35
36 //r / R
37 assert_checkalmostequal(r / R, [-4,2;3,-1]);
38 //r / C
39 assert_checkalmostequal(r / C, [-0.8+1.6*%i,0.4-0.8*%i;0.6-1.2*%i,-0.2+0.4*%i]);
40 //c / R
41 assert_checkalmostequal(c / R, [-2-4*%i,1+2*%i;1.5+3*%i,-0.5-1*%i]);
42 //c / C
43 assert_checkalmostequal(c / C, [-2,1;1.5,-0.5]);
44
45
46 //DOUBLE / double
47
48 //R / r
49 assert_checkalmostequal(R / r, [0.5,1;1.5,2]);
50 R3rref(:,:,1) = [0.5,1;1.5,2];
51 R3rref(:,:,2) = [0.5,1.5;1,2];
52 assert_checkalmostequal(R3 / r, R3rref);
53 //R / c
54 assert_checkalmostequal(R / c, [0.2-0.4*%i,0.4-0.8*%i;0.6-1.2*%i,0.8-1.6*%i]);
55 R3cref(:,:,1) = [0.2-0.4*%i,0.4-0.8*%i;0.6-1.2*%i,0.8-1.6*%i];
56 R3cref(:,:,2) = [0.2-0.4*%i,0.6-1.2*%i;0.4-0.8*%i,0.8-1.6*%i];
57 assert_checkalmostequal(R3 / c, R3cref);
58 //C / r
59 assert_checkalmostequal(C / r, [0.5+1*%i,1+2*%i;1.5+3*%i,2+4*%i]);
60 C3rref(:,:,1) = [0.5+1*%i,1+2*%i;1.5+3*%i,2+4*%i];
61 C3rref(:,:,2) = [0.5-1*%i,1.5-3*%i;1-2*%i,2-4*%i];
62 assert_checkalmostequal(C3 / r, C3rref);
63 //C / c
64 assert_checkalmostequal(C / c, [1,2;3,4]);
65 C3cref(:,:,1) = [1,2;3,4];
66 C3cref(:,:,2) = [-0.6-0.8*%i,-1.8-2.4*%i;-1.2-1.6*%i,-2.4-3.2*%i];
67 assert_checkalmostequal(C3 / c, C3cref);
68
69
70 //DOUBLE / DOUBLE
71
72 //R / R
73 assert_checkalmostequal(R / R, [1,0;0,1]);
74 //R / C
75 assert_checkalmostequal(R / C, [0.2-0.4*%i,0;0,0.2-0.4*%i]);
76 //C / R
77 assert_checkalmostequal(C / R, [1+2*%i,0;0,1+2*%i]);
78 //C / C
79 assert_checkalmostequal(C / C, [1,0;0,1]);
80
81 //SPARSE / double
82
83 //SP / r
84 assert_checkalmostequal(SP/ r, sparse([1,2;4,5;3,10],[0.5,1,1.5]));
85 //SP / c
86 assert_checkalmostequal(SP/ c, sparse([1,2;4,5;3,10],[0.2-0.4*%i,0.4-0.8*%i,0.6-1.2*%i]));
87 //SPC /r
88 assert_checkalmostequal(SPC/ r, sparse([1,2;4,5;3,10],[0.5+2*%i,1+4*%i,1.5+6*%i]));
89 //SPC /c
90 assert_checkalmostequal(SPC/ c, sparse([1,2;4,5;3,10],[1.8+0.4*%i,3.6+0.8*%i,5.4+1.2*%i]));
91