func TestPoint8(t *testing.T) { point1 := geo.NewPoint("1", "0") point2 := geo.NewPoint("11", "01") point3 := geo.NewPoint("110", "010") point4 := geo.NewPoint("1101", "0100") point5 := geo.NewPoint("1100", "0111") node1 := testTree.Find(point1) assert.Equal(t, node1.hash, "11", "node1 hash") node2 := testTree.Find(point2) assert.Equal(t, node2.hash, "1100", "node2 hash") node3 := testTree.Find(point3) assert.Equal(t, node3.hash, "110010", "node3 hash") node4 := testTree.Find(point4) assert.Equal(t, node4.hash, "11001001", "node4 hash") node5 := testTree.Find(point5) assert.Equal(t, node5.hash, "11001111", "node5 hash") assert.Equal(t, node1.parent.orient, c.U, "node1 orient") assert.Equal(t, node2.parent.orient, c.L, "node2 orient") assert.Equal(t, node3.parent.orient, c.D, "node3 orient") assert.Equal(t, node4.parent.orient, c.D, "node4 orient") assert.Equal(t, node5.parent.orient, c.R, "node5 orient") assert.True(t, node4.ContainsPoint(point4)) }
func TestRangeQuery(t *testing.T) { assert.Equal(t, len(testTree.RangeQuery(geo.NewPoint("000", "000"), geo.NewPoint("111", "111"))), pointsInserted) numOfMatches := 0 min := geo.NewPoint("100", "000") max := geo.NewPoint("111", "011") matches := testTree.RangeQuery(min, max) for n := testTree.next; n.next != nil; n = n.next { if n.isWithinRange(min, max) { numOfMatches++ } } assert.Equal(t, 84, numOfMatches) assert.Equal(t, len(matches)-1, numOfMatches) }
func init() { testTree = NewTree(1) for i := 0; i < 2; i++ { for j := 0; j < 2; j++ { x := fmt.Sprintf("%01s", strconv.FormatInt(int64(i), 2)) y := fmt.Sprintf("%01s", strconv.FormatInt(int64(j), 2)) g := geo.NewPoint(x, y) testpoints = append(testpoints, g) testTree.Insert(g) } } for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { x := fmt.Sprintf("%02s", strconv.FormatInt(int64(i), 2)) y := fmt.Sprintf("%02s", strconv.FormatInt(int64(j), 2)) g := geo.NewPoint(x, y) testpoints = append(testpoints, g) testTree.Insert(g) } } for i := 0; i < 8; i++ { for j := 0; j < 8; j++ { x := fmt.Sprintf("%03s", strconv.FormatInt(int64(i), 2)) y := fmt.Sprintf("%03s", strconv.FormatInt(int64(j), 2)) g := geo.NewPoint(x, y) testpoints = append(testpoints, g) testTree.Insert(g) } } for i := 0; i < 16; i++ { for j := 0; j < 16; j++ { x := fmt.Sprintf("%04s", strconv.FormatInt(int64(i), 2)) y := fmt.Sprintf("%04s", strconv.FormatInt(int64(j), 2)) g := geo.NewPoint(x, y) testpoints = append(testpoints, g) testTree.Insert(g) } } fmt.Println("Points inserted:", pointsInserted) }
func TestPoint7(t *testing.T) { point1 := geo.NewPoint("1", "1") point2 := geo.NewPoint("11", "10") point3 := geo.NewPoint("110", "100") node1 := testTree.Find(point1) assert.Equal(t, node1.hash, "10", "node1 hash") node2 := testTree.Find(point2) assert.Equal(t, node2.hash, "1011", "node2 hash") node3 := testTree.Find(point3) assert.Equal(t, node3.hash, "101110", "node3 hash") assert.Equal(t, node1.parent.orient, c.U, "node1 orient") assert.Equal(t, node2.parent.orient, c.U, "node2 orient") assert.Equal(t, node3.parent.orient, c.L, "node3 orient") assert.True(t, node3.ContainsPoint(point3)) }