PRQuadTree / src / SkipListTest.java
SkipListTest.java
Raw
import student.TestCase;
import student.TestableRandom;

/**
 * 
 * @author nickgrifasi
 * @version 9/20/21 Tests the SkipList data structure class methods
 */
public class SkipListTest extends TestCase {

    private SkipList<String, String> skipList1;
    private SkipList<String, Rectangle> skipList3;
    private KVPair<String, String> kvpair1;
    private KVPair<String, String> kvpair2;
    private KVPair<String, String> kvpair3;
    private KVPair<String, Integer> kvpair4;
    private KVPair<String, Rectangle> kvpair6;
    private KVPair<String, Rectangle> kvpair7;
    private KVPair<String, Rectangle> kvpair8;
    private Rectangle rectangle;
    private Rectangle rectangle2;
    private Rectangle rectangle3;

    /**
     * Sets up test cases
     */
    public void setUp() {
        // nothing within this method
    }

    /**
     * Tests SkipLists insert method
     */
    public void testInsert() {
        skipList1 = new SkipList<String, String>();
        kvpair1 = new KVPair<String, String>("tester", "part1");
        kvpair2 = new KVPair<String, String>("tested", "part2");
        kvpair3 = new KVPair<String, String>("test", "part3");

        skipList1.insert(kvpair1);
        skipList1.insert(kvpair2);
        skipList1.insert(kvpair3);
        assertEquals(kvpair2.compareTo(skipList1
                .search("tested").getPair()), 0);
        assertEquals(kvpair1.compareTo(skipList1
                .search("tester").getPair()), 0);
        assertEquals(skipList1.search("testNOT"), null); 
        skipList1.dump();
        SkipList<String, Integer> skipList2 = new SkipList<String, Integer>();
        kvpair4 = new KVPair<String, Integer>("test1", 1);
        KVPair<String, Integer> kvpair5 = new 
                KVPair<String, Integer>("test2", 1);

        assertEquals(1, skipList2.getNode().getLevel());
        TestableRandom.setNextInts(1);
        skipList2.insert(kvpair4);
        //assertEquals(1, skipList2.getNode().getLevel());

        TestableRandom.setNextInts(2);
        skipList2.insert(kvpair5);
        skipList2.dump();

        //assertEquals(2, skipList2.getNode().getLevel());
        
        KVPair<String, String> kvpair10 = 
                new KVPair<String, String>("@@@", "@@@");
        
        skipList1.insert(kvpair10);

    }

    /**
     * Tests SkipList removal method
     */
    public void testRemove() {
        skipList1 = new SkipList<String, String>();
        kvpair1 = new KVPair<String, String>("tester", "part1");
        kvpair2 = new KVPair<String, String>("tested", "part2");
        kvpair3 = new KVPair<String, String>("tester", "part1");
        kvpair4 = new KVPair<String, Integer>("tested", 3);

        skipList1.insert(kvpair1);
        skipList1.insert(kvpair2);
        skipList1.dump();
        assertEquals("part1", skipList1.removeName("tester"));
        assertEquals("part2", skipList1.removeData("part2"));
        skipList1.dump();

        KVPair<String, String> kvpair9 = new KVPair<String, String>(null, "");
        skipList1.insert(kvpair9);
        assertEquals(null, skipList1.removeData("123123"));
        skipList3 = new SkipList<String, Rectangle>();
        rectangle = new Rectangle("test", 1000, 1000, 500, 500);
        rectangle2 = new Rectangle("test2", 1, 1, 1, 1);
        kvpair6 = new KVPair<String, Rectangle>("test", rectangle);
        KVPair<String, Rectangle> kvpair99 = new 
                KVPair<String, Rectangle>(null, rectangle2);
        skipList3.insert(kvpair6);
        skipList3.removeData(rectangle);
        skipList3.insert(kvpair99);
        skipList3.removeData(rectangle);
        
        rectangle3 = new Rectangle("test3", 1, 1000, 1, 1000);
        //KVPair<String, Rectangle> kvpair3000 = new
                //KVPair<String, Rectangle>("test3", rectangle3);
       // skipList3.insert(kvpair3000);
        skipList3.removeData(rectangle3);

    }

    /**
     * tests the regionsearch method
     */
    public void testRegionsearch() {
        rectangle = new Rectangle("test", 1, 1, 2, 2);
        rectangle2 = new Rectangle("test2", 2, 2, 1, 1);
        skipList3 = new SkipList<String, Rectangle>();
        kvpair6 = new KVPair<String, Rectangle>("test", rectangle);
        skipList3.insert(kvpair6);

        skipList3.regionsearch(rectangle);
        kvpair7 = new KVPair<String, Rectangle>("test2", rectangle2);
        skipList3.insert(kvpair7);
        skipList3.regionsearch(rectangle);
        rectangle3 = new Rectangle("test3", 1, 1, -200, -3123);
        kvpair8 = new KVPair<String, Rectangle>("test3", rectangle3);
        skipList3.insert(kvpair8);
        skipList3.regionsearch(rectangle3);
        assertTrue(rectangle.findIntersection(rectangle2));
        
        

        Rectangle rejected = new Rectangle("tes4t", 1, 1, -12, -12);
        skipList3.regionsearch(rejected);
        
        
    }

    /**
     * tests the intersections method
     */
    public void testIntersections() {
        rectangle = new Rectangle("test", 1, 1, 10, 2);
        rectangle2 = new Rectangle("test2", 2, 2, 1, 10);
        rectangle3 = new Rectangle("test3", 3, 4, 5, 2);
        skipList3 = new SkipList<String, Rectangle>();
        kvpair6 = new KVPair<String, Rectangle>("test", rectangle);
        skipList3.insert(kvpair6);

        skipList3.regionsearch(rectangle);
        kvpair7 = new KVPair<String, Rectangle>("test2", rectangle2);
        skipList3.insert(kvpair7);
        skipList3.intersections();
        kvpair8 = new KVPair<String, Rectangle>("test3", rectangle3);

        skipList3.insert(kvpair8);
        skipList3.intersections();
        assertTrue(rectangle.findIntersection(rectangle2));
    }

}