def test_030_large_all_common_comps_exact(self): n_stolen, n_sighted, n_matches, expected = 1000, 20000, 1000, 19077500 self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def test_080_small3_all_common_comps_exact(self): n_stolen, n_sighted, n_matches, expected = 10, 1000, 10, 9405 self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def test_020_medium_some_common_comps_exact(self): n_stolen, n_sighted, n_matches, expected = 100, 1000, 5, 99647 self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def __ne__(self, other): if other is None: StatCounter.increment(PRIORITY_COMPS) return False if not isinstance(other, Priority): raise ValueError(PRIORITY_COMPARISON_TYPE_ERROR) StatCounter.increment(PRIORITY_COMPS) return self._priority != other._priority
def test_010_tiny_comps_exact(self): n_stolen, n_sighted, n_matches, expected = 2, 5, 2, 9 self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def test_070_small2_all_common_comps_exact(self): n_stolen, n_sighted, n_matches = 100, 100, 100 expected = n_stolen * (n_stolen + 1) // 2 self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def test_040_small_all_common_comps_exact(self): n_stolen, n_sighted, n_matches = 10, 10, 10 expected = n_stolen * (n_stolen + 1) // 2 # can you see why expected must be given by the formula above in this case? self.comparisons_test(n_stolen, n_sighted, n_matches, expected) StatCounter.reset_comparisons() self.internal_comparisons_test(n_stolen, n_sighted, n_matches, quiet=True)
def setUp(self): """Runs before every test case""" StatCounter.reset_counts() # sub classes can change the following default settings self.use_fast_heapify = False # the default setting # set max number of childre that will be tested self.max_num_children = DEFAULT_MAX_NUM_CHILDREN_TO_TEST # Most tests will change num_children before running # set to 2 as a simple default self.num_children = 2
def setUp(self): """Runs before every test case""" StatCounter.reset_comparisons()
def __ge__(self, other): if not isinstance(other, NumberPlate): raise ValueError(COMPARISON_TYPE_ERROR) StatCounter.increment() return self._plate >= other._plate
def __hash__(self): """ hash(my_number_plate) will use this method, ie, it will return the hash value for my_number_plate. """ StatCounter.increment(HASHES) return _fnv32a_hash(self._plate)
def __eq__(self, other): if not isinstance(other, NumberPlate): print(type(other)) raise TypeError(COMPARISON_TYPE_ERROR) StatCounter.increment(COMPS) return self._plate == other._plate
def __lt__(self, other): if not isinstance(other, NumberPlate): raise ValueError(PLATE_COMPARISON_TYPE_ERROR) StatCounter.increment(PLATE_COMPS) return self._plate < other._plate
def __gt__(self, other): if not isinstance(other, Priority): raise ValueError(PRIORITY_COMPARISON_TYPE_ERROR) StatCounter.increment(PRIORITY_COMPS) return self._priority > other._priority
def setUp(self): """This runs before each test case""" StatCounter.reset_counts()
def real_comparisons(counter): """ calling real_comparisons will be equivalent to calling StatCounter.get_count """ return StatCounter.get_count(counter)