Esempio n. 1
0
def test_sub():
    p1 = Point(2, 5)
    p2 = Point(6, 7)
    actual = p2 - p1
    n.assert_equal(4, actual.x, get_message(4, actual.x))
    n.assert_equal(2, actual.y, get_message(2, actual.y))
Esempio n. 2
0
 def test_point_negative(self):
     """ check if point negative is correct (__neg_) """
     self.assertTrue(-p1 == Point(-1.0, -2.0, 3.0))
Esempio n. 3
0
 def test_point_greater(self):
     """ compare two points to check greater (__gt__) """
     self.assertTrue(p1 > Point(1.0, 2.0, 2.0))
     self.assertFalse(p1 > Point(1.0, 2.0, 6.0))
Esempio n. 4
0
 def test_line_upper_left(self):
     """ checks if upper left point of line is correct """
     self.assertTrue(l4.upperLeft == Point(0.0, 8.0, 0.0))
Esempio n. 5
0
 def test_point_equal(self):
     """ check if point is equal to given point (__eq__) """
     self.assertTrue(p1 == Point(1.0, 2.0, 3.0))
     self.assertFalse(p1 == Point(1.0, 3.0, 4.0))
Esempio n. 6
0
 def test_line_translate(self):
     """ checks if line is translated correctly (translate) """
     self.assertTrue(
         l1.translate(1.0, 2.0, 1.0) == Line(Point(2.0, 4.0, 4.0),
                                             Point(3.0, 6.0, 7.0)))
Esempio n. 7
0
 def test_get_offset_line(self):
     """ checks if correct offset line returned (getOffsetLine) """
     self.assertTrue(
         l4.getOffsetLine(4) == Line(Point(-4.0, 0.0, 0.0),
                                     Point(-4.0, 8.0, 0.0)))
Esempio n. 8
0
#point 를 임포트 하여 사용
from point import Point 

p1 = Point(10,10)
print("repr:",repr(p1))
print("instance count:", Point.instance_count)
p2 = Point(20,20)
print("p2", p2)
print("repr:",repr(p2))


print("instance count : " , Point.instance_count)

# repr 메세지 확인

p2_copy= eval(repr(p2))
print("p2_copy:", p2_copy)

Esempio n. 9
0
def test_unbound_class_method():
    p = Point()
    Point.set_x(p, 20)
    Point.set_y(p, 20)
    Point.show(p)
    p.show()
Esempio n. 10
0
from point import Point

p1 = Point(4, 2)
p2 = Point(3, 7)

print(p1.distance(p2))
Esempio n. 11
0
from line import Line
from point import Point

l1 = Line()
print(l1)
print("length:", l1.length())
p1 = Point(1, 1)
p2 = Point(2, 2)
l1 = Line(p1, p2)
print(l1)
print("length:", l1.length())
p1 = Point(1, 1)
p2 = Point(1, 5)
l1 = Line(p1, p2)
print(l1)
p1 = Point(-1, -1)
print("length:", l1.length())
p2 = Point(-1, -5)
l1 = Line(p1, p2)
print(l1)
print("length:", l1.length())
Esempio n. 12
0
def test_repr():
    p = Point(6, 2)
    expected = 'Point: 6, 2'
    actual = repr(p)
    n.assert_equal(expected, actual, get_message(expected, actual))
Esempio n. 13
0
def test_dist():
    p1 = Point(1, 2)
    p2 = Point(4, 6)
    actual = p1.dist(p2)
    expected = 5.0
    n.assert_almost_equal(expected, actual, msg=get_message(expected, actual))
Esempio n. 14
0
def test_mul():
    p1 = Point(2, 5)
    actual = p1 * 3
    n.assert_equal(6, actual.x, get_message(6, actual.x))
    n.assert_equal(15, actual.y, get_message(15, actual.y))
Esempio n. 15
0
 def test_mirror_line(self):
     """ check if line mirrored correctly about given axis (mirror) """
     self.assertTrue(
         l1.mirror(c.X) == Line(Point(1.0, -2.0, 3.0), Point(
             2.0, -4.0, 6.0)))
Esempio n. 16
0
def bound_class_method():
    p = Point()
    p.set_x(10)
    p.set_y(10)
    p.show()
Esempio n. 17
0
 def test_line_midpoint(self):
     """ checks if midpoint of line is correct (getMidPoint) """
     self.assertTrue(l1.getMidPoint() == Point(1.5, 3.0, 4.5))
