ajantha-bhat commented on a change in pull request #3481: [CARBONDATA-3548]Geospatial Support: add hash id create,query condition analyze and generate hash id list
URL: https://github.com/apache/carbondata/pull/3481#discussion_r375603747 ########## File path: geo/src/test/java/org/apache/carbondata/geo/QuadTreeClsTest.java ########## @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.carbondata.geo; + +import org.junit.*; +import org.junit.rules.ExpectedException; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.matchers.JUnitMatchers.containsString; + + +/** + * QuadTreeClsTest Tester. + */ +public class QuadTreeClsTest { + + @Rule + public ExpectedException exception = ExpectedException.none(); + + QuadTreeCls qtreee; + + @Before + public void before() throws Exception { + qtreee = new QuadTreeCls(0, 0, 16, 16, 4 ); + } + + @After + public void after() throws Exception { + qtreee.clean(); + } + + @Test + public void testInsertPolygonFirstAndLastPoint() throws Exception { + //Insert the entire area, directly root + List<double[]> pointList = new ArrayList<>(); + pointList.add(new double[] {0, 0}); + pointList.add(new double[] {0, 16}); + pointList.add(new double[] {16, 16}); + pointList.add(new double[] {16, 0}); + exception.expect(RuntimeException.class); + exception.expectMessage("please make first point the same as last point"); + qtreee.insert(pointList); + } + + /** + * The test just inserts the entire coordinate area + */ + @Test + public void testInsertPolygonFullRange() throws Exception { + //Insert the entire area, directly root + List<double[]> pointList = new ArrayList<>(); + pointList.add(new double[] {0, 0}); + pointList.add(new double[] {0, 16}); + pointList.add(new double[] {16, 16}); + pointList.add(new double[] {16, 0}); + pointList.add(new double[] {0, 0}); + qtreee.insert(pointList); + Assume.assumeTrue(qtreee.getRoot().getGrid().getStatus() == GridData.STATUS_ALL); + Long[] gridRange = qtreee.getRoot().getGrid().getHashIDRange(); + Assume.assumeTrue(gridRange[0] == 0); + Assume.assumeTrue(gridRange[1] == 255); + } + + /** + * Test insertion area is larger than the whole area + */ + @Test + public void testInsertBiggerPolygon() throws Exception { + List<double[]> pointList = new ArrayList<>(); + pointList.add(new double[] {4.3, 20}); + pointList.add(new double[] {7.3, 13.8}); + pointList.add(new double[] {18, 11.8}); + pointList.add(new double[] {11.5, 6.3}); + pointList.add(new double[] {4.3, 20}); + + qtreee.insert(pointList); + QuadNode root = qtreee.getRoot(); + + Assume.assumeTrue(root.childrenIsNull()); + } + + /** + * Illegal test insertion area + */ + @Test + public void testInsertLessThan3Points() throws Exception { + List<double[]> pointList = new ArrayList<>(); + pointList.add(new double[] {4.3, 9.4}); + pointList.add(new double[] {7.3, 13.8}); + exception.expect(RuntimeException.class); + exception.expectMessage("polygon at least need 4 points, first and last is same."); + qtreee.insert(pointList); + QuadNode root = qtreee.getRoot(); + Assume.assumeTrue(root.childrenIsNull()); + } + + /** + * Test creation Hadid + */ + @Test + public void testCreateHashID() throws Exception { + GridData grid = new GridData(0,0, 15,15,4); + // Here is a grid + Assume.assumeTrue(grid.createHashID(0,0) == 0); + Assume.assumeTrue(grid.createHashID(0,1) == 1); + Assume.assumeTrue(grid.createHashID(1,0) == 2); + Assume.assumeTrue(grid.createHashID(1,1) == 3); + + Assume.assumeTrue(grid.createHashID(0,2) == 4); + Assume.assumeTrue(grid.createHashID(0,3) == 5); + Assume.assumeTrue(grid.createHashID(1,2) == 6); + Assume.assumeTrue(grid.createHashID(1,3) == 7); + + Assume.assumeTrue(grid.createHashID(2,0) == 8); + Assume.assumeTrue(grid.createHashID(2,1) == 9); + Assume.assumeTrue(grid.createHashID(3,0) == 10); + Assume.assumeTrue(grid.createHashID(3,1) == 11); + + Assume.assumeTrue(grid.createHashID(2,2) == 12); + Assume.assumeTrue(grid.createHashID(2,3) == 13); + Assume.assumeTrue(grid.createHashID(3,2) == 14); + Assume.assumeTrue(grid.createHashID(3,3) == 15); + // Center point + Assume.assumeTrue(grid.createHashID(0,4) == 16); + Assume.assumeTrue(grid.createHashID(0,5) == 17); + Assume.assumeTrue(grid.createHashID(1,4) == 18); + Assume.assumeTrue(grid.createHashID(1,5) == 19); + + Assume.assumeTrue(grid.createHashID(0,6) == 20); + Assume.assumeTrue(grid.createHashID(0,7) == 21); + Assume.assumeTrue(grid.createHashID(1,6) == 22); + Assume.assumeTrue(grid.createHashID(1,7) == 23); + + Assume.assumeTrue(grid.createHashID(2,4) == 24); + Assume.assumeTrue(grid.createHashID(2,5) == 25); + Assume.assumeTrue(grid.createHashID(3,4) == 26); + Assume.assumeTrue(grid.createHashID(3,5) == 27); + + Assume.assumeTrue(grid.createHashID(2,6) == 28); + Assume.assumeTrue(grid.createHashID(2,7) == 29); + Assume.assumeTrue(grid.createHashID(3,6) == 30); + Assume.assumeTrue(grid.createHashID(3,7) == 31); + + + System.out.println(grid.createHashID(7,7)); Review comment: remove the print statement from the test case, just keep the assert ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |