1 Star 0 Fork 0

lius511/simple-db-hw-2021

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FilterTest.java 3.87 KB
一键复制 编辑 原始数据 按行查看 历史
Tianyu Li 提交于 2021-03-09 11:40 +08:00 . add lab2 files
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.common.Utility;
import simpledb.execution.Filter;
import simpledb.execution.OpIterator;
import simpledb.execution.Predicate;
import simpledb.storage.Tuple;
import simpledb.storage.TupleDesc;
import simpledb.systemtest.SimpleDbTestBase;
public class FilterTest extends SimpleDbTestBase {
final int testWidth = 3;
OpIterator 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);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/lius511/simple-db-hw-2021.git
git@gitee.com:lius511/simple-db-hw-2021.git
lius511
simple-db-hw-2021
simple-db-hw-2021
master

搜索帮助