Esempio n. 18
0
    def testconstructwithverification(self):
        points = [
            Point([x, 0, 1], Euclidean())
            for x in [8, 1, 2, 32, 64, 81, 80, 160]
        ]
        T = SNT(4, 1, 1, 4)
        T.construct(points, PL)
        ver = SNTVerify(T, points)
        ver.populate()
        self.assertTrue(ver.relativescorrect())
        self.assertTrue(ver.issemicompressed())
        self.assertTrue(ver.islocalnettree())
        self.assertFalse(ver.isglobalnettree())
        T.cc = 4 / 3
        T.cp = 1 / 6
        self.assertTrue(ver.isglobalnettree())

        points = [Point([x], Euclidean()) for x in [7, 44, 30, 24, 76]]
        T = SNT(5, 1, 1)
        T.construct(points, PL)
        ver = SNTVerify(T, points)
        ver.populate()
        self.assertTrue(ver.relativescorrect())
        self.assertTrue(ver.issemicompressed())
        self.assertTrue(ver.islocalnettree())
        T.cc = 5 / 4
        T.cp = 1 / 4
        self.assertTrue(ver.isglobalnettree())

        points = [Point([x], Euclidean()) for x in [25, 20, 54, 30, 40, 0]]
        T = SNT(5, 1, 1)
        T.construct(points, PL)
        ver = SNTVerify(T, points)
        ver.populate()
        self.assertTrue(ver.relativescorrect())
        self.assertTrue(ver.issemicompressed())
        self.assertTrue(ver.islocalnettree())
        T.cc = 5 / 4
        T.cp = 1 / 4
        self.assertTrue(ver.isglobalnettree())

        points = [
            Point([x], Euclidean()) for x in [-55, 93, -90, -14, -13, -12]
        ]
        T = SNT(7, 1, 1)
        T.construct(points, PL)
        ver = SNTVerify(T, points)
        ver.populate()
        self.assertTrue(ver.relativescorrect())
        self.assertTrue(ver.islocalnettree())
        self.assertTrue(ver.issemicompressed())

        metric = Euclidean()
        points = [
            Point([random.randint(-10000, 10000) for _ in range(2)], metric)
            for _ in range(200)
        ]
        tmp = list()
        for p in points:
            if p in tmp:
                print('duplicate:', p)
            else:
                tmp.append(p)
        points = tmp
        tau = 7
        T = SNT(tau, 1, 1)
        T.construct(points, PL)
        ver = SNTVerify(T, points)
        ver.populate()
        self.assertTrue(ver.relativescorrect())
        self.assertTrue(ver.islocalnettree())
        self.assertTrue(ver.issemicompressed())
        T.cc = tau / (tau - 1)
        T.cp = (tau - 3) / (2 * (tau - 1))
        self.assertTrue(ver.isglobalnettree())
Esempio n. 19
0
 def test_line_rotate(self):
     """ checks if line is rotated correctly (rotate) """
     self.assertTrue(
         l1.rotate(np.pi / 2, Point(0, 0)) == Line(Point(-2.0, 1.0, 3.0),
                                                   Point(-4.0, 2.0, 6.0)))
Esempio n. 20
0
 def arbitrary_point(self, parameter_name='t'):
     """Returns a symbolic point that is on the ellipse."""
     t = C.Symbol(parameter_name, real=True)
     return Point(self.center[0] + self.hradius * C.cos(t),
                  self.center[1] + self.vradius * C.sin(t))
Esempio n. 21
0
 def test_do_lines_intersect(self):
     """ checks if lines intersect and returns nature of intersection """
     self.assertTrue(l4.segmentsIntersect(l5) == (1, Point(0, 6, 0)))
Esempio n. 22
0
 def __init__(self):
     self.center = Point()
     self.velocity = Velocity()
     self.radius = 0.0
     self.alive = True
Esempio n. 23
0
 def test_line_lower_right(self):
     """ checks if lower right point of line is correct """
     self.assertTrue(l4.lowerRight == Point(0.0, 0.0))
Esempio n. 24
0
    pri_grid, privacy_sum = privacy_init(grid_x, grid_y, grid_z, occ_grid,
                                         privacy_radius)
    print("The occ_grid is: ")
    for m in range(grid_x):
        print("The value of x: ", m)
        print(occ_grid[m])
    starttime = time.time()
    aStar = AStar(occ_grid, pri_grid_known, grid, privacy_sum_known,
                  starting_point, end_point, 1, T_budget)
    # 开始寻路
    #trajectory_ref = aStar.start()
    trajectory_ref_temp = np.load(file="refpath.npy")
    trajectory_ref = []
    for i in range(len(trajectory_ref_temp)):
        point = Point(int(trajectory_ref_temp[i][0]),
                      int(trajectory_ref_temp[i][1]),
                      int(trajectory_ref_temp[i][2]),
                      int(trajectory_ref_temp[i][3]))
        trajectory_ref.append(point)

    endtime = time.time()
    dtime = endtime - starttime
    print("程序运行时间:%.8s s" % dtime)

    path_grid = copy.deepcopy(occ_grid)

    # print(len(pathList))
    sum = 0
    if trajectory_ref == None:
        print("No solution!")
        exit(0)
    else:
