def test1(self): moonList = [] moonA = Moon(-1, 0, 2) moonB = Moon(2, -10, -7) moonC = Moon(4, -8, 8) moonD = Moon(3, 5, -1) moonList.append(moonA) moonList.append(moonB) moonList.append(moonC) moonList.append(moonD) out = calctotEnergy(10, moonList.copy()) self.assertEqual(179, out)
def test2(self): moonList = [] moonA = Moon(-8, -10, 0) moonB = Moon(5, 5, 10) moonC = Moon(2, -7, 3) moonD = Moon(9, -8, -3) moonList.append(moonA) moonList.append(moonB) moonList.append(moonC) moonList.append(moonD) out = calctotEnergy(100, moonList.copy()) self.assertEqual(1940, out)
def test3(self): moonList = [] moonA = Moon(-15, 1, 4) moonB = Moon(1, -10, -8) moonC = Moon(-5, 4, 9) moonD = Moon(4, 6, -2) moonList.append(moonA) moonList.append(moonB) moonList.append(moonC) moonList.append(moonD) out = calctotEnergy(1000, moonList.copy()) self.assertEqual(8625, out)
def test_apply_velocity(): # x=1, y=2, z=3 and a velocity of x=-2, y=0,z=3, then its new position would be x=-1, y=2, z=6 moon = Moon("<x=1, y=2, z=3>") moon.velocity = (-2, 0, 3) expected = Moon("<x=-1, y=2, z=6>") expected.velocity = (-2, 0, 3) moon.apply_velocity() assert moon == expected
def test_get_total_energy_2nd_example(): expected = 1940 start_input = [ "<x=-8, y=-10, z=0>", "<x=5, y=5, z=10>", "<x=2, y=-7, z=3>", "<x=9, y=-8, z=-3>", ] moons = [Moon(row) for row in start_input] result = get_total_energy(moons, 100) assert result == expected
def test_init_handles_string_input(): line = "<x=15, y=-2, z=-6>" expected_x = 15 expected_y = -2 expected_z = -6 result = Moon(line) assert result.x == expected_x assert result.y == expected_y assert result.z == expected_z
def test_get_total_energy(): expected = 179 start_input = [ "<x=-1, y=0, z=2>", "<x=2, y=-10, z=-7>", "<x=4, y=-8, z=8>", "<x=3, y=5, z=-1>", ] moons = [Moon(row) for row in start_input] result = get_total_energy(moons, 10) assert result == expected
def test_get_steps_to_find_same_state(): expected = 4686774924 start_input = [ "<x=-8, y=-10, z=0>", "<x=5, y=5, z=10>", "<x=2, y=-7, z=3>", "<x=9, y=-8, z=-3>", ] moons = [Moon(row) for row in start_input] result = get_steps_to_find_same_state(moons) assert result == expected
def setUp(self): self.moons1 = [ Moon([-1, 0, 2]), Moon([2, -10, -7]), Moon([4, -8, 8]), Moon([3, 5, -1]) ] self.result1 = [ Moon([2, -1, 1]), Moon([3, -7, -4]), Moon([1, -7, 5]), Moon([2, 2, 0]) ] self.result2 = [ Moon([5, -3, -1]), Moon([1, -2, 2]), Moon([1, -4, -1]), Moon([1, -4, 2]) ] self.result3 = [ Moon([-1, -9, 2]), Moon([4, 1, 5]), Moon([2, 2, -4]), Moon([3, -7, -1]) ] self.result4 = [ Moon([2, 1, -3]), Moon([1, -8, 0]), Moon([3, -6, 1]), Moon([2, 0, 4]) ] self.moons2 = separateAxis([ Moon([-1, 0, 2]), Moon([2, -10, -7]), Moon([4, -8, 8]), Moon([3, 5, -1]) ])