1+ using NUnit . Framework ;
2+ using StackCalculator ;
3+ using System ;
4+
5+ namespace TestStackCalculator ;
6+
7+ /// <summary>
8+ /// A class for testing a stack calculator
9+ /// </summary>
10+ public class TestsStackCalculator
11+ {
12+ Calculator ? stackCalculator ;
13+ [ SetUp ]
14+ public void Setup ( )
15+ {
16+ stackCalculator = new Calculator ( ) ;
17+ }
18+
19+ [ Test ]
20+ public void DevideByZero ( )
21+ {
22+ string [ ] firstArray = { "123" , "0" , "/" } ;
23+ Assert . Throws < System . DivideByZeroException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
24+ }
25+
26+ [ Test ]
27+ public void ExpressionFromInvalidCharacter ( )
28+ {
29+ string [ ] firstArray = { "123" , "0" , "a" } ;
30+ Assert . Throws < InvalidCharacterException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
31+ }
32+
33+ [ Test ]
34+ public void FirstIncorrectExpression ( )
35+ {
36+ string [ ] firstArray = { "123" , "4" , "*" , "-" } ;
37+ Assert . Throws < IncorrectExpressionException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
38+ }
39+
40+ [ Test ]
41+ public void SecondIncorrectExpression ( )
42+ {
43+ string [ ] firstArray = { "123" , "4" , "9" , "23" , "*" , "-" } ;
44+ Assert . Throws < IncorrectExpressionException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
45+ }
46+
47+ [ Test ]
48+ public void ValidOneCharacterExpression ( )
49+ {
50+ string [ ] firstArray = { "12" } ;
51+ Assert . AreEqual ( 12 , stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
52+ }
53+
54+
55+ [ Test ]
56+ public void ValidExpressionFromZeros ( )
57+ {
58+ string [ ] firstArray = { "0" , "0" , "+" , "0" , "-" } ;
59+ Assert . AreEqual ( 0 , stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
60+ }
61+
62+ [ Test ]
63+ public void ExpressionWithoutNumbers ( )
64+ {
65+ string [ ] firstArray = { "+" , "-" } ;
66+ Assert . Throws < IncorrectExpressionException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
67+ }
68+
69+ [ Test ]
70+ public void EmptyString ( )
71+ {
72+ string [ ] firstArray = { " " } ;
73+ Assert . Throws < IncorrectExpressionException > ( ( ) => stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
74+ }
75+
76+ [ Test ]
77+ public void LongExpression ( )
78+ {
79+ string [ ] firstArray = { "0" , "120" , "+" , "45" , "15" , "/" , "33" , "+" , "-5" , "-13" , "+" , "9" , "/" , "/" , "1" , "123" , "*" , "+" , "-" } ;
80+ Assert . AreEqual ( 15 , stackCalculator ? . CountTheExpressionInPostfixForm ( firstArray ) ) ;
81+ }
82+ }
0 commit comments