Example #1
0
  @Test
  public void testEquals() {
    TupleDesc singleInt = new TupleDesc(new Type[] {Type.INT_TYPE});
    TupleDesc singleInt2 = new TupleDesc(new Type[] {Type.INT_TYPE});
    TupleDesc intString = new TupleDesc(new Type[] {Type.INT_TYPE, Type.STRING_TYPE});

    // .equals() with null should return false
    assertFalse(singleInt.equals(null));

    // .equals() with the wrong type should return false
    assertFalse(singleInt.equals(new Object()));

    assertTrue(singleInt.equals(singleInt));
    assertTrue(singleInt.equals(singleInt2));
    assertTrue(singleInt2.equals(singleInt));
    assertTrue(intString.equals(intString));

    assertFalse(singleInt.equals(intString));
    assertFalse(singleInt2.equals(intString));
    assertFalse(intString.equals(singleInt));
    assertFalse(intString.equals(singleInt2));
  }
Example #2
0
 /**
  * Adds the specified tuple to the page; the tuple should be updated to reflect that it is now
  * stored on this page.
  *
  * @throws DbException if the page is full (no empty slots) or tupledesc is mismatch.
  * @param t The tuple to add.
  */
 public void insertTuple(Tuple t) throws DbException {
   // some code goes here
   // not necessary for lab1
   RecordId targetrid = t.getRecordId();
   if (getNumEmptySlots() == 0 || !td.equals(t.getTupleDesc())) {
     throw new DbException("Either page is full or tuple desc doesn't match");
   }
   for (int i = 0; i < getNumTuples(); i++) {
     if (!isSlotUsed(i)) {
       markSlotUsed(i, true);
       RecordId rid = new RecordId(pid, i);
       t.setRecordId(rid);
       tuples[i] = t;
       return;
     }
   }
 }