-
Notifications
You must be signed in to change notification settings - Fork 15
/
InsertTest.java
66 lines (56 loc) · 1.61 KB
/
InsertTest.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
package simpledb;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;
/**
* We reserve more heavy-duty insertion testing for HeapFile and HeapPage.
* This suite is superficial.
*/
public class InsertTest extends TestUtil.CreateHeapFile {
private DbIterator scan1;
private TransactionId tid;
/**
* Initialize each unit test
*/
@Before public void setUp() throws Exception {
super.setUp();
this.scan1 = TestUtil.createTupleList(2,
new int[] { 1, 2,
1, 4,
1, 6,
3, 2,
3, 4,
3, 6,
5, 7 });
this.tid = new TransactionId();
}
/**
* Unit test for Insert.getTupleDesc()
*/
@Test public void getTupleDesc() throws Exception {
Insert op = new Insert(tid, scan1, empty.getId());
TupleDesc expected = Utility.getTupleDesc(1);
TupleDesc actual = op.getTupleDesc();
assertEquals(expected, actual);
}
/**
* Unit test for Insert.getNext(), inserting elements into an empty file
*/
@Test public void getNext() throws Exception {
Insert op = new Insert(tid, scan1, empty.getId());
op.open();
assertTrue(TestUtil.compareTuples(
Utility.getHeapTuple(7, 1), // the length of scan1
op.next()));
// we should fit on one page
assertEquals(1, empty.numPages());
}
/**
* JUnit suite target
*/
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(InsertTest.class);
}
}