-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestEvaluate.java
More file actions
60 lines (47 loc) · 1.63 KB
/
TestEvaluate.java
File metadata and controls
60 lines (47 loc) · 1.63 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
package gp_project;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class TestEvaluate {
static FunctionEvaluator m_fEval;
@Before
public void setUp() throws Exception {
m_fEval = new FunctionEvaluator();
}
@Test
public void testEvaluateSimplePostOrderList() {
List<String> postOrderList = Arrays.asList("2", "3", "*");
double xValue = 0.0; //doesn't really matter since x is not in this tree
EvaluationResult result = m_fEval.evaluate(postOrderList, xValue);
assertEquals(result.yValue, 6, 0);
}
@Test
public void testEvaluatePostOrderList() {
List<String> postOrderList = Arrays.asList("3","2","*","6","2","/","+");
double xValue = 0.0; //doesn't really matter since x is not in this tree
EvaluationResult result = m_fEval.evaluate(postOrderList, xValue);
assertEquals(result.yValue, 9, 0);
}
@Test
public void testEvaluatePostOrderListWithVariable() {
List<String> postOrderList = Arrays.asList("3","x","*","6","x","/","+");
double xValue = 2.0;
EvaluationResult result = m_fEval.evaluate(postOrderList, xValue);
assertEquals(result.yValue, 9, 0);
}
@Test
public void testGetOperator()
{
assertEquals(FunctionEvaluator.getOperator("+"), OperatorType.ADD);
assertEquals(FunctionEvaluator.getOperator("-"), OperatorType.SUBTRACT);
assertEquals(FunctionEvaluator.getOperator("/"), OperatorType.DIVIDE);
assertEquals(FunctionEvaluator.getOperator("*"), OperatorType.MULTIPLY);
}
@Test(expected=IllegalArgumentException.class)
public void testInvalidOperator()
{
FunctionEvaluator.getOperator("%");
}
}