OSDN Git Service

CVSリポジトリから移行。
[rpolishcomop/repo.git] / expression-computer / src / test / java / jp / sourceforge / expression_computer / test / RpnParserTest.jav_
1
2 package jp.sourceforge.rpn_computer.test;
3
4 import jp.sourceforge.rpn_computer.ParseException;
5 import jp.sourceforge.rpn_computer.RpnNode;
6 import jp.sourceforge.rpn_computer.RpnParser;
7 import jp.sourceforge.rpn_computer.node.ExpressionStatementNode;
8 import jp.sourceforge.rpn_computer.node.FloatingPointLiteralNode;
9 import jp.sourceforge.rpn_computer.node.FunctionExpressionNode;
10 import jp.sourceforge.rpn_computer.node.IntegerLiteralNode;
11 import junit.framework.TestCase;
12
13 public class RpnParserTest extends TestCase {
14
15     public RpnParserTest(String name) {
16         super(name);
17     }
18
19     public void testFail_null1() {
20         String exp = null;
21
22         RpnParser parser = new RpnParser();
23         try {
24             parser.parse(exp);
25             fail();
26         } catch (NullPointerException e) {
27             assertEquals("expressionがnullです。", e.getMessage());
28         }
29     }
30
31     public void testFail_EmptyStatement() {
32         String exp = "";
33
34         RpnParser parser = new RpnParser();
35         try {
36             parser.parse(exp);
37             fail();
38         } catch (ParseException e) {
39         }
40     }
41
42     public void testNormal_IntegerLiteral1() {
43         String exp = "1";
44
45         RpnParser parser = new RpnParser();
46         RpnNode expression = parser.parse(exp);
47
48         assertTrue(expression instanceof ExpressionStatementNode);
49         assertEquals(1, expression.getChildren().length);
50
51         RpnNode integerLiteral = expression.getChildren()[0];
52         assertTrue(integerLiteral instanceof IntegerLiteralNode);
53         assertEquals("1", ((IntegerLiteralNode) integerLiteral).getValue());
54         assertEquals(0, integerLiteral.getChildren().length);
55     }
56
57     public void testNormal_IntegerLiteral2() {
58         String exp = "123456789";
59
60         RpnParser parser = new RpnParser();
61         RpnNode expression = parser.parse(exp);
62
63         assertTrue(expression instanceof ExpressionStatementNode);
64         assertEquals(1, expression.getChildren().length);
65
66         RpnNode integerLiteral = expression.getChildren()[0];
67         assertTrue(integerLiteral instanceof IntegerLiteralNode);
68         assertEquals("123456789", ((IntegerLiteralNode) integerLiteral).getValue());
69         assertEquals(0, integerLiteral.getChildren().length);
70     }
71
72     public void testNormal_IntegerLiteral3() {
73         String exp = "0xfFff";
74
75         RpnParser parser = new RpnParser();
76         RpnNode expression = parser.parse(exp);
77
78         assertTrue(expression instanceof ExpressionStatementNode);
79         assertEquals(1, expression.getChildren().length);
80
81         RpnNode integerLiteral = expression.getChildren()[0];
82         assertTrue(integerLiteral instanceof IntegerLiteralNode);
83         assertEquals("0xfFff", ((IntegerLiteralNode) integerLiteral).getValue());
84         assertEquals(0, integerLiteral.getChildren().length);
85     }
86
87     public void testNormal_IntegerLiteral4() {
88         String exp = "07777";
89
90         RpnParser parser = new RpnParser();
91         RpnNode expression = parser.parse(exp);
92
93         assertTrue(expression instanceof ExpressionStatementNode);
94         assertEquals(1, expression.getChildren().length);
95
96         RpnNode integerLiteral = expression.getChildren()[0];
97         assertTrue(integerLiteral instanceof IntegerLiteralNode);
98         assertEquals("07777", ((IntegerLiteralNode) integerLiteral).getValue());
99         assertEquals(0, integerLiteral.getChildren().length);
100     }
101
102     public void testNormal_IntegerLiteral5() {
103         String exp = "0";
104
105         RpnParser parser = new RpnParser();
106         RpnNode expression = parser.parse(exp);
107
108         assertTrue(expression instanceof ExpressionStatementNode);
109         assertEquals(1, expression.getChildren().length);
110
111         RpnNode integerLiteral = expression.getChildren()[0];
112         assertTrue(integerLiteral instanceof IntegerLiteralNode);
113         assertEquals("0", ((IntegerLiteralNode) integerLiteral).getValue());
114         assertEquals(0, integerLiteral.getChildren().length);
115     }
116
117     public void testFail_IntegerLiteral1() {
118         String exp = "123456789123456789123456789";
119
120         RpnParser parser = new RpnParser();
121         try {
122             parser.parse(exp);
123             fail();
124         } catch (ParseException e) {
125         }
126     }
127
128     public void testFail_IntegerLiteral2() {
129         String exp = "123,456,789";
130
131         RpnParser parser = new RpnParser();
132         try {
133             parser.parse(exp);
134             fail();
135         } catch (ParseException e) {
136         }
137     }
138
139     public void testNormal_FloatingPointLiteral1() {
140         String exp = "123.456";
141
142         RpnParser parser = new RpnParser();
143         RpnNode expression = parser.parse(exp);
144
145         assertTrue(expression instanceof ExpressionStatementNode);
146         assertEquals(1, expression.getChildren().length);
147
148         RpnNode floatingPointLiteral = expression.getChildren()[0];
149         assertTrue(floatingPointLiteral instanceof FloatingPointLiteralNode);
150         assertEquals("123.456", ((FloatingPointLiteralNode) floatingPointLiteral).getValue());
151         assertEquals(0, floatingPointLiteral.getChildren().length);
152     }
153
154     public void testNormal_FloatingPointLiteral2() {
155         String exp = "0.123456";
156
157         RpnParser parser = new RpnParser();
158         RpnNode expression = parser.parse(exp);
159
160         assertTrue(expression instanceof ExpressionStatementNode);
161         assertEquals(1, expression.getChildren().length);
162
163         RpnNode floatingPointLiteral = expression.getChildren()[0];
164         assertTrue(floatingPointLiteral instanceof FloatingPointLiteralNode);
165         assertEquals("0.123456", ((FloatingPointLiteralNode) floatingPointLiteral).getValue());
166         assertEquals(0, floatingPointLiteral.getChildren().length);
167     }
168
169     public void testNormal_FloatingPointLiteral3() {
170         String exp = ".123456";
171
172         RpnParser parser = new RpnParser();
173         RpnNode expression = parser.parse(exp);
174
175         assertTrue(expression instanceof ExpressionStatementNode);
176         assertEquals(1, expression.getChildren().length);
177
178         RpnNode floatingPointLiteral = expression.getChildren()[0];
179         assertTrue(floatingPointLiteral instanceof FloatingPointLiteralNode);
180         assertEquals(".123456", ((FloatingPointLiteralNode) floatingPointLiteral).getValue());
181         assertEquals(0, floatingPointLiteral.getChildren().length);
182     }
183
184     public void testNormal_FloatingPointLiteral4() {
185         String exp = "0.0";
186
187         RpnParser parser = new RpnParser();
188         RpnNode expression = parser.parse(exp);
189
190         assertTrue(expression instanceof ExpressionStatementNode);
191         assertEquals(1, expression.getChildren().length);
192
193         RpnNode floatingPointLiteral = expression.getChildren()[0];
194         assertTrue(floatingPointLiteral instanceof FloatingPointLiteralNode);
195         assertEquals("0.0", ((FloatingPointLiteralNode) floatingPointLiteral).getValue());
196         assertEquals(0, floatingPointLiteral.getChildren().length);
197     }
198
199     public void testNormal_FloatingPointLiteral5() {
200         String exp = ".0";
201
202         RpnParser parser = new RpnParser();
203         RpnNode expression = parser.parse(exp);
204
205         assertTrue(expression instanceof ExpressionStatementNode);
206         assertEquals(1, expression.getChildren().length);
207
208         RpnNode floatingPointLiteral = expression.getChildren()[0];
209         assertTrue(floatingPointLiteral instanceof FloatingPointLiteralNode);
210         assertEquals(".0", ((FloatingPointLiteralNode) floatingPointLiteral).getValue());
211         assertEquals(0, floatingPointLiteral.getChildren().length);
212     }
213
214     public void testFail_FloatingPointLiteral1() {
215         String exp = "123.456.789";
216
217         RpnParser parser = new RpnParser();
218         try {
219             parser.parse(exp);
220             fail();
221         } catch (ParseException e) {
222         }
223     }
224
225     public void testNormal_FunctionExpression1() {
226         String exp = "foo()";
227
228         RpnParser parser = new RpnParser();
229         RpnNode expression = parser.parse(exp);
230
231         assertTrue(expression instanceof ExpressionStatementNode);
232         assertEquals(1, expression.getChildren().length);
233
234         RpnNode function = expression.getChildren()[0];
235         assertTrue(function instanceof FunctionExpressionNode);
236         assertEquals(3, function.getChildren().length);
237
238         RpnNode functionName = function.getChildren()[0];
239         assertTrue(functionName instanceof FunctionExpressionNode.FunctionNameNode);
240         assertEquals("foo", ((FunctionExpressionNode.FunctionNameNode) functionName).getName());
241         assertEquals(0, functionName.getChildren().length);
242
243         RpnNode leftBracket = function.getChildren()[1];
244         assertTrue(leftBracket instanceof FunctionExpressionNode.LeftBracketNode);
245         assertEquals(0, leftBracket.getChildren().length);
246
247         RpnNode rightBracket = function.getChildren()[2];
248         assertTrue(rightBracket instanceof FunctionExpressionNode.RightBracketNode);
249         assertEquals(0, rightBracket.getChildren().length);
250     }
251
252     public void testNormal_FunctionExpression2() {
253         String exp = "foo(1, 2)";
254
255         RpnParser parser = new RpnParser();
256         RpnNode expression = parser.parse(exp);
257
258         assertTrue(expression instanceof ExpressionStatementNode);
259         assertEquals(1, expression.getChildren().length);
260
261         RpnNode function = expression.getChildren()[0];
262         assertTrue(function instanceof FunctionExpressionNode);
263         assertEquals(6, function.getChildren().length);
264
265         RpnNode functionName = function.getChildren()[0];
266         assertTrue(functionName instanceof FunctionExpressionNode.FunctionNameNode);
267         assertEquals("foo", ((FunctionExpressionNode.FunctionNameNode) functionName).getName());
268         assertEquals(0, functionName.getChildren().length);
269
270         RpnNode leftBracket = function.getChildren()[1];
271         assertTrue(leftBracket instanceof FunctionExpressionNode.LeftBracketNode);
272         assertEquals(0, leftBracket.getChildren().length);
273
274         RpnNode integerLiteral = function.getChildren()[2];
275         assertTrue(integerLiteral instanceof IntegerLiteralNode);
276         assertEquals("1", ((IntegerLiteralNode) integerLiteral).getValue());
277         assertEquals(0, integerLiteral.getChildren().length);
278
279         RpnNode comma = function.getChildren()[3];
280         assertTrue(comma instanceof FunctionExpressionNode.CommaNode);
281         assertEquals(0, comma.getChildren().length);
282
283         integerLiteral = function.getChildren()[4];
284         assertTrue(integerLiteral instanceof IntegerLiteralNode);
285         assertEquals("2", ((IntegerLiteralNode) integerLiteral).getValue());
286         assertEquals(0, integerLiteral.getChildren().length);
287
288         RpnNode rightBracket = function.getChildren()[5];
289         assertTrue(rightBracket instanceof FunctionExpressionNode.RightBracketNode);
290         assertEquals(0, rightBracket.getChildren().length);
291     }
292
293     public void testNormal_FunctionExpression3() {
294         String exp = "foo(1 + 2)";
295
296         RpnParser parser = new RpnParser();
297         RpnNode expression = parser.parse(exp);
298
299         assertTrue(expression instanceof ExpressionStatementNode);
300         assertEquals(1, expression.getChildren().length);
301
302         RpnNode function = expression.getChildren()[0];
303         assertTrue(function instanceof FunctionExpressionNode);
304         assertEquals(6, function.getChildren().length);
305
306         RpnNode functionName = function.getChildren()[0];
307         assertTrue(functionName instanceof FunctionExpressionNode.FunctionNameNode);
308         assertEquals("foo", ((FunctionExpressionNode.FunctionNameNode) functionName).getName());
309         assertEquals(0, functionName.getChildren().length);
310
311         RpnNode leftBracket = function.getChildren()[1];
312         assertTrue(leftBracket instanceof FunctionExpressionNode.LeftBracketNode);
313         assertEquals(0, leftBracket.getChildren().length);
314
315         RpnNode integerLiteral = function.getChildren()[2];
316         assertTrue(integerLiteral instanceof IntegerLiteralNode);
317         assertEquals("1", ((IntegerLiteralNode) integerLiteral).getValue());
318         assertEquals(0, integerLiteral.getChildren().length);
319
320         RpnNode comma = function.getChildren()[3];
321         assertTrue(comma instanceof FunctionExpressionNode.CommaNode);
322         assertEquals(0, comma.getChildren().length);
323
324         integerLiteral = function.getChildren()[4];
325         assertTrue(integerLiteral instanceof IntegerLiteralNode);
326         assertEquals("2", ((IntegerLiteralNode) integerLiteral).getValue());
327         assertEquals(0, integerLiteral.getChildren().length);
328
329         RpnNode rightBracket = function.getChildren()[5];
330         assertTrue(rightBracket instanceof FunctionExpressionNode.RightBracketNode);
331         assertEquals(0, rightBracket.getChildren().length);
332     }
333
334     public void testNormal_FunctionExpression4() {
335         String exp = "foo() + bar()";
336
337         fail();
338     }
339
340     public void testFail_FunctionExpression1() {
341         String exp = "foo()";
342
343         RpnParser parser = new RpnParser();
344         try {
345             parser.parse(exp);
346             fail();
347         } catch (ParseException e) {
348         }
349     }
350
351     public void testFail_FunctionExpression3() {
352         String exp = "foo(10, )";
353
354         RpnParser parser = new RpnParser();
355         try {
356             parser.parse(exp);
357             fail();
358         } catch (ParseException e) {
359         }
360     }
361
362     public void testFail_FunctionExpression4() {
363         String exp = "foo(";
364
365         RpnParser parser = new RpnParser();
366         try {
367             parser.parse(exp);
368             fail();
369         } catch (ParseException e) {
370         }
371     }
372
373     public void testFail_FunctionExpression5() {
374         String exp = "foo)";
375
376         RpnParser parser = new RpnParser();
377         try {
378             parser.parse(exp);
379             fail();
380         } catch (ParseException e) {
381         }
382     }
383
384     public void testFail_FunctionExpression6() {
385         String exp = "foo(10 10)";
386
387         RpnParser parser = new RpnParser();
388         try {
389             parser.parse(exp);
390             fail();
391         } catch (ParseException e) {
392         }
393     }
394
395     public void testNormal_Variable1() {
396         String exp = "x";
397
398         fail();
399     }
400
401     public void testNormal_Variable2() {
402         String exp = "abc123_";
403
404         fail();
405     }
406
407     public void testNormal_Variable3() {
408         String exp = "_abc";
409
410         fail();
411     }
412
413     public void testNormal_Variable4() {
414         String exp = "ほげ";
415
416         fail();
417     }
418
419     public void testFail_Variable1() {
420         String exp = "123abc";
421
422         RpnParser parser = new RpnParser();
423         try {
424             parser.parse(exp);
425             fail();
426         } catch (ParseException e) {
427         }
428     }
429
430     public void testNormal_ParenthesesExpression1() {
431         String exp = "(1 + 2)";
432
433         fail();
434     }
435
436     public void testNormal_ParenthesesExpression2() {
437         String exp = "(1 + (2 - 3))";
438
439         fail();
440     }
441
442     public void testFail_ParenthesesExpression1() {
443         String exp = "()";
444
445         RpnParser parser = new RpnParser();
446         try {
447             parser.parse(exp);
448             fail();
449         } catch (ParseException e) {
450         }
451     }
452
453     public void testFail_ParenthesesExpression2() {
454         String exp = "(1 + 2";
455
456         RpnParser parser = new RpnParser();
457         try {
458             parser.parse(exp);
459             fail();
460         } catch (ParseException e) {
461         }
462     }
463
464     public void testFail_ParenthesesExpression3() {
465         String exp = "1 + 2)";
466
467         RpnParser parser = new RpnParser();
468         try {
469             parser.parse(exp);
470             fail();
471         } catch (ParseException e) {
472         }
473     }
474
475     public void testNormal_PreIncrementExpression1() {
476         String exp = "++x";
477
478         fail();
479     }
480
481     public void testFail_PreIncrementExpression1() {
482         String exp = "++1";
483
484         RpnParser parser = new RpnParser();
485         try {
486             parser.parse(exp);
487             fail();
488         } catch (ParseException e) {
489         }
490     }
491
492     public void testFail_PreIncrementExpression2() {
493         String exp = "++++x";
494
495         RpnParser parser = new RpnParser();
496         try {
497             parser.parse(exp);
498             fail();
499         } catch (ParseException e) {
500         }
501     }
502
503     public void testFail_PreIncrementExpression3() {
504         String exp = "++(++x)";
505
506         RpnParser parser = new RpnParser();
507         try {
508             parser.parse(exp);
509             fail();
510         } catch (ParseException e) {
511         }
512     }
513
514     public void testNormal_PostIncrementExpression1() {
515         String exp = "x++";
516
517         fail();
518     }
519
520     public void testFail_PostIncrementExpression1() {
521         String exp = "1++";
522
523         RpnParser parser = new RpnParser();
524         try {
525             parser.parse(exp);
526             fail();
527         } catch (ParseException e) {
528         }
529     }
530
531     public void testFail_PostIncrementExpression2() {
532         String exp = "x++++";
533
534         RpnParser parser = new RpnParser();
535         try {
536             parser.parse(exp);
537             fail();
538         } catch (ParseException e) {
539         }
540     }
541
542     public void testFail_PostIncrementExpression3() {
543         String exp = "(x++)++";
544
545         RpnParser parser = new RpnParser();
546         try {
547             parser.parse(exp);
548             fail();
549         } catch (ParseException e) {
550         }
551     }
552
553     public void testNormal_PreDecrementExpression1() {
554         String exp = "--x";
555
556         fail();
557     }
558
559     public void testFail_PreDecrementExpression1() {
560         String exp = "--1";
561
562         RpnParser parser = new RpnParser();
563         try {
564             parser.parse(exp);
565             fail();
566         } catch (ParseException e) {
567         }
568     }
569
570     public void testFail_PreDecrementExpression2() {
571         String exp = "----x";
572
573         RpnParser parser = new RpnParser();
574         try {
575             parser.parse(exp);
576             fail();
577         } catch (ParseException e) {
578         }
579     }
580
581     public void testFail_PreDecrementExpression3() {
582         String exp = "--(--x)";
583
584         RpnParser parser = new RpnParser();
585         try {
586             parser.parse(exp);
587             fail();
588         } catch (ParseException e) {
589         }
590     }
591
592     public void testNormal_PostDecrementExpression1() {
593         String exp = "x--";
594
595         fail();
596     }
597
598     public void testFail_PostDecrementExpression1() {
599         String exp = "1--";
600
601         RpnParser parser = new RpnParser();
602         try {
603             parser.parse(exp);
604             fail();
605         } catch (ParseException e) {
606         }
607     }
608
609     public void testFail_PostDecrementExpression2() {
610         String exp = "x----";
611
612         RpnParser parser = new RpnParser();
613         try {
614             parser.parse(exp);
615             fail();
616         } catch (ParseException e) {
617         }
618     }
619
620     public void testFail_PostDecrementExpression3() {
621         String exp = "(x--)--";
622
623         RpnParser parser = new RpnParser();
624         try {
625             parser.parse(exp);
626             fail();
627         } catch (ParseException e) {
628         }
629     }
630
631     public void testNormal_UnaryExpressionNotPlusMinus1() {
632         String exp = "~1";
633
634         fail();
635     }
636
637     public void testNormal_UnaryExpressionNotPlusMinus2() {
638         String exp = "~x";
639
640         fail();
641     }
642
643     public void testNormal_UnaryExpressionNotPlusMinus3() {
644         String exp = "~(~1)";
645
646         fail();
647     }
648
649     public void testNormal_UnaryExpressionNotPlusMinus4() {
650         String exp = "!0";
651
652         fail();
653     }
654
655     public void testNormal_UnaryExpressionNotPlusMinus5() {
656         String exp = "!1";
657
658         fail();
659     }
660
661     public void testNormal_UnaryExpressionNotPlusMinus6() {
662         String exp = "!0.1";
663
664         fail();
665     }
666
667     public void testNormal_UnaryExpressionNotPlusMinus7() {
668         String exp = "!(!9)";
669
670         fail();
671     }
672
673     public void testFail_UnaryExpressionNotPlusMinus1() {
674         String exp = "~~1";
675
676         RpnParser parser = new RpnParser();
677         try {
678             parser.parse(exp);
679             fail();
680         } catch (ParseException e) {
681         }
682     }
683
684     public void testFail_UnaryExpressionNotPlusMinus2() {
685         String exp = "!!1";
686
687         RpnParser parser = new RpnParser();
688         try {
689             parser.parse(exp);
690             fail();
691         } catch (ParseException e) {
692         }
693     }
694
695     public void testNormal_UnaryExpression1() {
696         String exp = "+0";
697
698         fail();
699     }
700
701     public void testNormal_UnaryExpression2() {
702         String exp = "+999";
703
704         fail();
705     }
706
707     public void testNormal_UnaryExpression3() {
708         String exp = "+(+999)";
709
710         fail();
711     }
712
713     public void testNormal_UnaryExpression4() {
714         String exp = "+(+x)";
715
716         fail();
717     }
718
719     public void testNormal_UnaryExpression5() {
720         String exp = "-0";
721
722         fail();
723     }
724
725     public void testNormal_UnaryExpression6() {
726         String exp = "-999";
727
728         fail();
729     }
730
731     public void testNormal_UnaryExpression7() {
732         String exp = "-(-999)";
733
734         fail();
735     }
736
737     public void testNormal_UnaryExpression8() {
738         String exp = "-(-x)";
739
740         fail();
741     }
742
743     public void testFail_UnaryExpression1() {
744         String exp = "+++1";
745
746         RpnParser parser = new RpnParser();
747         try {
748             parser.parse(exp);
749             fail();
750         } catch (ParseException e) {
751         }
752     }
753
754     public void testFail_UnaryExpression2() {
755         String exp = "---1";
756
757         RpnParser parser = new RpnParser();
758         try {
759             parser.parse(exp);
760             fail();
761         } catch (ParseException e) {
762         }
763     }
764
765     public void testNormal_MultiplicativeExpression1() {
766         String exp = "2 * 3";
767
768         fail();
769     }
770
771     public void testNormal_MultiplicativeExpression2() {
772         String exp = "4 / 2";
773
774         fail();
775     }
776
777     public void testNormal_MultiplicativeExpression3() {
778         String exp = "10 % 3";
779
780         fail();
781     }
782
783     public void testNormal_MultiplicativeExpression4() {
784         String exp = "2 * 6 / 3 % 3";
785
786         fail();
787     }
788
789     public void testNormal_MultiplicativeExpression5() {
790         String exp = "1 / 0";
791
792         fail();
793     }
794
795     public void testNormal_MultiplicativeExpression6() {
796         String exp = "0 / 0";
797
798         fail();
799     }
800
801     public void testFail_MultiplicativeExpression1() {
802         String exp = "2 * * 3";
803
804         RpnParser parser = new RpnParser();
805         try {
806             parser.parse(exp);
807             fail();
808         } catch (ParseException e) {
809         }
810     }
811
812     public void testFail_MultiplicativeExpression2() {
813         String exp = "2 / / 3";
814
815         RpnParser parser = new RpnParser();
816         try {
817             parser.parse(exp);
818             fail();
819         } catch (ParseException e) {
820         }
821     }
822
823     public void testFail_MultiplicativeExpression3() {
824         String exp = "2 % % 3";
825
826         RpnParser parser = new RpnParser();
827         try {
828             parser.parse(exp);
829             fail();
830         } catch (ParseException e) {
831         }
832     }
833
834     public void testFail_MultiplicativeExpression4() {
835         String exp = "2 *";
836
837         RpnParser parser = new RpnParser();
838         try {
839             parser.parse(exp);
840             fail();
841         } catch (ParseException e) {
842         }
843     }
844
845     public void testNormal_AdditiveExpression1() {
846         String exp = "1 + 2";
847
848         fail();
849     }
850
851     public void testNormal_AdditiveExpression2() {
852         String exp = "1 - 2";
853
854         fail();
855     }
856
857     public void testNormal_AdditiveExpression3() {
858         String exp = "1 - 2 + 3";
859
860         fail();
861     }
862
863     public void testFail_AdditiveExpression1() {
864         String exp = "1 + + + 1";
865
866         RpnParser parser = new RpnParser();
867         try {
868             parser.parse(exp);
869             fail();
870         } catch (ParseException e) {
871         }
872     }
873
874     public void testFail_AdditiveExpression2() {
875         String exp = "1 - - - 1";
876
877         RpnParser parser = new RpnParser();
878         try {
879             parser.parse(exp);
880             fail();
881         } catch (ParseException e) {
882         }
883     }
884
885     public void testFail_AdditiveExpression3() {
886         String exp = "1 +";
887
888         RpnParser parser = new RpnParser();
889         try {
890             parser.parse(exp);
891             fail();
892         } catch (ParseException e) {
893         }
894     }
895
896     public void testNormal_ShiftExpression1() {
897         String exp = "0 << 1";
898
899         fail();
900     }
901
902     public void testNormal_ShiftExpression2() {
903         String exp = "123 << 3";
904
905         fail();
906     }
907
908     public void testNormal_ShiftExpression3() {
909         String exp = "0 >> 1";
910
911         fail();
912     }
913
914     public void testNormal_ShiftExpression4() {
915         String exp = "123 >> 1";
916
917         fail();
918     }
919
920     public void testNormal_ShiftExpression5() {
921         String exp = "-123 >> 1";
922
923         fail();
924     }
925
926     public void testNormal_ShiftExpression6() {
927         String exp = "0 >>> 1";
928
929         fail();
930     }
931
932     public void testNormal_ShiftExpression7() {
933         String exp = "123 >>> 1";
934
935         fail();
936     }
937
938     public void testNormal_ShiftExpression8() {
939         String exp = "-123 >>> 1";
940
941         fail();
942     }
943
944     public void testNormal_ShiftExpression9() {
945         String exp = "123.456 << 3.456";
946
947         fail();
948     }
949
950     public void testNormal_ShiftExpression10() {
951         String exp = "1 << 2 << 3";
952
953         fail();
954     }
955
956     public void testFail_ShiftExpression1() {
957         String exp = "1 << << 1";
958
959         RpnParser parser = new RpnParser();
960         try {
961             parser.parse(exp);
962             fail();
963         } catch (ParseException e) {
964         }
965     }
966
967     public void testFail_ShiftExpression2() {
968         String exp = "1 >> >> 1";
969
970         RpnParser parser = new RpnParser();
971         try {
972             parser.parse(exp);
973             fail();
974         } catch (ParseException e) {
975         }
976     }
977
978     public void testFail_ShiftExpression3() {
979         String exp = "1 >>> >>> 1";
980
981         RpnParser parser = new RpnParser();
982         try {
983             parser.parse(exp);
984             fail();
985         } catch (ParseException e) {
986         }
987     }
988
989     public void testFail_ShiftExpression4() {
990         String exp = "1 <<<< 1";
991
992         RpnParser parser = new RpnParser();
993         try {
994             parser.parse(exp);
995             fail();
996         } catch (ParseException e) {
997         }
998     }
999
1000     public void testNormal_RelationalExpression1() {
1001         String exp = "123 > 122";
1002
1003         fail();
1004     }
1005
1006     public void testNormal_RelationalExpression2() {
1007         String exp = "123.1 > 123.2";
1008
1009         fail();
1010     }
1011
1012     public void testNormal_RelationalExpression3() {
1013         String exp = "123.1 > 123.1";
1014
1015         fail();
1016     }
1017
1018     public void testNormal_RelationalExpression4() {
1019         String exp = "122 < 123";
1020
1021         fail();
1022     }
1023
1024     public void testNormal_RelationalExpression5() {
1025         String exp = "123.2 < 123.1";
1026
1027         fail();
1028     }
1029
1030     public void testNormal_RelationalExpression6() {
1031         String exp = "123.2 < 123.2";
1032
1033         fail();
1034     }
1035
1036     public void testNormal_RelationalExpression7() {
1037         String exp = "123 >= 122";
1038
1039         fail();
1040     }
1041
1042     public void testNormal_RelationalExpression8() {
1043         String exp = "123.1 >= 123.2";
1044
1045         fail();
1046     }
1047
1048     public void testNormal_RelationalExpression9() {
1049         String exp = "123.1 >= 123.1";
1050
1051         fail();
1052     }
1053
1054     public void testNormal_RelationalExpression10() {
1055         String exp = "122 <= 123";
1056
1057         fail();
1058     }
1059
1060     public void testNormal_RelationalExpression11() {
1061         String exp = "123.2 <= 123.1";
1062
1063         fail();
1064     }
1065
1066     public void testNormal_RelationalExpression12() {
1067         String exp = "123.1 <= 123.1";
1068
1069         fail();
1070     }
1071
1072     public void testNormal_RelationalExpression13() {
1073         String exp = "0 > 0 > 0";
1074
1075         fail();
1076     }
1077
1078     public void testFail_RelationalExpression1() {
1079         String exp = "1 > > 2";
1080
1081         RpnParser parser = new RpnParser();
1082         try {
1083             parser.parse(exp);
1084             fail();
1085         } catch (ParseException e) {
1086         }
1087     }
1088
1089     public void testFail_RelationalExpression2() {
1090         String exp = "1 < < 2";
1091
1092         RpnParser parser = new RpnParser();
1093         try {
1094             parser.parse(exp);
1095             fail();
1096         } catch (ParseException e) {
1097         }
1098     }
1099
1100     public void testFail_RelationalExpression3() {
1101         String exp = "1 >= >= 2";
1102
1103         RpnParser parser = new RpnParser();
1104         try {
1105             parser.parse(exp);
1106             fail();
1107         } catch (ParseException e) {
1108         }
1109     }
1110
1111     public void testFail_RelationalExpression4() {
1112         String exp = "1 <= <= 2";
1113
1114         RpnParser parser = new RpnParser();
1115         try {
1116             parser.parse(exp);
1117             fail();
1118         } catch (ParseException e) {
1119         }
1120     }
1121
1122     public void testNormal_EqualityExpression1() {
1123         String exp = "123.456 == 123.456";
1124
1125         fail();
1126     }
1127
1128     public void testNormal_EqualityExpression2() {
1129         String exp = "123.456 == 123.4567";
1130
1131         fail();
1132     }
1133
1134     public void testNormal_EqualityExpression3() {
1135         String exp = "123.456 != 123.456";
1136
1137         fail();
1138     }
1139
1140     public void testNormal_EqualityExpression4() {
1141         String exp = "123.456 != 123.4567";
1142
1143         fail();
1144     }
1145
1146     public void testNormal_EqualityExpression5() {
1147         String exp = "NaN == NaN";
1148
1149         fail();
1150     }
1151
1152     public void testNormal_EqualityExpression6() {
1153         String exp = "NaN != NaN";
1154
1155         fail();
1156     }
1157
1158     public void testNormal_EqualityExpression7() {
1159         String exp = "0 == 0 == 0";
1160
1161         fail();
1162     }
1163
1164     public void testFail_EqualityExpression1() {
1165         String exp = "1 == == 2";
1166
1167         RpnParser parser = new RpnParser();
1168         try {
1169             parser.parse(exp);
1170             fail();
1171         } catch (ParseException e) {
1172         }
1173     }
1174
1175     public void testFail_EqualityExpression2() {
1176         String exp = "1 != != 2";
1177
1178         RpnParser parser = new RpnParser();
1179         try {
1180             parser.parse(exp);
1181             fail();
1182         } catch (ParseException e) {
1183         }
1184     }
1185
1186     public void testNormal_AndExpression1() {
1187         String exp = "123 & 456";
1188
1189         fail();
1190     }
1191
1192     public void testNormal_AndExpression2() {
1193         String exp = "123.456 & 456.789";
1194
1195         fail();
1196     }
1197
1198     public void testNormal_AndExpression3() {
1199         String exp = "123 & 456 & 789";
1200
1201         fail();
1202     }
1203
1204     public void testFail_AndExpression1() {
1205         String exp = "123 & & 456";
1206
1207         RpnParser parser = new RpnParser();
1208         try {
1209             parser.parse(exp);
1210             fail();
1211         } catch (ParseException e) {
1212         }
1213
1214     }
1215
1216     public void testNormal_ExclusiveOrExpression1() {
1217         String exp = "123 ^ 456";
1218
1219         fail();
1220     }
1221
1222     public void testNormal_ExclusiveOrExpression2() {
1223         String exp = "123.456 ^ 456.789";
1224
1225         fail();
1226     }
1227
1228     public void testNormal_ExclusiveOrExpression3() {
1229         String exp = "123 ^ 456 ^ 789";
1230
1231         fail();
1232     }
1233
1234     public void testFail_ExclusiveOrExpression1() {
1235         String exp = "123 ^ ^ 456";
1236
1237         RpnParser parser = new RpnParser();
1238         try {
1239             parser.parse(exp);
1240             fail();
1241         } catch (ParseException e) {
1242         }
1243     }
1244
1245     public void testNormal_InclusiveOrExpression1() {
1246         String exp = "123 | 456";
1247
1248         fail();
1249     }
1250
1251     public void testNormal_InclusiveOrExpression2() {
1252         String exp = "123.456 | 456.789";
1253
1254         fail();
1255     }
1256
1257     public void testNormal_InclusiveOrExpression3() {
1258         String exp = "123 | 456 | 789";
1259
1260         fail();
1261     }
1262
1263     public void testFail_InclusiveOrExpression1() {
1264         String exp = "123 | | 456";
1265
1266         RpnParser parser = new RpnParser();
1267         try {
1268             parser.parse(exp);
1269             fail();
1270         } catch (ParseException e) {
1271         }
1272     }
1273
1274     public void testNormal_ConditionalAndExpression1() {
1275         String exp = "0 && 0";
1276
1277         fail();
1278     }
1279
1280     public void testNormal_ConditionalAndExpression2() {
1281         String exp = "0 && 1";
1282
1283         fail();
1284     }
1285
1286     public void testNormal_ConditionalAndExpression3() {
1287         String exp = "0 && 123.456";
1288
1289         fail();
1290     }
1291
1292     public void testNormal_ConditionalAndExpression4() {
1293         String exp = "1 && 0";
1294
1295         fail();
1296     }
1297
1298     public void testNormal_ConditionalAndExpression5() {
1299         String exp = "123.456 && 0";
1300
1301         fail();
1302     }
1303
1304     public void testNormal_ConditionalAndExpression6() {
1305         String exp = "1 && 1";
1306
1307         fail();
1308     }
1309
1310     public void testNormal_ConditionalAndExpression7() {
1311         String exp = "123.456 && 123.456";
1312
1313         fail();
1314     }
1315
1316     public void testFail_ConditionalAndExpression1() {
1317         String exp = "0 && && 0";
1318
1319         RpnParser parser = new RpnParser();
1320         try {
1321             parser.parse(exp);
1322             fail();
1323         } catch (ParseException e) {
1324         }
1325     }
1326
1327     public void testNormal_ConditionalOrExpression1() {
1328         String exp = "0 || 0";
1329
1330         fail();
1331     }
1332
1333     public void testNormal_ConditionalOrExpression2() {
1334         String exp = "0 || 1";
1335
1336         fail();
1337     }
1338
1339     public void testNormal_ConditionalOrExpression3() {
1340         String exp = "0 || 123.456";
1341
1342         fail();
1343     }
1344
1345     public void testNormal_ConditionalOrExpression4() {
1346         String exp = "1 || 0";
1347
1348         fail();
1349     }
1350
1351     public void testNormal_ConditionalOrExpression5() {
1352         String exp = "123.456 || 0";
1353
1354         fail();
1355     }
1356
1357     public void testNormal_ConditionalOrExpression6() {
1358         String exp = "1 || 1";
1359
1360         fail();
1361     }
1362
1363     public void testNormal_ConditionalOrExpression7() {
1364         String exp = "123.456 || 123.456";
1365
1366         fail();
1367     }
1368
1369     public void testFail_ConditionalOrExpression1() {
1370         String exp = "0 || || 0";
1371
1372         RpnParser parser = new RpnParser();
1373         try {
1374             parser.parse(exp);
1375             fail();
1376         } catch (ParseException e) {
1377         }
1378     }
1379
1380     public void testNormal_ConditionalExpression1() {
1381         String exp = "0 ? 123 : 456";
1382
1383         fail();
1384     }
1385
1386     public void testNormal_ConditionalExpression2() {
1387         String exp = "1 ? 123 : 456";
1388
1389         fail();
1390     }
1391
1392     public void testNormal_ConditionalExpression3() {
1393         String exp = "789 ? 123 : 456";
1394
1395         fail();
1396     }
1397
1398     public void testNormal_ConditionalExpression4() {
1399         String exp = "0 ? 1 : 2 ? 3 : 4";
1400
1401         fail();
1402     }
1403
1404     public void testFail_ConditionalExpression2() {
1405         String exp = "0 ? 1";
1406
1407         RpnParser parser = new RpnParser();
1408         try {
1409             parser.parse(exp);
1410             fail();
1411         } catch (ParseException e) {
1412         }
1413     }
1414
1415     public void testFail_ConditionalExpression3() {
1416         String exp = "1 : 2";
1417
1418         RpnParser parser = new RpnParser();
1419         try {
1420             parser.parse(exp);
1421             fail();
1422         } catch (ParseException e) {
1423         }
1424     }
1425
1426     public void testFail_ConditionalExpression4() {
1427         String exp = "0 ? 1 ? 2";
1428
1429         RpnParser parser = new RpnParser();
1430         try {
1431             parser.parse(exp);
1432             fail();
1433         } catch (ParseException e) {
1434         }
1435     }
1436
1437     public void testNormal_AssignmentExpression1() {
1438         String exp = "x = 123";
1439
1440         fail();
1441     }
1442
1443     public void testNormal_AssignmentExpression2() {
1444         String exp = "x += 1";
1445
1446         fail();
1447     }
1448
1449     public void testNormal_AssignmentExpression3() {
1450         String exp = "x -= 1";
1451
1452         fail();
1453     }
1454
1455     public void testNormal_AssignmentExpression4() {
1456         String exp = "x *= 2";
1457
1458         fail();
1459     }
1460
1461     public void testNormal_AssignmentExpression5() {
1462         String exp = "x /= 3";
1463
1464         fail();
1465     }
1466
1467     public void testNormal_AssignmentExpression6() {
1468         String exp = "x %= 4";
1469
1470         fail();
1471     }
1472
1473     public void testNormal_AssignmentExpression7() {
1474         String exp = "x &= 1";
1475
1476         fail();
1477     }
1478
1479     public void testNormal_AssignmentExpression8() {
1480         String exp = "x ^= 1";
1481
1482         fail();
1483     }
1484
1485     public void testNormal_AssignmentExpression9() {
1486         String exp = "x |= 1";
1487
1488         fail();
1489     }
1490
1491     public void testNormal_AssignmentExpression10() {
1492         String exp = "x <<= 1";
1493
1494         fail();
1495     }
1496
1497     public void testNormal_AssignmentExpression11() {
1498         String exp = "x >>= 1";
1499
1500         fail();
1501     }
1502
1503     public void testNormal_AssignmentExpression12() {
1504         String exp = "x >>>= 1";
1505
1506         fail();
1507     }
1508
1509     public void testNormal_AssignmentExpression13() {
1510         String exp = "x = y = 1";
1511
1512         fail();
1513     }
1514
1515     public void testFail_AssignmentExpression1() {
1516         String exp = "x = = 1";
1517
1518         RpnParser parser = new RpnParser();
1519         try {
1520             parser.parse(exp);
1521             fail();
1522         } catch (ParseException e) {
1523         }
1524     }
1525
1526 }