def test_player_managerCollisionEvents(self): old_life = self.game.perso.life destination = self.game.tilemap.layers['pnjs'].find('monstre')[0] (dx, dy) = self.__calcule_delta(self.game.perso, destination) self.game.perso.move(dx, dy) self.game.player_stackEvents(self.game.perso, self.game.monster_layer, self.game.playerEvents) self.game.player_manageCollisionEvents(self.game.perso, self.game.playerEvents) TestCase.assertLess(self, self.game.perso.life, old_life)
def doframe(t: unittest.TestCase, curr: sllib.Frame, prev: sllib.Frame): """Validate some basic data for the frame""" t.assertGreaterEqual(curr.course, 0) t.assertLessEqual(curr.course, 6.28) t.assertLess(curr.gps_speed, 15) t.assertLess(curr.altitude, 500) t.assertLess(curr.temperature, 22) t.assertGreater(curr.temperature, 10) t.assertGreater(curr.framesize, curr.packetsize) t.assertGreater(curr.framesize, 1900) t.assertLessEqual(len(curr.packet), curr.packetsize) if prev is not None: t.assertGreater(curr.offset, prev.offset) t.assertGreaterEqual(curr.time1, prev.time1)
def run_single_assertions(cls, test: unittest.TestCase, retriever: Retriever): data = retriever.retrieve() expected_locations = ("0214655255", "0214657975") unique_loaded_locations = data.observation_location.unique() for location in expected_locations: test.assertIn(location, unique_loaded_locations) earliest_possible_date = datetime(year=2015, month=12, day=1, tzinfo=timezone.utc) latest_possible_date = datetime(year=2016, month=1, day=2, tzinfo=timezone.utc) earliest_date = data.value_date.min() latest_date = data.value_date.max() test.assertGreater(earliest_date, earliest_possible_date) test.assertLess(latest_date, latest_possible_date) for location_name, subset in data.groupby(by="observation_location"): test.assertGreater(subset.value_date.min(), earliest_possible_date) test.assertLess(subset.value_date.max(), latest_possible_date) current_date = earliest_date.date() present_days = subset.value_date.apply(lambda d: d.date()).unique() missing_days = list() while current_date <= latest_date: if current_date not in present_days: missing_days.append(current_date) else: missing_days.clear() test.assertLess(len(missing_days), 5) current_date += timedelta(days=1)
def run_acceptance_test(test_case: unittest.TestCase, model_id: str, props_to_test: list = None) -> bool: """ Runs the acceptance test for the given model id. :param test_case: The unittest case. :param model_id: The model ID to run the test for. :return: True if successful, false or exception if not. """ npy_test_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "test_" + model_id + ".npy") ucvm_model_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "ucvm_model.xml") spacing = 0.05 depth = 5000 bottom_corner = {"e": 0, "n": 0} if not os.path.exists(npy_test_file) or not os.path.exists( ucvm_model_file): return False with open(ucvm_model_file, "r") as fd: ucvm_model = xmltodict.parse(fd.read()) bottom_corner["e"] = \ float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["e"]) bottom_corner["n"] = \ float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["n"]) model_type = ucvm_model["root"]["information"]["type"] arr = np.load(npy_test_file) nums = {"x": len(arr), "y": len(arr[0]), "z": len(arr[0][0])} sd_array = [ SeismicData() for _ in range(nums["x"] * nums["y"] * nums["z"]) ] counter = 0 for z in range(nums["z"]): for y in range(nums["y"]): for x in range(nums["x"]): sd_array[counter].original_point = Point( bottom_corner["e"] + spacing * x, bottom_corner["n"] + spacing * y, 0 + depth * z) counter += 1 UCVM.query(sd_array, model_id, [model_type]) if props_to_test is None or len(props_to_test) == 0: props_to_test = ["vp", "vs", "density"] counter = 0 epsilon = 0.006 for z in range(nums["z"]): for y in range(nums["y"]): for x in range(nums["x"]): if arr[x][y][z][0] <= 0 and sd_array[counter].velocity_properties.vp is None or \ arr[x][y][z][1] <= 0 and sd_array[counter].velocity_properties.vs is None or \ arr[x][y][z][2] <= 0 and sd_array[counter].velocity_properties.density is None: counter += 1 continue # This is to account for a floating point rounding issue in the CVM-S4.26 test which has the new UCVM # thinking that the corner is in bounds and the old version thinking it's out of bounds. This version # thinks the point is 1534.999999999 where as the old version thinks it's exactly 1535. This also fixes # a difference whereby the old CVM-S5 extended below 50000km but the new one does not. if (sd_array[counter].original_point.x_value == -116 and sd_array[counter].original_point.y_value == 30.45 and model_id == "cvms426") or \ (sd_array[counter].original_point.z_value == 50000 and model_id == "cvms426"): counter += 1 continue if "vp" in props_to_test: test_case.assertGreater( sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 - epsilon) test_case.assertLess( sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 + epsilon) if "vs" in props_to_test: test_case.assertGreater( sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 - epsilon) test_case.assertLess( sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 + epsilon) if "density" in props_to_test: test_case.assertGreater( sd_array[counter].velocity_properties.density / arr[x][y][z][2], 1 - epsilon) test_case.assertLess( sd_array[counter].velocity_properties.density / arr[x][y][z][2], 1 + epsilon) counter += 1 return True
def run_acceptance_test(test_case: unittest.TestCase, model_id: str, props_to_test: list=None) -> bool: """ Runs the acceptance test for the given model id. :param test_case: The unittest case. :param model_id: The model ID to run the test for. :return: True if successful, false or exception if not. """ npy_test_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "test_" + model_id + ".npy") ucvm_model_file = os.path.join(UCVM_MODELS_DIRECTORY, model_id, "ucvm_model.xml") spacing = 0.05 depth = 5000 bottom_corner = { "e": 0, "n": 0 } if not os.path.exists(npy_test_file) or not os.path.exists(ucvm_model_file): return False with open(ucvm_model_file, "r") as fd: ucvm_model = xmltodict.parse(fd.read()) bottom_corner["e"] = \ float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["e"]) bottom_corner["n"] = \ float(ucvm_model["root"]["information"]["coverage"]["bottom-left"]["n"]) model_type = ucvm_model["root"]["information"]["type"] arr = np.load(npy_test_file) nums = { "x": len(arr), "y": len(arr[0]), "z": len(arr[0][0]) } sd_array = [SeismicData() for _ in range(nums["x"] * nums["y"] * nums["z"])] counter = 0 for z in range(nums["z"]): for y in range(nums["y"]): for x in range(nums["x"]): sd_array[counter].original_point = Point(bottom_corner["e"] + spacing * x, bottom_corner["n"] + spacing * y, 0 + depth * z) counter += 1 UCVM.query(sd_array, model_id, [model_type]) if props_to_test is None or len(props_to_test) == 0: props_to_test = ["vp", "vs", "density"] counter = 0 epsilon = 0.006 for z in range(nums["z"]): for y in range(nums["y"]): for x in range(nums["x"]): if arr[x][y][z][0] <= 0 and sd_array[counter].velocity_properties.vp is None or \ arr[x][y][z][1] <= 0 and sd_array[counter].velocity_properties.vs is None or \ arr[x][y][z][2] <= 0 and sd_array[counter].velocity_properties.density is None: counter += 1 continue # This is to account for a floating point rounding issue in the CVM-S4.26 test which has the new UCVM # thinking that the corner is in bounds and the old version thinking it's out of bounds. This version # thinks the point is 1534.999999999 where as the old version thinks it's exactly 1535. This also fixes # a difference whereby the old CVM-S5 extended below 50000km but the new one does not. if (sd_array[counter].original_point.x_value == -116 and sd_array[counter].original_point.y_value == 30.45 and model_id == "cvms426") or \ (sd_array[counter].original_point.z_value == 50000 and model_id == "cvms426"): counter += 1 continue if "vp" in props_to_test: test_case.assertGreater(sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 - epsilon) test_case.assertLess(sd_array[counter].velocity_properties.vp / arr[x][y][z][0], 1 + epsilon) if "vs" in props_to_test: test_case.assertGreater(sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 - epsilon) test_case.assertLess(sd_array[counter].velocity_properties.vs / arr[x][y][z][1], 1 + epsilon) if "density" in props_to_test: test_case.assertGreater(sd_array[counter].velocity_properties.density / arr[x][y][z][2], 1 - epsilon) test_case.assertLess(sd_array[counter].velocity_properties.density / arr[x][y][z][2], 1 + epsilon) counter += 1 return True
# In[27]: # (4 points) Stress testing from unittest import TestCase from time import time import random tc = TestCase() ht = OrderedHashtable(100000) d = {} start = time() for _ in range(100000): k, v = str(random.randrange(100000)), str( random.randrange(10000000, 99999999)) d[k] = v ht[k] = v for k, v in d.items(): tc.assertTrue(k in ht) tc.assertEqual(d[k], ht[k]) end = time() print(end - start) tc.assertLess(end - start, 1.5, 'Your implementation ran too slow!') # In[ ]: