def test_add_empty(self): vector_a = Vector(1, 2) vector_b = Vector(3, 4) test = DangerOpportunity(vector_a, vector_b) new = test.add(DangerOpportunity.empty()) self.assertEqual(test, new) self.assertIsNot(test, new)
def test_team_vectors_multiple_per_team(self): fpp = FootPrintPackage() fp_1_a = FootPrint(Token.ATTACKING, W, self.team_1) fp_1_b = FootPrint(Token.DANGER, S, self.team_1) fp_2_a = FootPrint(Token.ATTACKING, S, self.team_2) fp_2_b = FootPrint(Token.OBJECTIVE, N, self.team_2) fp_2_c = FootPrint(Token.DEAD, N, self.team_2) fpp.push(fp_1_a) fpp.push(fp_1_b) fpp.push(fp_2_a) fpp.push(fp_2_b) fpp.push(fp_2_c) answer = fpp.team_vectors() team_1_answer = answer[self.team_1] team_2_answer = answer[self.team_2] self.assertEqual(team_1_answer.danger, Vector(-1, -1)) self.assertEqual(team_1_answer.opportunity, Vector(-2, 0)) self.assertEqual(team_2_answer.danger, Vector(0, 1)) self.assertEqual(team_2_answer.opportunity, Vector(0, -1))
def test_init(self): v = Vector(2, 5) self. assertEqual(v.x, 2) self.assertEqual(v.y, 5) v = Vector(0, 0) self. assertEqual(v.x, 0) self.assertEqual(v.y, 0) v = Vector(-2, -5) self. assertEqual(v.x, -2) self.assertEqual(v.y, -5)
def test_from_dir_and_mag(self): v = Vector.from_dir_and_mag(N, 10) self.assertEqual(v.x, 0) self.assertEqual(v.y, 10) v = Vector.from_dir_and_mag(S, 10) self.assertEqual(v.x, 0) self.assertEqual(v.y, -10) v = Vector.from_dir_and_mag(E, 10) self.assertEqual(v.x, 10) self.assertEqual(v.y, 0) v = Vector.from_dir_and_mag(W, 10) self.assertEqual(v.x, -10) self.assertEqual(v.y, 0)
def test_team_vectors_one_per_team(self): fp_1 = FootPrint(Token.DANGER, W, self.team_1) for token, direction in zip(Token, cycle(Direction)): fpp = FootPrintPackage() fp_2 = FootPrint(token, direction, self.team_2) fpp.push(fp_1) fpp.push(fp_2) answer = fpp.team_vectors() self.assertEqual( answer, { self.team_1: DangerOpportunity(danger=Vector(-1, 0), opportunity=Vector(0, 0)), self.team_2: fp_2.vectorize(), })
def test_add_non_empty(self): vector_a = Vector(1, 2) vector_b = Vector(3, 5) test = DangerOpportunity(vector_a, vector_b) to_add = DangerOpportunity(Vector(1, 1), Vector(-1, -1)) expected = DangerOpportunity(Vector(2, 3), Vector(2, 4)) self.assertEqual(test.add(to_add), expected)
def test_footprint_vectorize(self): footprint = FootPrint(Token.ATTACKING, E, self.team_1) answer = footprint.vectorize() self.assertEqual(answer.danger, Vector.from_dir_and_mag(E, 1)) self.assertEqual(answer.opportunity, Vector.from_dir_and_mag(E, 2)) footprint = FootPrint(Token.ATTACKING, N, self.team_1) answer = footprint.vectorize() self.assertEqual(answer.danger, Vector.from_dir_and_mag(N, 1)) self.assertEqual(answer.opportunity, Vector.from_dir_and_mag(N, 2)) footprint = FootPrint(Token.ATTACKING, S, self.team_1) answer = footprint.vectorize() self.assertEqual(answer.danger, Vector.from_dir_and_mag(S, 1)) self.assertEqual(answer.opportunity, Vector.from_dir_and_mag(S, 2)) footprint = FootPrint(Token.ATTACKING, W, self.team_1) answer = footprint.vectorize() self.assertEqual(answer.danger, Vector.from_dir_and_mag(W, 1)) self.assertEqual(answer.opportunity, Vector.from_dir_and_mag(W, 2))
def test_ne_false(self): self.assertFalse(Vector(1, 2).__ne__(Vector(1, 2)))
def test_eq_false(self): self.assertFalse(Vector(2, 2).__eq__(Vector(1, 2))) self.assertFalse(Vector(1, 1).__eq__(Vector(1, 2)))
def test_eq_true(self): self.assertTrue(Vector(1, 2).__eq__(Vector(1, 2)))
def test_direction_tuple_negative(self): v = Vector(-2, -3) self.assertEqual(v.direction_tuple(), ((W, 2), (S, 3)))
def test_direction_tuple_zero(self): v = Vector(0, 0) self.assertEqual(v.direction_tuple(), ((E, 0), (N, 0)))
def test_dangeroppurtunity_eq_true(self): vector_a = Vector(1, 2) vector_b = Vector(3, 4) self.assertEqual(DangerOpportunity(vector_a, vector_b), DangerOpportunity(vector_a, vector_b))
def test_dangeroppurtunity_init(self): vector_a = Vector(1, 2) vector_b = Vector(3, 4) test = DangerOpportunity(vector_a, vector_b) self.assertEqual(test.danger, vector_a) self.assertEqual(test.opportunity, vector_b)
def test_ne_true(self): self.assertTrue(Vector(2, 2).__ne__(Vector(1, 2))) self.assertTrue(Vector(1, 1).__ne__(Vector(1, 2)))
def test_dangeroppurtunity_eq_false_by_order(self): vector_a = Vector(1, 2) vector_b = Vector(3, 4) self.assertNotEqual(DangerOpportunity(vector_a, vector_b), DangerOpportunity(vector_b, vector_a))
def test_dangeroppurtunity_eq_false_by_number(self): vector_a = Vector(1, 2) vector_b = Vector(3, 4) vector_c = Vector(-1, 0) self.assertNotEqual(DangerOpportunity(vector_a, vector_b), DangerOpportunity(vector_a, vector_c))
def test_repr(self): self.assertEqual(repr(Vector(1, -1)), 'Vector(1, -1)')
def test_from_dir_and_mag_composite_direction(self): v = Vector.from_dir_and_mag(CompositeDirection(N, E), 5) expected_x_y = 5 / sqrt(2) self.assertAlmostEqual(v.x, expected_x_y, places=7) self.assertAlmostEqual(v.y, expected_x_y, places=7)
def test_dangeroppurtunity_empty(self): test = DangerOpportunity.empty() self.assertEqual(test.danger, Vector(0, 0)) self.assertEqual(test.opportunity, Vector(0, 0))
def test_add(self): v1 = Vector(3, 6) v2 = Vector(-1, 2) v3 = v1.add(v2) self.assertEqual(v3.x, 2) self.assertEqual(v3.y, 8)
def vectorize(self) -> DangerOpportunity: danger = Vector.from_dir_and_mag(self.direction, self.token.danger) opportunity = Vector.from_dir_and_mag(self.direction, self.token.opportunity) return DangerOpportunity(danger=danger, opportunity=opportunity)
def test_direction_tuple_positive(self): v = Vector(2, 3) self.assertEqual(v.direction_tuple(), ((E, 2), (N, 3)))