Esempio n. 25
0
 def test_point_notequal(self):
     """ check points are not equal (__ne__) """
     self.assertTrue(p1 != Point(1.0, 2.0, 8.0))
     self.assertFalse(p1 != Point(1.0, 2.0, 3.0))
Esempio n. 26
0
    def searchNear(self, minF, offsetX, offsetY, offsetZ, cam):
        """
        搜索节点周围的点
        :param minF:F值最小的节点
        :param offsetX:坐标偏移量
        :param offsetY:
        :return:
        """
        # 越界检测
        if (minF.point.x + offsetX < 0
                or minF.point.x + offsetX > self.grid[0] - 1
                or minF.point.y + offsetY < 0
                or minF.point.y + offsetY > self.grid[1] - 1
                or minF.point.z + offsetZ < 0
                or minF.point.z + offsetZ > self.grid[2] - 1):
            return
        # 如果是障碍,就忽略
        # if self.map3d[minF.point.x + offsetX][minF.point.y + offsetY][minF.point.z + offsetZ] != self.passTag:
        # if self.map3d[minF.point.x + offsetX][minF.point.y + offsetY][minF.point.z + offsetZ] in self.passTag:
        if self.map3d[minF.point.x +
                      offsetX][minF.point.y +
                               offsetY][minF.point.z +
                                        offsetZ] == self.passTag:
            return
        # 如果在关闭表中,就忽略
        currentPoint = Point(minF.point.x + offsetX, minF.point.y + offsetY,
                             minF.point.z + offsetZ, cam)
        if self.pointInCloseList(currentPoint):
            return
        """new setting for time limit"""

        # 设置单位花费
        # step = 1/self.ideallength
        step = 1

        # delta_g = step + privacy_threat
        delta_g = step

        # 如果不在openList中,就把它加入openlist
        # currentNode = self.pointInOpenList(currentPoint)
        # 用一个列表来收集相同的点
        """
        same_point_list = self.the_same_points_in_open_list(currentPoint)
        if not same_point_list:
            # print("currentPoint:", currentPoint, currentNode)
            currentNode = AStar.Node(currentPoint, self.endPoint, self.ideallength, g=minF.g + delta_g)
            currentNode.father = minF
            currentNode.cam = minF.cam + cam
            currentNode.step = minF.step + 1
            self.openList.append(currentNode)

            #print("MinF$$$$$: ", minF.step, minF.point, currentNode.step, currentNode.point)
            return
        """
        currentNode = self.pointInOpenList(currentPoint)
        if not currentNode:
            currentNode = AStar.Node(currentPoint,
                                     self.endPoint,
                                     self.ideallength,
                                     g=minF.g + delta_g)
            currentNode.father = minF
            #self.openList.append(currentNode)
            heappush(self.openList, currentNode)
            return
        # 如果在openList中,判断minF到当前点的G是否更小
        if minF.g + delta_g < currentNode.g:  # 如果更小,就重新计算g值,并且改变father
            currentNode.g = minF.g + delta_g
            currentNode.father = minF
        """
Esempio n. 27
0
 def test_point_lesser(self):
     """ compare two points to check lesser (__lt__) """
     self.assertTrue(p1 < Point(2.0, 4.0, 6.0))
     self.assertFalse(p1 < Point(1.0, 2.0, 2.0))
Esempio n. 28
0
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 26 13:53:41 2017

@author: siddhant
"""

import unittest
from point import Point
import constants as c
from line import Line
import numpy as np

p1 = Point(1.0, 2.0, 3.0)
p2 = Point(2.0, 4.0, 6.0)
p3 = Point(6.0, 12.0, 18.0)
p4 = Point(8.0, 12.0, 14.0)

l1 = Line(p1, p2)
l2 = Line(p1, p3)
l3 = Line(p1, p2)
l4 = Line(Point(0, 0), Point(0, 8, 0))
l5 = Line(Point(4, 0, 0), Point(0, 6, 0))


class PointTestCase(unittest.TestCase):

    #def test_point_valid(self):

    def test_point_equal(self):
        """ check if point is equal to given point (__eq__) """
Esempio n. 29
0
 def test_point_mirror(self):
     """ check if point correctly mirrored about axis (mirror) """
     self.assertTrue(p1.mirror(c.X) == Point(1.0, -2.0, 3.0))
Esempio n. 30
0
def test_add():
    p1 = Point(2, 5)
    p2 = Point(6, 7)
    actual = p1 + p2
    n.assert_equal(8, actual.x, get_message(8, actual.x))
    n.assert_equal(12, actual.y, get_message(12, actual.y))