chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import easygraph as eg
|
||||
import pytest
|
||||
|
||||
from easygraph.utils.exception import EasyGraphError
|
||||
|
||||
|
||||
class TestClassic:
|
||||
def test_complete_hypergraph(self):
|
||||
print(eg.complete_hypergraph(10))
|
||||
assert eg.complete_hypergraph(10) is not None
|
||||
|
||||
def test_random_hypergraph(self):
|
||||
import random
|
||||
|
||||
import numpy as np
|
||||
|
||||
n = 100
|
||||
k1 = {i: random.randint(1, 100) for i in range(n)}
|
||||
k2 = {i: sorted(k1.values())[i] for i in range(n)}
|
||||
H = eg.chung_lu_hypergraph(k1, k2)
|
||||
H2 = eg.watts_strogatz_hypergraph(n=n, d=10, k=16, p=0.5, l=3)
|
||||
k1 = {i: random.randint(1, n) for i in range(n)}
|
||||
k2 = {i: sorted(k1.values())[i] for i in range(n)}
|
||||
g1 = {i: random.choice([0, 1]) for i in range(n)}
|
||||
g2 = {i: random.choice([0, 1]) for i in range(n)}
|
||||
omega = np.array([[n // 2, 10], [10, n // 2]])
|
||||
H3 = eg.dcsbm_hypergraph(k1, k2, g1, g2, omega)
|
||||
|
||||
assert H != None
|
||||
assert H2 != None
|
||||
assert H3 != None
|
||||
|
||||
def test_simple_hypergraph(self):
|
||||
H = eg.star_clique(6, 7, 2)
|
||||
print(H)
|
||||
|
||||
def test_uniform_hypergraph(self):
|
||||
n = 1000
|
||||
m = 3
|
||||
k = {0: 1, 1: 2, 2: 3, 3: 3}
|
||||
H = eg.uniform_hypergraph_configuration_model(k, m)
|
||||
print(H)
|
||||
|
||||
H2 = eg.uniform_erdos_renyi_hypergraph(10, 5, 0.5, "prob")
|
||||
# H2 = eg.uniform_HSBM(n,5,[3,4,5],[0.5,0.5,0.5])
|
||||
print("H2:", H2)
|
||||
|
||||
H3 = eg.uniform_HPPM(10, 6, 0.9, 10, 0.9)
|
||||
|
||||
print("H3:", H3)
|
||||
|
||||
|
||||
class TestHypergraphGenerators:
|
||||
def test_empty_hypergraph_default(self):
|
||||
hg = eg.empty_hypergraph()
|
||||
assert hg.num_v == 1
|
||||
assert len(hg.e[0]) == 0
|
||||
|
||||
def test_empty_hypergraph_custom_size(self):
|
||||
hg = eg.empty_hypergraph(5)
|
||||
assert hg.num_v == 5
|
||||
assert len(hg.e[0]) == 0
|
||||
|
||||
def test_complete_hypergraph_zero_nodes_raises(self):
|
||||
with pytest.raises(EasyGraphError):
|
||||
eg.complete_hypergraph(0)
|
||||
|
||||
def test_complete_hypergraph_n_1_excludes_singletons(self):
|
||||
hg = eg.complete_hypergraph(1, include_singleton=False)
|
||||
assert hg.num_v == 1
|
||||
assert len(hg.e[0]) == 0
|
||||
|
||||
def test_complete_hypergraph_n_3_excludes_singletons(self):
|
||||
hg = eg.complete_hypergraph(3, include_singleton=False)
|
||||
expected_edges = [[0, 1], [0, 2], [1, 2], [0, 1, 2]]
|
||||
assert sorted(sorted(e) for e in hg.e[0]) == sorted(
|
||||
sorted(e) for e in expected_edges
|
||||
)
|
||||
|
||||
def test_complete_hypergraph_n_3_includes_singletons(self):
|
||||
hg = eg.complete_hypergraph(3, include_singleton=True)
|
||||
expected_edges = [[0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2]]
|
||||
assert sorted(sorted(e) for e in hg.e[0]) == sorted(
|
||||
sorted(e) for e in expected_edges
|
||||
)
|
||||
@@ -0,0 +1,49 @@
|
||||
import easygraph as eg
|
||||
import pytest
|
||||
|
||||
from easygraph.utils.exception import EasyGraphError
|
||||
|
||||
|
||||
class TestRingLatticeHypergraph:
|
||||
def test_valid_ring_lattice(self):
|
||||
H = eg.ring_lattice(n=10, d=3, k=4, l=1)
|
||||
assert isinstance(H, eg.Hypergraph)
|
||||
assert H.num_v == 10
|
||||
assert all(len(edge) == 3 for edge in H.e[0])
|
||||
|
||||
def test_k_less_than_zero_raises_error(self):
|
||||
with pytest.raises(EasyGraphError, match="Invalid k value!"):
|
||||
eg.ring_lattice(n=10, d=3, k=-2, l=1)
|
||||
|
||||
def test_k_less_than_two_warns(self):
|
||||
with pytest.warns(UserWarning, match="disconnected"):
|
||||
H = eg.ring_lattice(n=10, d=3, k=1, l=1)
|
||||
assert isinstance(H, eg.Hypergraph)
|
||||
|
||||
def test_k_odd_warns(self):
|
||||
with pytest.warns(UserWarning, match="divisible by 2"):
|
||||
H = eg.ring_lattice(n=10, d=3, k=3, l=1)
|
||||
assert isinstance(H, eg.Hypergraph)
|
||||
|
||||
def test_ring_lattice_with_d_eq_1(self):
|
||||
H = eg.ring_lattice(n=5, d=1, k=2, l=0)
|
||||
assert all(len(edge) == 1 for edge in H.e[0])
|
||||
|
||||
def test_ring_lattice_with_overlap_zero(self):
|
||||
H = eg.ring_lattice(n=6, d=2, k=2, l=0)
|
||||
assert all(len(edge) == 2 for edge in H.e[0])
|
||||
|
||||
def test_large_n(self):
|
||||
H = eg.ring_lattice(n=100, d=4, k=6, l=2)
|
||||
assert H.num_v == 100
|
||||
assert all(len(e) == 4 for e in H.e[0])
|
||||
|
||||
def test_n_equals_1(self):
|
||||
H = eg.ring_lattice(n=1, d=1, k=2, l=0)
|
||||
assert H.num_v == 1
|
||||
assert isinstance(H, eg.Hypergraph)
|
||||
|
||||
def test_k_zero(self):
|
||||
H = eg.ring_lattice(n=5, d=2, k=0, l=1)
|
||||
assert H.num_v == 5
|
||||
assert len(H.e[0]) == 0
|
||||
@@ -0,0 +1,60 @@
|
||||
from itertools import combinations
|
||||
|
||||
import easygraph as eg
|
||||
import pytest
|
||||
|
||||
|
||||
class TestStarCliqueHypergraph:
|
||||
def test_valid_star_clique(self):
|
||||
H = eg.star_clique(n_star=5, n_clique=4, d_max=2)
|
||||
assert isinstance(H, eg.Hypergraph)
|
||||
assert H.num_v == 9 # 5 star nodes + 4 clique nodes
|
||||
assert any(0 in edge for edge in H.e[0]) # star center connected
|
||||
|
||||
def test_minimum_valid_values(self):
|
||||
H = eg.star_clique(n_star=2, n_clique=2, d_max=1)
|
||||
assert H.num_v == 4
|
||||
assert len(H.e[0]) >= 2
|
||||
|
||||
def test_n_star_zero_raises(self):
|
||||
with pytest.raises(ValueError, match="n_star must be an integer > 0."):
|
||||
eg.star_clique(0, 3, 1)
|
||||
|
||||
def test_n_clique_zero_raises(self):
|
||||
with pytest.raises(ValueError, match="n_clique must be an integer > 0."):
|
||||
eg.star_clique(3, 0, 1)
|
||||
|
||||
def test_d_max_negative_raises(self):
|
||||
with pytest.raises(ValueError, match="d_max must be an integer >= 0."):
|
||||
eg.star_clique(3, 4, -1)
|
||||
|
||||
def test_d_max_too_large_raises(self):
|
||||
with pytest.raises(ValueError, match="d_max must be <= n_clique - 1."):
|
||||
eg.star_clique(3, 4, 5)
|
||||
|
||||
def test_no_clique_edges_if_d_max_zero(self):
|
||||
H = eg.star_clique(3, 3, 0)
|
||||
clique_nodes = set(range(3, 6))
|
||||
for edge in H.e[0]:
|
||||
assert not clique_nodes.issubset(edge)
|
||||
|
||||
def test_clique_hyperedges_match_combinations(self):
|
||||
n_star, n_clique, d_max = 3, 4, 2
|
||||
H = eg.star_clique(n_star, n_clique, d_max)
|
||||
clique_nodes = list(range(n_star, n_star + n_clique))
|
||||
expected = {
|
||||
tuple(sorted(e))
|
||||
for d in range(1, d_max + 1)
|
||||
for e in combinations(clique_nodes, d + 1)
|
||||
}
|
||||
actual = {
|
||||
tuple(sorted(e)) for e in H.e[0] if all(node in clique_nodes for node in e)
|
||||
}
|
||||
assert expected.issubset(actual)
|
||||
|
||||
def test_star_legs_connect_to_center(self):
|
||||
H = eg.star_clique(5, 4, 1)
|
||||
star_nodes = list(range(5))
|
||||
center = star_nodes[0]
|
||||
for i in range(1, 4): # last star leg is used to connect to clique
|
||||
assert any({center, i}.issubset(edge) for edge in H.e[0])
|
||||
Reference in New Issue
Block a user