-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathFilterTest.java
130 lines (113 loc) · 3.66 KB
/
FilterTest.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
package simpledb;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;
import org.junit.Before;
import org.junit.Test;
import simpledb.systemtest.SimpleDbTestBase;
public class FilterTest extends SimpleDbTestBase {
int testWidth = 3;
DbIterator scan;
/**
* Initialize each unit test
*/
@Before public void setUp() {
this.scan = new TestUtil.MockScan(-5, 5, testWidth);
}
/**
* Unit test for Filter.getTupleDesc()
*/
@Test public void getTupleDesc() {
Predicate pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(0));
Filter op = new Filter(pred, scan);
TupleDesc expected = Utility.getTupleDesc(testWidth);
TupleDesc actual = op.getTupleDesc();
assertEquals(expected, actual);
}
/**
* Unit test for Filter.rewind()
*/
@Test public void rewind() throws Exception {
Predicate pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(0));
Filter op = new Filter(pred, scan);
op.open();
assertTrue(op.hasNext());
assertNotNull(op.next());
assertTrue(TestUtil.checkExhausted(op));
op.rewind();
Tuple expected = Utility.getHeapTuple(0, testWidth);
Tuple actual = op.next();
assertTrue(TestUtil.compareTuples(expected, actual));
op.close();
}
/**
* Unit test for Filter.getNext() using a < predicate that filters
* some tuples
*/
@Test public void filterSomeLessThan() throws Exception {
Predicate pred;
pred = new Predicate(0, Predicate.Op.LESS_THAN, TestUtil.getField(2));
Filter op = new Filter(pred, scan);
TestUtil.MockScan expectedOut = new TestUtil.MockScan(-5, 2, testWidth);
op.open();
TestUtil.compareDbIterators(op, expectedOut);
op.close();
}
/**
* Unit test for Filter.getNext() using a < predicate that filters
* everything
*/
@Test public void filterAllLessThan() throws Exception {
Predicate pred;
pred = new Predicate(0, Predicate.Op.LESS_THAN, TestUtil.getField(-5));
Filter op = new Filter(pred, scan);
op.open();
assertTrue(TestUtil.checkExhausted(op));
op.close();
}
/**
* Unit test for Filter.getNext() using an = predicate
*/
@Test public void filterEqual() throws Exception {
Predicate pred;
this.scan = new TestUtil.MockScan(-5, 5, testWidth);
pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(-5));
Filter op = new Filter(pred, scan);
op.open();
assertTrue(TestUtil.compareTuples(Utility.getHeapTuple(-5, testWidth),
op.next()));
op.close();
this.scan = new TestUtil.MockScan(-5, 5, testWidth);
pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(0));
op = new Filter(pred, scan);
op.open();
assertTrue(TestUtil.compareTuples(Utility.getHeapTuple(0, testWidth),
op.next()));
op.close();
this.scan = new TestUtil.MockScan(-5, 5, testWidth);
pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(4));
op = new Filter(pred, scan);
op.open();
assertTrue(TestUtil.compareTuples(Utility.getHeapTuple(4, testWidth),
op.next()));
op.close();
}
/**
* Unit test for Filter.getNext() using an = predicate passing no tuples
*/
@Test public void filterEqualNoTuples() throws Exception {
Predicate pred;
pred = new Predicate(0, Predicate.Op.EQUALS, TestUtil.getField(5));
Filter op = new Filter(pred, scan);
op.open();
TestUtil.checkExhausted(op);
op.close();
}
/**
* JUnit suite target
*/
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(FilterTest.class);
}
}