restore tests from operations module
[scilab.git] / scilab / modules / ast / tests / unit_tests / power.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 c = 1 + 2*%i;
13 C = [1+2*%i,2+4*%i;3+6*%i,4+8*%i];
14 pR = 1 + 2*%s*%s + 3*%s*%s*%s;
15 pC = pR + pR*%i;
16 PR = [pR,pR;pR,pR];
17 PC = [pC,pC;pC,pC];
18
19
20 //DOUBLE
21
22 // double ^ double
23
24 //r ^ r
25 assert_checkalmostequal(r ^ r, 4);
26 //r ^ c
27 assert_checkalmostequal(r ^ c, 0.3669139494866+%i*1.9660554808225);
28 //c ^ r
29 assert_checkequal(c ^ r, -3+%i*4);
30 //c ^ c
31 assert_checkalmostequal(c ^ c, -0.2225171568018+%i*0.1007091311361);
32
33 // DOUBLE ^ double
34 //R ^ r
35 assert_checkequal(R ^ r, [7,10;15,22]);
36 //R ^ c
37 assert_checkalmostequal(R ^ c, [-1.251952645008-%i*0.28072150763376,-1.825029337717-%i*0.410062225781;-2.7375440065755-%i*0.61509333867145,-3.9894966515835-%i*0.89581484630521]);
38 //C ^ r
39 assert_checkequal(C ^ r, [-21+%i*28,-30+%i*40;-45+%i*60,-66+%i*88]);
40 //C ^ c
41 assert_checkalmostequal(C ^ c, [-27.051150278703-%i*25.062777693306, 12.961689280285+%i*11.342742208568; 19.442533920428+%i*17.014113312852,-7.6086163582745-%i*8.048664380454]);
42
43 // double ^ DOUBLE
44 //r ^ R
45 assert_checkequal(r ^ R, [2,4;8,16]);
46 //r ^ C
47 assert_checkalmostequal(r ^ C, [ 0.3669139494866+%i*1.9660554808225,-3.7307483073443+%i*1.4427463627567;-4.2053829899227-%i*6.8054943911569, 11.836965865504-%i*10.765047101564]);
48 //c ^ R
49 assert_checkequal(c ^ R, [ 1+%i*2,-3+%i*4;-11-%i*2,-7-%i*24]);
50 //c ^ C
51 assert_checkalmostequal(c ^ C, [-0.2225171568018+%i*0.1007091311361, 0.0393715559770-%i*0.0448190190488;-0.0042471622281+%i*0.0139380758833,-0.0004586250484-%i*0.0035291890346]);
52
53
54 //POLY
55
56 //poly ^ double
57
58 //pR ^ r
59 assert_checkequal(pR ^ r, 1+4*%s^2+6*%s^3+4*%s^4+12*%s^5+9*%s^6);
60 //pC ^ r
61 assert_checkequal(pC ^ r, %i*2+(%i*8)*%s^2+(%i*12)*%s^3+(%i*8)*%s^4+(%i*24)*%s^5+(%i*18)*%s^6);
62
63 //poly ^ DOUBLE
64
65 //pR ^ R
66 assert_checkequal(pR ^ R, [1+2*%s^2+3*%s^3,1+4*%s^2+6*%s^3+4*%s^4+12*%s^5+9*%s^6;1+6*%s^2+9*%s^3+12*%s^4+36*%s^5+35*%s^6+36*%s^7+54*%s^8+27*%s^9,1+8*%s^2+12*%s^3+24*%s^4+72*%s^5+86*%s^6+144*%s^7+232*%s^8+204*%s^9+216*%s^10+216*%s^11+81*%s^12]);
67 //pC ^ R
68 assert_checkequal(pC ^ R, [1+%i+(2+%i*2)*%s^2+(3+%i*3)*%s^3,%i*2+(%i*8)*%s^2+(%i*12)*%s^3+(%i*8)*%s^4+(%i*24)*%s^5+(%i*18)*%s^6;-2+%i*2+(-12+%i*12)*%s^2+(-18+%i*18)*%s^3+(-24+%i*24)*%s^4+(-72+%i*72)*%s^5+(-70+%i*70)*%s^6+(-72+%i*72)*%s^7+(-108+%i*108)*%s^8+(-54+%i*54)*%s^9,-4-32*%s^2-48*%s^3-96*%s^4-288*%s^5-344*%s^6-576*%s^7-928*%s^8-816*%s^9-864*%s^10-864*%s^11-324*%s^12]);
69
70 //POLY ^ double
71 //PR ^ r
72 assert_checkequal(PR ^ r, [2+8*%s^2+12*%s^3+8*%s^4+24*%s^5+18*%s^6,2+8*%s^2+12*%s^3+8*%s^4+24*%s^5+18*%s^6;2+8*%s^2+12*%s^3+8*%s^4+24*%s^5+18*%s^6,2+8*%s^2+12*%s^3+8*%s^4+24*%s^5+18*%s^6]);
73 //PC ^ r
74 assert_checkequal(PC ^ r, [%i*4+(%i*16)*%s^2+(%i*24)*%s^3+(%i*16)*%s^4+(%i*48)*%s^5+(%i*36)*%s^6,%i*4+(%i*16)*%s^2+(%i*24)*%s^3+(%i*16)*%s^4+(%i*48)*%s^5+(%i*36)*%s^6;%i*4+(%i*16)*%s^2+(%i*24)*%s^3+(%i*16)*%s^4+(%i*48)*%s^5+(%i*36)*%s^6,%i*4+(%i*16)*%s^2+(%i*24)*%s^3+(%i*16)*%s^4+(%i*48)*%s^5+(%i*36)*%s^6]);