def test_stats_2_int() -> None: s = SampleStatistics() s.put(-1) s.put(1) assert s.mean() == 0.0 assert s.variance() == 2.0 assert s.deviation() == sqrt(2.0)
def test_stats_3_int() -> None: s = SampleStatistics() s.put(89) s.put(90) s.put(91) assert s.mean() == 90.0 assert s.variance() == 1.0 assert s.deviation() == 1.0
def test_stats_2_float() -> None: s = SampleStatistics() s.put(1.0) s.put(2.0) assert s.mean() == 1.5 assert s.variance() == 0.5 assert s.deviation() == sqrt(0.5)
def test_stats_3_float_mean_small() -> None: # found by hypothesis s = SampleStatistics() s.put(-9.020465019382587e+92) s.put(-9.020465019382587e+92) s.put(-9.020465019382587e+92) assert s.sum / s.samples < s.min assert s.mean() == s.min
def test_stats_floats(samples: Sequence[float]) -> None: s = SampleStatistics() for sample in samples: s.put(sample) assert s.mean() >= s.min assert s.mean() <= s.max assert s.variance() >= 0. if s.min < s.max: assert s.deviation() <= s.max - s.min
def test_stats_3_float_deviation_small() -> None: # found by hypothesis s = SampleStatistics() s.put(1.5765166949677225e-06) s.put(1.5765166949677225e-06) s.put(1.5765166949677225e-06) assert s.max == s.min assert (s.sum_of_squares - s.sum * s.sum / 3) / 2 > 0
def test_stats_3_float_deviation_big() -> None: # found by hypothesis s = SampleStatistics() s.put(688338275.2675972) s.put(688338275.2675972) s.put(688338275.2675972) assert s.max == s.min assert (s.sum_of_squares - s.sum * s.sum / 3) / 2 > 0
def bron_kerbosch_timed(graph: Graph, clique_count: int, func_indices: List[int], samples: int) -> List[SampleStatistics]: first = None times = [SampleStatistics() for _ in range(len(FUNCS))] for sample in range(1 if samples == 1 else 0, samples + 1): for func_index in func_indices: func = FUNCS[func_index] func_name = FUNC_NAMES[func_index] if sample == 0: reporter = SimpleReporter() begin = time.perf_counter() try: func(graph, reporter) except RecursionError: print(f"{func_name} recursed out!") secs = time.perf_counter() - begin if secs >= 3.0: print(f" {func_name:<8}: {secs:6.3f}s") current = sorted(sorted(clique) for clique in reporter.cliques) if first is None: if len(current) != clique_count: print( f"{func_name}: expected {clique_count}, obtained {len(current)} cliques!" ) if graph.order < 100 and not are_maximal(current): print(f" {func_name} not maximal") first = current elif first != current: print(f"{func_name}: " + f"expected {len(first)} cliques, " + f"obtained {len(current)} different cliques!") else: counter = CountingReporter() begin = time.perf_counter() try: func(graph, counter) except RecursionError: print(f"{func_name} recursed out!") secs = time.perf_counter() - begin if counter.cliques != clique_count: print( f"{func_name}: expected {clique_count}, obtained {counter.cliques} cliques!" ) times[func_index].put(secs) return times
def test_stats_0_i32() -> None: s = SampleStatistics() assert isnan(s.mean()) assert isnan(s.variance()) assert isnan(s.deviation())
def test_stats_9_int() -> None: s = SampleStatistics() s.put(2) s.put(4) s.put(4) s.put(4) s.put(5) s.put(5) s.put(5) s.put(7) s.put(9) assert s.mean() == 5.0 assert s.variance() == 4.0 assert s.deviation() == 2.0
def test_stats_1_int() -> None: s = SampleStatistics() s.put(-1) assert s.mean() == -1.0 assert isnan(s.variance()) assert isnan(s.deviation())