import unittest
from utils_coordinates import *

class TestCoordinates(unittest.TestCase):

    x = 5
    y = 13
    z = 19
        
    def test_constuctor(self):
        c = Coordinates(self.x,self.y,self.z)
        self.assertEqual(c.x,self.x)
        self.assertEqual(c.y,self.y)
        self.assertEqual(c.z,self.z)

    def test_from_tuple(self):
        c = Coordinates.from_tuple((self.x,self.y,self.z))
        self.assertEqual(c.x,self.x)
        self.assertEqual(c.y,self.y)
        self.assertEqual(c.z,self.z)

    def test_addition_with_int(self):
        c = Coordinates(self.x,self.y,self.z)
        c += 3
        self.assertEqual(c.x,self.x+3)
        self.assertEqual(c.y,self.y+3)
        self.assertEqual(c.z,self.z+3)
        
    def test_subtraction_with_int(self):
        c = Coordinates(self.x,self.y,self.z)
        c -= 3
        self.assertEqual(c.x,self.x-3)
        self.assertEqual(c.y,self.y-3)
        self.assertEqual(c.z,self.z-3)
        
    def test_addition_with_itself(self):
        c = Coordinates(self.x,self.y,self.z)
        c += Coordinates(self.y,self.z,self.x)
        self.assertEqual(c.x,self.x+self.y)
        self.assertEqual(c.y,self.y+self.z)
        self.assertEqual(c.z,self.z+self.x)
        
    def test_subtraction_with_itself(self):
        c = Coordinates(self.x,self.y,self.z)
        c -= Coordinates(self.y,self.z,self.x)
        self.assertEqual(c.x,self.x-self.y)
        self.assertEqual(c.y,self.y-self.z)
        self.assertEqual(c.z,self.z-self.x)
        
    def test_multiplication_with_int(self):
        c = Coordinates(self.x,self.y,self.z)
        c *= 2
        self.assertEqual(c.x,self.x*2)
        self.assertEqual(c.y,self.y*2)
        self.assertEqual(c.z,self.z*2)
        
    def test_division_with_int(self):
        c = Coordinates(self.x,self.y,self.z)
        c /= 2
        self.assertEqual(c.x,self.x//2)
        self.assertEqual(c.y,self.y//2)
        self.assertEqual(c.z,self.z//2)
        
    def test_move_positive(self):
        c = Coordinates(self.x,self.y,self.z)
        c = Coordinates.move_east(c)
        c = Coordinates.move_up(c)
        c = Coordinates.move_south(c)
        self.assertEqual(c.x,self.x+1)
        self.assertEqual(c.y,self.y+1)
        self.assertEqual(c.z,self.z+1)
        
    def test_move_negative(self):
        c = Coordinates(self.x,self.y,self.z)
        c = Coordinates.move_west(c)
        c = Coordinates.move_down(c)
        c = Coordinates.move_north(c)
        self.assertEqual(c.x,self.x-1)
        self.assertEqual(c.y,self.y-1)
        self.assertEqual(c.z,self.z-1)
    
    def test_l_norm_1(self):
        c = Coordinates(self.x,self.y,self.z)
        norm1 = c.l_norm(1)
        self.assertEqual(norm1, self.x+ self.y+ self.z)
    
    def test_l_norm_2(self):
        c = Coordinates(self.x,self.y,self.z)
        norm2 = c.l_norm(2)
        self.assertAlmostEqual(norm2, (self.x**2+ self.y**2+ self.z**2)**(1/2))
       
if __name__ == '__main__':
    unittest.main()
