
import unittest
from Util import Path, Position

__author__ = 'Simon Bouchard'


A_START = Position(100, 200)
A_TARGET = Position(123, -456)
A_PATH = Path(start=A_START, target=A_TARGET)

A_START_ARRAY = A_START.array
A_TARGET_ARRAY = A_TARGET.array

A_LIST_OF_POSITION = [Position(0, 0),
                      Position(0, 10),
                      Position(10, 10),
                      Position(10, 20),
                      Position(20, 20),
                      Position(20, 30)]

A_LONG_PATH = Path.from_points(A_LIST_OF_POSITION)
PATH_LENGTH = 50

A_LIST_OF_CLOSE_POSITION =  [Position(1,1), Position(1,-1),
                             Position(10,1), Position(10,1), Position(10,2),
                             Position(10, 21), Position(10, 20), Position(10, 22)]

A_PATH_WITH_CLOSE_POINTS = Path.from_points(A_LIST_OF_CLOSE_POSITION)


class TestPosition(unittest.TestCase):

    def test_givenStartTarget_whenNew_thenReturnPath(self):
        path = Path(start=A_START, target=A_TARGET)
        self.assertEqual(path.start, A_START)
        self.assertEqual(path.target, A_TARGET)

    def test_givenStartTargetArray_whenFromArray_thenReturnPath(self):
        path = Path.from_array(A_START_ARRAY, A_TARGET_ARRAY)
        self.assertEqual(path.start, A_START)
        self.assertEqual(path.target, A_TARGET)

    def test_givenListOfPosition_whenFromPoints_thenReturnPath(self):
        path = Path.from_points(A_LIST_OF_POSITION)
        self.assertEqual(path.points, A_LIST_OF_POSITION)

    def test_givenPath_whenFilter_thenRemoveClosePointsAndKeepTarget(self):
        path = A_PATH_WITH_CLOSE_POINTS.copy()
        path.filter(threshold=5)
        self.assertEqual(path.points, [Position(1,-1), Position(10,2), Position(10, 22)])

    def test_givenPath_whenCopy_thenReturnPathCopy(self):
        path = A_PATH.copy()
        self.assertIsNot(path, A_PATH)

    def test_givenPath_whenGettingLength_thenReturnLength(self):
        length = A_LONG_PATH.length
        self.assertEqual(length, PATH_LENGTH)

@@ -1051,33 +1051,23 @@
         
-self.
 assert
-Equal(
+ 
 path.tar
@@ -1061,33 +1061,35 @@
 sert path.target
-,
+ ==
  A_TARGET)%0A%0A    
@@ -1073,33 +1073,32 @@
 rget == A_TARGET
-)
 %0A%0A    def test_g
@@ -1270,33 +1270,23 @@
         
-self.
 assert
-Equal(
+ 
 path.tar
@@ -1288,17 +1288,19 @@
 h.target
-,
+ ==
  A_TARGE
@@ -1300,17 +1300,16 @@
 A_TARGET
-)
 %0A%0A    de
@@ -1319,57 +1319,69 @@
 est_
-givenListOfPosition_whenFromPoints_thenReturnPath
+whenInitializingFromAListOfPoints_thenAListOfPointsIsAssigned
 (sel
@@ -1444,33 +1444,23 @@
         
-self.
 assert
-Equal(
+ 
 path.poi
@@ -1462,17 +1462,19 @@
 h.points
-,
+ ==
  A_LIST_
@@ -1484,17 +1484,16 @@
 POSITION
-)
 %0A%0A    de
@@ -1650,33 +1650,23 @@
         
-self.
 assert
-Equal(
+ 
 path.poi
@@ -1668,17 +1668,19 @@
 h.points
-,
+ ==
  %5BPositi
@@ -1722,17 +1722,16 @@
 10, 22)%5D
-)
 %0A%0A    de
@@ -1823,38 +1823,33 @@
     
-self.
 assert
-IsNot(path,
+ path is not
  A_PATH
-)
 %0A%0A  
@@ -1959,32 +1959,24 @@
     
-self.
 assert
-Equal(
+ 
 length
-,
+ ==
  PAT
@@ -1983,10 +1983,9 @@
 H_LENGTH
-)
 %0A

fix review