author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 10 May 2015 14:42:14 +0100 | |
changeset 455 | 44208dab727c |
parent 454 | a9cd5ea7cc36 |
permissions | -rw-r--r-- |
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
375
diff
changeset
|
1 |
"{ Package: 'stx:goodies/petitparser/tests' }" |
0 | 2 |
|
454
a9cd5ea7cc36
Portability: fixes for Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
a9cd5ea7cc36
Portability: fixes for Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
4 |
|
0 | 5 |
PPCompositeParserTest subclass:#PPArithmeticParserTest |
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
9 |
category:'PetitTests-Tests' |
|
10 |
! |
|
11 |
||
12 |
||
13 |
!PPArithmeticParserTest methodsFor:'accessing'! |
|
14 |
||
15 |
parserClass |
|
16 |
^ PPArithmeticParser |
|
17 |
! ! |
|
18 |
||
19 |
!PPArithmeticParserTest methodsFor:'testing'! |
|
20 |
||
21 |
testNum |
|
22 |
self assert: '0' is: 0. |
|
23 |
self assert: '0.0' is: 0.0. |
|
24 |
self assert: '1' is: 1. |
|
25 |
self assert: '1.2' is: 1.2. |
|
26 |
self assert: '34' is: 34. |
|
27 |
self assert: '56.78' is: 56.78. |
|
28 |
self assert: '-9' is: -9. |
|
29 |
self assert: '-9.9' is: -9.9 |
|
30 |
! ! |
|
31 |
||
32 |
!PPArithmeticParserTest methodsFor:'testing-expression'! |
|
33 |
||
34 |
testBrackets |
|
35 |
self assert: '(1)' is: 1. |
|
36 |
self assert: '(1 + 2)' is: 3. |
|
48 | 37 |
|
0 | 38 |
self assert: '((1))' is: 1. |
39 |
self assert: '((1 + 2))' is: 3. |
|
40 |
||
41 |
self assert: '2 * (3 + 4)' is: 14. |
|
42 |
self assert: '(2 + 3) * 4' is: 20. |
|
43 |
self assert: '6 / (2 + 4)' is: 1. |
|
44 |
self assert: '(2 + 6) / 2' is: 4 |
|
45 |
! |
|
46 |
||
47 |
testPriority |
|
48 |
self assert: '2 * 3 + 4' is: 10. |
|
49 |
self assert: '2 + 3 * 4' is: 14. |
|
50 |
self assert: '6 / 3 + 4' is: 6. |
|
51 |
self assert: '2 + 6 / 2' is: 5 |
|
52 |
! ! |
|
53 |
||
54 |
!PPArithmeticParserTest methodsFor:'testing-operations'! |
|
55 |
||
56 |
testAdd |
|
57 |
self assert: '1 + 2' is: 3. |
|
58 |
self assert: '2 + 1' is: 3. |
|
59 |
self assert: '1 + 2.3' is: 3.3. |
|
60 |
self assert: '2.3 + 1' is: 3.3. |
|
61 |
self assert: '1 + -2' is: -1. |
|
62 |
self assert: '-2 + 1' is: -1 |
|
63 |
! |
|
64 |
||
65 |
testAddMany |
|
66 |
self assert: '1' is: 1. |
|
67 |
self assert: '1 + 2' is: 3. |
|
68 |
self assert: '1 + 2 + 3' is: 6. |
|
69 |
self assert: '1 + 2 + 3 + 4' is: 10. |
|
70 |
self assert: '1 + 2 + 3 + 4 + 5' is: 15 |
|
71 |
! |
|
72 |
||
73 |
testDiv |
|
74 |
self assert: '12 / 3' is: 4. |
|
75 |
self assert: '-16 / -4' is: 4 |
|
76 |
! |
|
77 |
||
78 |
testDivMany |
|
79 |
self assert: '100 / 2' is: 50. |
|
80 |
self assert: '100 / 2 / 2' is: 25. |
|
81 |
self assert: '100 / 2 / 2 / 5' is: 5. |
|
82 |
self assert: '100 / 2 / 2 / 5 / 5' is: 1 |
|
48 | 83 |
|
0 | 84 |
! |
85 |
||
86 |
testMul |
|
87 |
self assert: '2 * 3' is: 6. |
|
88 |
self assert: '2 * -4' is: -8 |
|
89 |
! |
|
90 |
||
91 |
testMulMany |
|
92 |
self assert: '1 * 2' is: 2. |
|
93 |
self assert: '1 * 2 * 3' is: 6. |
|
94 |
self assert: '1 * 2 * 3 * 4' is: 24. |
|
95 |
self assert: '1 * 2 * 3 * 4 * 5' is: 120 |
|
96 |
! |
|
97 |
||
98 |
testPow |
|
99 |
self assert: '2 ^ 3' is: 8. |
|
100 |
self assert: '-2 ^ 3' is: -8. |
|
101 |
self assert: '-2 ^ -3' is: -0.125 |
|
102 |
! |
|
103 |
||
104 |
testPowMany |
|
105 |
self assert: '4 ^ 3' is: 64. |
|
106 |
self assert: '4 ^ 3 ^ 2' is: 262144. |
|
107 |
self assert: '4 ^ 3 ^ 2 ^ 1' is: 262144. |
|
108 |
self assert: '4 ^ 3 ^ 2 ^ 1 ^ 0' is: 262144 |
|
109 |
! |
|
110 |
||
111 |
testSub |
|
112 |
self assert: '1 - 2' is: -1. |
|
113 |
self assert: '1.2 - 1.2' is: 0. |
|
114 |
self assert: '1 - -2' is: 3. |
|
115 |
self assert: '-1 - -2' is: 1 |
|
116 |
! |
|
117 |
||
118 |
testSubMany |
|
119 |
self assert: '1' is: 1. |
|
120 |
self assert: '1 - 2' is: -1. |
|
121 |
self assert: '1 - 2 - 3' is: -4. |
|
122 |
self assert: '1 - 2 - 3 - 4' is: -8. |
|
123 |
self assert: '1 - 2 - 3 - 4 - 5' is: -13 |
|
124 |
! ! |
|
125 |
||
126 |
!PPArithmeticParserTest class methodsFor:'documentation'! |
|
127 |
||
48 | 128 |
version |
185 | 129 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPArithmeticParserTest.st,v 1.4 2014-03-04 14:34:09 cg Exp $' |
48 | 130 |
! |
131 |
||
132 |
version_CVS |
|
185 | 133 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPArithmeticParserTest.st,v 1.4 2014-03-04 14:34:09 cg Exp $' |
48 | 134 |
! |
135 |
||
0 | 136 |
version_SVN |
185 | 137 |
^ '$Id: PPArithmeticParserTest.st,v 1.4 2014-03-04 14:34:09 cg Exp $' |
0 | 138 |
! ! |
185 | 139 |