package simpledb.unittest;

import simpledb.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import junit.framework.JUnit4TestAdapter;

public class HeapPageIdTest {
    
    private HeapPageId pid;
    
    @Before public void setUp() {
	pid = new HeapPageId(1, 1);
    }

    /**
     * Unit test for HeapPageId.tableid()
     */
    @Test public void tableid() {
	assertEquals(1, pid.tableid());
    }
    
    /**
     * Unit test for HeapPageId.pageno()
     */
    @Test public void pageno() {
	assertEquals(1, pid.pageno());
    }

    /**
     * Unit test for HeapPageId.hashCode()
     */
    @Test public void testHashCode() {
	int code1, code2;

	// NOTE(ghuo): the hashCode could be anything. test determinism, 
	// at least.
	pid = new HeapPageId(1, 1);
	code1 = pid.hashCode();
	assertEquals(code1, pid.hashCode());
	assertEquals(code1, pid.hashCode());
	
	pid = new HeapPageId(2, 2);
	code2 = pid.hashCode();
	assertEquals(code2, pid.hashCode());
	assertEquals(code2, pid.hashCode());
    }

    /**
     * Unit test for HeapPageId.equals()
     */
    @Test public void equals() {
	HeapPageId pid1, pid2;

	pid1 = new HeapPageId(1, 1);
	assertTrue(pid.equals(pid1));

	pid2 = new HeapPageId(2, 2);
	assertFalse(pid.equals(pid2));
	
	assertFalse(pid.equals("not a PageId"));
    }

    /**
     * JUnit suite target
     */
    public static junit.framework.Test suite() {
	return new JUnit4TestAdapter(HeapPageIdTest.class);
    }
}

