chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:36:30 +08:00
commit 55ab4e4a73
473 changed files with 72932 additions and 0 deletions
@@ -0,0 +1,63 @@
import unittest
import easygraph as eg
class test_random_network(unittest.TestCase):
def setUp(self):
self.G = eg.datasets.get_graph_karateclub()
def test_erdos_renyi_M(self):
print(eg.erdos_renyi_M(8, 5).edges)
def test_erdos_renyi_P(self):
print(eg.erdos_renyi_P(8, 0.2).nodes)
def test_fast_erdos_renyi_P(self):
print(eg.fast_erdos_renyi_P(8, 0.2).nodes)
def test_WS_Random(self):
print(eg.WS_Random(8, 1, 0.5).nodes)
def test_graph_Gnm(self):
print(eg.graph_Gnm(8, 5).nodes)
def test_erdos_renyi_M_max_edges(self):
n = 5
max_edges = n * (n - 1) // 2
G = eg.erdos_renyi_M(n, max_edges)
self.assertEqual(len(G.edges), max_edges)
def test_erdos_renyi_P_extreme_p(self):
G0 = eg.erdos_renyi_P(10, 0.0)
G1 = eg.erdos_renyi_P(10, 1.0)
self.assertEqual(len(G0.edges), 0)
self.assertEqual(len(G1.edges), 45) # 10 * 9 / 2
def test_fast_erdos_renyi_P_large_p(self):
G = eg.fast_erdos_renyi_P(10, 0.9)
self.assertEqual(len(G.nodes), 10)
def test_WS_Random_structure(self):
G = eg.WS_Random(10, 2, 0.1)
self.assertEqual(len(G.nodes), 10)
self.assertTrue(all(0 <= u < 10 and 0 <= v < 10 for u, v, *_ in G.edges))
def test_WS_Random_invalid_k(self):
G = eg.WS_Random(5, 5, 0.1)
self.assertIsNone(G)
def test_graph_Gnm_basic(self):
G = eg.graph_Gnm(10, 15)
self.assertEqual(len(G.nodes), 10)
self.assertEqual(len(G.edges), 15)
def test_graph_Gnm_invalid_inputs(self):
with self.assertRaises(AssertionError):
eg.graph_Gnm(1, 1)
with self.assertRaises(AssertionError):
eg.graph_Gnm(5, 11) # 5*4/2 = 10 max
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,87 @@
import unittest
import easygraph as eg
class test_classic(unittest.TestCase):
def setUp(self):
self.G = eg.datasets.get_graph_karateclub()
def test_empty_graph(self):
# print(eg.empty_graph(-1).nodes)
print(eg.empty_graph(10).nodes)
def test_path_graph(self):
eg.path_graph(10, eg.DiGraph)
def test_complete_graph(self):
eg.complete_graph(10, eg.DiGraph)
def test_empty_graph_default(self):
G = eg.empty_graph()
self.assertEqual(len(G.nodes), 0)
self.assertEqual(len(G.edges), 0)
def test_empty_graph_with_n(self):
G = eg.empty_graph(5)
self.assertEqual(set(G.nodes), set(range(5)))
self.assertEqual(len(G.edges), 0)
def test_empty_graph_with_custom_nodes(self):
G = eg.empty_graph(["a", "b", "c"])
self.assertEqual(set(G.nodes), {"a", "b", "c"})
self.assertEqual(len(G.edges), 0)
def test_empty_graph_with_existing_graph(self):
existing = eg.Graph()
existing.add_node(999)
G = eg.empty_graph(3, create_using=existing)
self.assertIn(0, G.nodes) # node 0 added
self.assertEqual(len(G.nodes), 4) # 999 is retained
self.assertEqual(len(G.edges), 0)
def test_path_graph_basic(self):
G = eg.path_graph(4)
self.assertEqual(len(G.nodes), 4)
self.assertEqual(len(G.edges), 3)
edges = {(u, v) for u, v, _ in G.edges}
self.assertTrue((0, 1) in edges and (1, 2) in edges and (2, 3) in edges)
def test_path_graph_with_custom_nodes(self):
G = eg.path_graph(["x", "y", "z"])
self.assertEqual(len(G.nodes), 3)
actual_edges = {(u, v) for u, v, _ in G.edges}
expected_edges = {("x", "y"), ("y", "z")}
self.assertEqual(actual_edges, expected_edges)
def test_complete_graph_basic(self):
G = eg.complete_graph(4)
self.assertEqual(len(G.nodes), 4)
self.assertEqual(len(G.edges), 6) # n*(n-1)/2 for undirected
def test_complete_graph_directed(self):
G = eg.complete_graph(3, create_using=eg.DiGraph())
self.assertTrue(G.is_directed())
self.assertEqual(len(G.nodes), 3)
self.assertEqual(len(G.edges), 6) # n*(n-1) for directed
def test_complete_graph_custom_nodes(self):
G = eg.complete_graph(["a", "b", "c"])
self.assertEqual(set(G.nodes), {"a", "b", "c"})
actual_edges = {(u, v) for u, v, _ in G.edges}
expected_edges = {("a", "b"), ("a", "c"), ("b", "c")}
self.assertEqual(actual_edges, expected_edges)
def test_complete_graph_one_node(self):
G = eg.complete_graph(1)
self.assertEqual(len(G.nodes), 1)
self.assertEqual(len(G.edges), 0)
def test_complete_graph_zero_nodes(self):
G = eg.complete_graph(0)
self.assertEqual(len(G.nodes), 0)
self.assertEqual(len(G.edges), 0)
if __name__ == "__main__":
unittest.main()