14
14
**/
15
15
package com .googlecode .aviator .test .function ;
16
16
17
+ import static com .googlecode .aviator .TestUtils .assertEquals ;
17
18
import static org .junit .Assert .assertArrayEquals ;
18
- import static org .junit .Assert .assertEquals ;
19
19
import static org .junit .Assert .assertFalse ;
20
20
import static org .junit .Assert .assertNull ;
21
21
import static org .junit .Assert .assertTrue ;
38
38
import com .googlecode .aviator .exception .CompileExpressionErrorException ;
39
39
import com .googlecode .aviator .exception .ExpressionRuntimeException ;
40
40
import com .googlecode .aviator .exception .ExpressionSyntaxErrorException ;
41
+ import com .googlecode .aviator .runtime .RuntimeUtils ;
41
42
import com .googlecode .aviator .runtime .function .AbstractFunction ;
42
43
import com .googlecode .aviator .runtime .function .FunctionUtils ;
43
44
import com .googlecode .aviator .runtime .type .AviatorLong ;
@@ -64,6 +65,44 @@ public void testMultilineExpressions() {
64
65
}
65
66
}
66
67
68
+ @ Test
69
+ public void testExponent () {
70
+ assertEquals (1 , exec ("0**0" ));
71
+ assertEquals (1 , exec ("1**0" ));
72
+ assertEquals (1.0 , exec ("1.2**0" ));
73
+ assertEquals (-9 , exec ("-3**2" ));
74
+ assertEquals (-1.0 , exec ("-1.2**0" ));
75
+ assertEquals (-1 , exec ("-1**0" ));
76
+ assertEquals (new BigDecimal ("1" ), exec ("3M**0" ));
77
+ assertEquals (new BigInteger ("-1" ), exec ("-2N**0" ));
78
+ assertEquals (1 , exec ("1 + 4/2**3" ));
79
+
80
+ assertEquals (1 , exec ("1 + 4/-2**3" ));
81
+ assertEquals (33.0 , exec ("1 + 4/2**-3" ));
82
+ assertEquals (5 , exec ("1 + 4/2**0" ));
83
+ assertEquals (-2.2 , exec ("1-4**2*5**-1" ));
84
+ assertEquals (-2.2 , exec ("1-(4**2)*(5**-1)" ));
85
+
86
+ assertEquals (Math .pow (2 , 1000 ), exec ("2**1000.0" ));
87
+ assertEquals (Math .pow (2 , 1000 ), exec ("2.0**1000.0" ));
88
+ assertEquals (Math .pow (2 , 1000 ), exec ("2.0**1000" ));
89
+
90
+ assertEquals (new BigDecimal ("2.0" ).pow (1000 , RuntimeUtils .getMathContext (null )),
91
+ exec ("2.0M**1000" ));
92
+ assertEquals (new BigDecimal ("2.0" ).pow (1000 , RuntimeUtils .getMathContext (null )),
93
+ exec ("2.0M**1000.001" ));
94
+ assertEquals (new BigInteger ("2" ).pow (1000 ), exec ("2N**1000.001" ));
95
+ assertEquals (new BigInteger ("2" ).pow (1000 ), exec ("2N**1000.001" ));
96
+
97
+ Expression exp = AviatorEvaluator .compile ("a-b/c**2.0*1000" );
98
+
99
+ assertEquals (-221.2222222222222 , exp .execute (exp .newEnv ("a" , 1 , "b" , 2 , "c" , 3 )));
100
+ assertEquals (-221.2222222222222 , exp .execute (exp .newEnv ("a" , 1 , "b" , -2 , "c" , -3 )));
101
+ assertEquals (322.2222222222222 , exec ("100-2/-3**2.0*1000" ));
102
+ assertEquals (-122.2222222222222 , exec ("100-2/(-3)**2.0*1000" ));
103
+ assertEquals (-122.2222222222222 , exp .execute (exp .newEnv ("a" , 100 , "b" , 2 , "c" , -3 )));
104
+ }
105
+
67
106
@ Test
68
107
public void testCompareWithVariableSyntaxSuger () {
69
108
try {
0 commit comments