PRQuadTree / src / PRQuadtreeTest.java
PRQuadtreeTest.java
Raw
import student.TestCase;
/**
 * Tests the methods in the PRQuadtree class
 * @author nickgrifasi
 * @version 10/15/21
 */
public class PRQuadtreeTest extends TestCase {
    
    private PRQuadtree quadtree;
    private Point test5;
    private Point test6;
    private Point test7;
    
    
    
    
    /**
     * sets up the test method
     */
    public void setUp()
    {
        quadtree = new PRQuadtree();
    }
    
    /**
     * tests the insert method in QuadTree
     */
    public void testInsert()
    {
        Point test1 = new Point("test1", 5, 25);
        Point test2 = new Point("test2", 15, 35);
        Point test3 = new Point("test3", 5, 25);
        Point test4 = new Point("test4", 200, 200);
        
        quadtree.insert(test1);
        quadtree.insert(test2);
        quadtree.insert(test3);
        quadtree.insert(test4);
        quadtree.dump();
        
        String dumpFile = systemOut().getHistory();
        
        assertEquals("QuadTree dump:\n" +
            "Node at 0, 0, 1024: Internal\n" + 
                "  Node at 0, 0, 512: Internal\n" + 
            "    Node at 0, 0, 256: Internal\n" + 
                "      Node at 0, 0, 128:\n" + 
            "      (test1, 5, 25)\n" + 
                "      (test3, 5, 25)\n" + 
            "      (test2, 15, 35)\n" + 
                "      Node at 128, 0, 128: Empty\n" + 
            "      Node at 0, 128, 128: Empty\n" + 
                "      Node at 128, 128, 128:\n" + 
            "      (test4, 200, 200)\n" + 
                "    Node at 256, 0, 256: Empty\n" + 
            "    Node at 0, 256, 256: Empty\n" + 
                "    Node at 256, 256, 256: Empty\n" + 
            "  Node at 512, 0, 512: Empty\n" + 
                "  Node at 0, 512, 512: Empty\n" + 
            "  Node at 512, 512, 512: Empty\n" + 
                "13 quadtree nodes printed\n"
              , dumpFile);
        quadtree.remove(test3, true);
        quadtree.remove(test3, false);
   
    }
    
    /**
     * tests duplicate method
     */
    public void testDuplicate()
    {
        test5 = new Point("test2", 15, 35);
        test6 = new Point("test3", 5, 25);
        test7 = new Point("test4", 15, 35);
        
        quadtree.insert(test5);
        quadtree.insert(test6);
        quadtree.insert(test7);
        
        
        quadtree.findDuplicates();
        String duplicateFile = systemOut().getHistory();
        assertEquals("(15, 35)\n", duplicateFile);
        
        
    }
    
    /**
     * tests duplicate method
     */
    public void testDuplicate2()
    {
        test5 = new Point("test2", 15, 35);
        test6 = new Point("test3", 5, 25);
        test7 = new Point("test4", 15, 35);
        
        quadtree.insert(test5);
        quadtree.insert(test6);
        quadtree.insert(test7);
        
        
        String duplicateFile = systemOut().getHistory();
        quadtree.remove(test7, false);
        quadtree.findDuplicates();
        assertEquals("", duplicateFile);
        
    }
}