-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfixPostfixUnitTesting.java
More file actions
77 lines (53 loc) · 2.12 KB
/
InfixPostfixUnitTesting.java
File metadata and controls
77 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import org.junit.Test;
import static org.junit.Assert.*;
public class InfixPostfixUnitTesting {
/**
* Testing ConvertToPostFix
*/
// Tests ConvertToPostfix with a valid infix input
@Test
public void ConvertToPostFix_ValidTest() {
String infixStr1 = "a*b/(c-a)+d*e";
String expectedPostfix1 = "ab*ca-/de*+";
String infixStr2 = "a/b*(c+(d-e))";
String expectedPostfix2 = "ab/cde-+*";
assertEquals(expectedPostfix1,LinkedStackTest.convertToPostfix(infixStr1));
assertEquals(expectedPostfix2,LinkedStackTest.convertToPostfix(infixStr2));
}
// Tests ConvertToPostfix with a null input
@Test
public void ConvertToPostFix_NullTest() {
String infixNull = null;
String expectedReturn = null;
assertEquals(expectedReturn,infixNull);
}
/**
* Testing EvaluatePostfix
*/
// Tests EvaluatePostfix with valid postfix and values for variables
@Test
public void EvaluatePostfix_ValidInput(){
int[] varValues = {2,3,4,5,6};
String postfixStr = "ab*ca-/de*+";
int expectedValue = 33;
assertEquals(expectedValue,ArrayStackTest.evaluatePostfix(postfixStr, varValues));
}
// Tests EvaluatePostfix with a null input for either postfix or variable values
@Test
public void EvaluatePostfix_NullInput() {
// If either input is null, expected return is -1
int expectedReturn = -1;
// Case 1: variable values input is null
int[] varValues1 = null;
String postfixStr1 = "ab*ca-/de*+";
assertEquals(expectedReturn,ArrayStackTest.evaluatePostfix(postfixStr1, varValues1));
// Case 2: postfix input is null
int[] varValues2 = {2,3,4,5,6};
String postfixStr2 = null;
assertEquals(expectedReturn,ArrayStackTest.evaluatePostfix(postfixStr2, varValues2));
// Case 3: postfix input and variable values input are both null
int[] varValues3 = null;
String postfixStr3 = null;
assertEquals(expectedReturn,ArrayStackTest.evaluatePostfix(postfixStr3, varValues3));
}
}