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,27 @@
import unittest
import easygraph as eg
class TestGeometry(unittest.TestCase):
def setUp(self):
self.G = eg.datasets.get_graph_karateclub()
def test_overall(self):
eg.draw_SHS_center(self.G, [1, 33, 34], style="side")
eg.draw_SHS_center(self.G, [1, 33, 34], style="center")
eg.draw_SHS_center_kk(self.G, [1, 33, 34], style="side")
eg.draw_SHS_center_kk(self.G, [1, 33, 34], style="center")
eg.draw_kamada_kawai(self.G, style="side")
eg.draw_kamada_kawai(self.G, style="center")
eg.draw_SHS_center(self.G, [1, 33, 34], rate=0.8, style="side")
eg.draw_SHS_center(self.G, [1, 33, 34], rate=0.8, style="center")
eg.draw_SHS_center_kk(self.G, [1, 33, 34], rate=0.8, style="side")
eg.draw_SHS_center_kk(self.G, [1, 33, 34], rate=0.8, style="center")
eg.draw_kamada_kawai(self.G, rate=0.8, style="side")
eg.draw_kamada_kawai(self.G, rate=0.8, style="center")
if __name__ == "__main__":
unittest.main()
# pretty awesome images
@@ -0,0 +1,78 @@
import math
import unittest
import numpy as np
from easygraph.functions.drawing.geometry import common_tangent_radian
from easygraph.functions.drawing.geometry import polar_position
from easygraph.functions.drawing.geometry import rad_2_deg
from easygraph.functions.drawing.geometry import radian_from_atan
from easygraph.functions.drawing.geometry import vlen
class TestGeometryUtils(unittest.TestCase):
def test_radian_from_atan_axes(self):
self.assertAlmostEqual(radian_from_atan(0, 1), math.pi / 2)
self.assertAlmostEqual(radian_from_atan(0, -1), 3 * math.pi / 2)
self.assertAlmostEqual(radian_from_atan(1, 0), 0)
self.assertAlmostEqual(radian_from_atan(-1, 0), math.pi)
def test_radian_from_atan_quadrants(self):
# Q1
self.assertAlmostEqual(radian_from_atan(1, 1), math.atan(1))
# Q4
self.assertAlmostEqual(radian_from_atan(1, -1), math.atan(-1) + 2 * math.pi)
# Q2
self.assertAlmostEqual(radian_from_atan(-1, 1), math.atan(-1) + math.pi)
# Q3
self.assertAlmostEqual(radian_from_atan(-1, -1), math.atan(1) + math.pi)
def test_radian_from_atan_zero_vector(self):
result = radian_from_atan(0, 0)
self.assertAlmostEqual(result, 3 * math.pi / 2)
def test_vlen(self):
self.assertEqual(vlen((3, 4)), 5.0)
self.assertEqual(vlen((0, 0)), 0.0)
self.assertAlmostEqual(vlen((-3, -4)), 5.0)
def test_common_tangent_radian_basic(self):
r1, r2, d = 3, 2, 5
angle = common_tangent_radian(r1, r2, d)
expected = math.acos(abs(r2 - r1) / d)
self.assertAlmostEqual(angle, expected)
def test_common_tangent_radian_reversed(self):
r1, r2, d = 2, 3, 5
angle = common_tangent_radian(r1, r2, d)
expected = math.pi - math.acos(abs(r2 - r1) / d)
self.assertAlmostEqual(angle, expected)
def test_common_tangent_radian_touching(self):
self.assertAlmostEqual(common_tangent_radian(3, 3, 5), math.pi / 2)
def test_common_tangent_radian_invalid(self):
with self.assertRaises(ValueError):
common_tangent_radian(5, 1, 2)
def test_polar_position_origin(self):
pos = polar_position(0, 0, np.array([5, 5]))
np.testing.assert_array_almost_equal(pos, np.array([5, 5]))
def test_polar_position_90deg(self):
pos = polar_position(1, math.pi / 2, np.array([0, 0]))
np.testing.assert_array_almost_equal(pos, np.array([0, 1]))
def test_polar_position_negative_angle(self):
pos = polar_position(1, -math.pi / 2, np.array([1, 1]))
np.testing.assert_array_almost_equal(pos, np.array([1, 0]))
def test_rad_2_deg(self):
self.assertEqual(rad_2_deg(0), 0)
self.assertEqual(rad_2_deg(math.pi), 180)
self.assertEqual(rad_2_deg(2 * math.pi), 360)
self.assertEqual(rad_2_deg(-math.pi / 2), -90)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,39 @@
import unittest
import easygraph as eg
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.api as sm
class TestPlot(unittest.TestCase):
def setUp(self):
self.ds = eg.datasets.get_graph_karateclub()
self.edges = [
(1, 4),
(2, 4),
("String", "Bool"),
(4, 1),
(0, 4),
(4, 256),
((1, 2), (3, 4)),
]
self.test_graphs = [eg.Graph(), eg.DiGraph()]
self.test_graphs.append(eg.classes.DiGraph(self.edges))
self.shs = eg.common_greedy(self.ds, int(len(self.ds.nodes) / 3))
def test_plot_Followers(self):
eg.functions.plot_Followers(self.ds, self.shs)
def test_plot_Connected_Communities(self):
eg.functions.plot_Connected_Communities(self.ds, self.shs)
def test_plot_Neighborhood_Followers(self):
eg.functions.plot_Neighborhood_Followers(self.ds, self.shs)
def test_plot_Betweenness_Centrality(self):
eg.functions.plot_Betweenness_Centrality(self.ds, self.shs)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,56 @@
import unittest
import easygraph as eg
import matplotlib.pyplot as plt
import numpy as np
class TestPositioning(unittest.TestCase):
def setUp(self):
self.ds = eg.datasets.get_graph_karateclub()
self.edges = [
(1, 4),
(2, 4),
("String", "Bool"),
(4, 1),
(0, 4),
(4, 256),
((1, 2), (3, 4)),
]
self.test_graphs = [eg.Graph(), eg.DiGraph()]
self.test_graphs.append(eg.classes.DiGraph(self.edges))
self.shs = eg.common_greedy(self.ds, int(len(self.ds.nodes) / 3))
def test_random_position(self):
print()
for i in self.test_graphs:
print(eg.random_position(i))
def test_circular_position(self):
print()
for i in self.test_graphs:
print(eg.circular_position(i))
def test_shell_position(self):
print()
for i in self.test_graphs:
print(eg.shell_position(i))
def test_rescale_position(self):
print()
for i in self.test_graphs:
try:
pos = eg.random_position(i)
obj = np.array(list(pos.values()))
print(eg.rescale_position(obj))
except Exception as e:
print(e)
def test_kamada_kawai_layout(self):
print()
for i in self.test_graphs:
print(eg.kamada_kawai_layout(i))
if __name__ == "__main__":
unittest.main()