-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzheng_lab_13Test.java
129 lines (107 loc) · 3.55 KB
/
zheng_lab_13Test.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
public class zheng_lab_13Test {
zheng_lab_13 lab;
Integer[] expectedResult1;
Integer[] expectedResult2;
Integer[] expectedResult3;
String inputFilename = "lab13_input_data.txt";
String expectedResultsFilename = "lab13_expected_results.txt";
@Before
public void setUp() throws Exception
{
// instantiate an instance of lab13
lab = new zheng_lab_13();
// read the input value and populate the ArrayList<Integer> in the lab13 class
lab.readData(inputFilename);
// testData.get(0) has the expected results for getResult1()
// testData.get(1) has the expected results for getResult2()
// testData.get(2) has the expected results for getResult3()
ArrayList<ArrayList<Integer>> testData = new ArrayList<>();
for( int i = 0; i < 3; i++ )
{
testData.add(new ArrayList<Integer>());
}
try
{
System.out.println("reading " + expectedResultsFilename);
java.io.BufferedReader input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(expectedResultsFilename)));
for( int i = 0; i < testData.size(); i++ )
{
ArrayList<Integer> currentTestData = testData.get(i);
String inn;
input.readLine();
while( (inn = input.readLine()) != null )
{
if( inn.length() > 0 )
{
currentTestData.add(Integer.valueOf(inn));
}
else
{
break;
}
}
testData.set(i, currentTestData);
System.out.println("testData.get(" + i + ").size() = " + testData.get(i).size());
}
input.close();
// put code here to populate expectedResult1 with the values in testData.get(0)
// so that you can use "assertArrayEquals" to verify expectedResult1 and lab.getResult1() are the same
expectedResult1 = new Integer[testData.get(0).size()];
for(int i = 0; i < testData.get(0).size(); i++)
{
expectedResult1[i] = testData.get(0).get(i);
}
// put code here to populate expectedResult2 with the values in testData.get(1)
// so that you can use "assertArrayEquals" to verify expectedResult2 and lab.getResult2() are the same
expectedResult2 = new Integer[testData.get(1).size()];
for(int i = 0; i < testData.get(1).size(); i++)
{
expectedResult2[i] = testData.get(1).get(i);
}
// put code here to populate expectedResult3 with the values in testData.get(2)
// so that you can use "assertArrayEquals" to verify expectedResult3 and lab.getResult3() are the same
expectedResult3 = new Integer[testData.get(2).size()];
for(int i = 0; i < testData.get(2).size(); i++)
{
expectedResult3[i] = testData.get(2).get(i);
}
}
catch(Exception e)
{
System.out.println(e.toString());
System.exit(0);
}
}
@Test
public void testGetTotalCount() {
assertEquals(1000, lab.getTotalCount());
}
@Test
public void testGetOddCount() {
assertEquals(507, lab.getOddCount());
}
@Test
public void testGetEvenCount() {
assertEquals(493, lab.getEvenCount());
}
@Test
public void testGetDistinctGreaterThanFiveCount() {
assertEquals(94, lab.getDistinctGreaterThanFiveCount());
}
@Test
public void testGetResult1() {
assertArrayEquals(expectedResult1, lab.getResult1());
}
@Test
public void testGetResult2() {
assertArrayEquals(expectedResult2, lab.getResult2());
}
@Test
public void testGetResult3() {
assertArrayEquals(expectedResult3, lab.getResult3());
}
}