Exemple #1
0
def test_strongly_connected_components_is_deterministic(
        graph: DirectedGraph) -> None:
    assert iequal(
        graph.strongly_connected_components(),
        graph.strongly_connected_components(),
        strict=True,
    )
Exemple #2
0
def test_topological_sort_is_deterministic(graph: DirectedGraph,
                                           reverse: bool) -> None:
    assert iequal(
        graph.topological_sort(reverse=reverse),
        graph.topological_sort(reverse=reverse),
        strict=True,
    )
Exemple #3
0
def test_chenyu_is_deterministic_hashables(points: list[Hashable],
                                           k: int) -> None:
    distance = lambda x, y: abs(hash(x) - hash(y))

    clusters1 = chenyu(points, distance, k)
    clusters2 = chenyu(points, distance, k)

    assert iequal(clusters1, clusters2, strict=True)
Exemple #4
0
def test_chenyu_is_deterministic_plane_points(points: list[tuple[int, int]],
                                              k: int) -> None:
    distance = lambda x, y: (x[0] - y[0])**2 + (x[1] - y[1])**2

    clusters1 = chenyu(points, distance, k)
    clusters2 = chenyu(points, distance, k)

    assert iequal(clusters1, clusters2, strict=True)
Exemple #5
0
def test_dfs_is_deterministic(graph: DirectedGraph) -> None:
    for node in graph.nodes():
        assert iequal(graph.dfs(node), graph.dfs(node), strict=True)
Exemple #6
0
def test_iequal_unequal(iterables: list[Iterable[int]]) -> None:
    ls = set((*iterable,) for iterable in iterables)
    assume(len(ls) > 1)
    new_iterables = map(iter, ls)
    assert not iequal(*new_iterables, strict=True)
Exemple #7
0
def test_iequal_equal(iterable: Iterable[int], length: int) -> None:
    iterables = tee(iterable, length)
    assert iequal(*iterables, strict=True)
def test_minimum_spanning_tree_deterministic(graph: WeightedGraph) -> None:
    assert iequal(graph.minimum_spanning_tree(),
                  graph.minimum_spanning_tree(),
                  strict=True)