def tearDown(self):
     self.assertTrue(self.vectorQ1 == standardcalc.Vector2D(3, 4))
     self.assertTrue(self.vectorQ2 == standardcalc.Vector2D(-3, 4))
     self.assertTrue(self.vectorQ3 == standardcalc.Vector2D(-1, -1))
     self.assertTrue(self.vectorQ4 == standardcalc.Vector2D(6, -8))
     self.assertTrue(self.vectorQ1 == [3, 4])
     self.assertTrue(self.vectorQ2 == [-3, 4])
     self.assertTrue(self.vectorQ3 == [-1, -1])
     self.assertTrue(self.vectorQ4 == [6, -8])
 def setUp(self):
     # Vectors in each quadrant
     # Q1 is top right: x>0, y>0, and goes counter clockwise
     self.vectorQ1 = standardcalc.Vector2D(3, 4)
     self.vectorQ2 = standardcalc.Vector2D(-3, 4)
     self.vectorQ3 = standardcalc.Vector2D(-1, -1)
     self.vectorQ4 = standardcalc.Vector2D(6, -8)
     self.vectors = [
         self.vectorQ1, self.vectorQ2, self.vectorQ3, self.vectorQ4
     ]
    def testScalarMultiplication(self):
        actual = self.vectorQ1 * 2
        expected = standardcalc.Vector2D(6, 8)
        self.assertEqual(actual, expected)

        actual = 2 * self.vectorQ1
        self.assertEqual(actual, expected)
    def testAngles(self):
        north = standardcalc.Vector2D(0, 1)
        south = standardcalc.Vector2D(0, -1)
        west = standardcalc.Vector2D(-1, 0)
        east = standardcalc.Vector2D(1, 0)
        northeast = standardcalc.Vector2D(1, 1)
        northwest = standardcalc.Vector2D(-1, 1)
        southeast = standardcalc.Vector2D(1, -1)
        southwest = standardcalc.Vector2D(-1, -1)

        specialTriangle = standardcalc.Vector2D.create_from_angle(30, 2)

        self.assertEqual(north.angle(), 0)
        self.assertEqual(south.angle(), 180)
        self.assertEqual(west.angle(), -90)
        self.assertEqual(east.angle(), 90)

        self.assertEqual(northeast.angle(), 45)
        self.assertEqual(northwest.angle(), -45)
        self.assertEqual(southeast.angle(), 135)
        self.assertEqual(southwest.angle(), -135)

        self.assertAlmostEqual(specialTriangle.angle(), 30, delta=0.1)
    def testAngleBetween(self):
        north = standardcalc.Vector2D(0, 1)
        south = standardcalc.Vector2D(0, -1)
        west = standardcalc.Vector2D(-1, 0)
        east = standardcalc.Vector2D(1, 0)
        northeast = standardcalc.Vector2D(1, 1)
        northwest = standardcalc.Vector2D(-1, 1)
        southeast = standardcalc.Vector2D(1, -1)
        southwest = standardcalc.Vector2D(-1, -1)

        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(north, south), 180)
        self.assertAlmostEqual(standardcalc.Vector2D.angle_between(east, west),
                               180)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(north, east), 90)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(north, west), -90)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southeast, south), 45)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southeast, northeast), -90)
        self.assertAlmostEqual(standardcalc.Vector2D.angle_between(
            southeast, northwest),
                               180,
                               places=5)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southeast, west), 135)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southwest, north), 135)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southwest, southeast), -90)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southwest, west), 45)
        self.assertAlmostEqual(
            standardcalc.Vector2D.angle_between(southwest, southwest), 0, 5)
 def testScalarDivision(self):
     actual = self.vectorQ1 / 2
     expected = standardcalc.Vector2D(1.5, 2)
     self.assertEqual(actual, expected)
 def testSubtractionToSelf(self):
     actual = standardcalc.Vector2D.zero()
     actual -= self.vectorQ1
     expected = standardcalc.Vector2D(-3, -4)
     self.assertEqual(actual, expected)
 def testSubtraction(self):
     actual = self.vectorQ1 - self.vectorQ2
     expected = standardcalc.Vector2D(6, 0)
     self.assertEqual(actual, expected)
 def testAdditionToSelf(self):
     actual = standardcalc.Vector2D.zero()
     actual += self.vectorQ1
     expected = standardcalc.Vector2D(3, 4)
     self.assertEqual(actual, expected)
 def testAddition(self):
     actual = self.vectorQ1 + self.vectorQ2
     expected = standardcalc.Vector2D(0, 8)
     self.assertEqual(actual, expected)