Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
test(kg): remove shadowed duplicate Test*EdgeCases classes
Anai-Guo90a5f865e68b
diff --git a/tests/kg/test_link_predictor.py b/tests/kg/test_link_predictor.pyindex f27d9b8c..c79fbc14 100644--- a/tests/kg/test_link_predictor.py+++ b/tests/kg/test_link_predictor.py@@ -456,96 +456,6 @@ class TestLinkPredictorMethods:assert score >= 0-class TestLinkPredictorEdgeCases:- """Edge case tests for LinkPredictor."""-- def setup_method(self):- """Set up test fixtures."""- self.predictor = LinkPredictor()-- def test_empty_graph(self):- """Test link prediction on empty graph."""- empty_graph = nx.Graph()-- links = self.predictor.predict_links(empty_graph, top_k=5)- assert links == []-- def test_single_node_graph(self):- """Test link prediction on single node graph."""- single_node_graph = nx.Graph()- single_node_graph.add_node("A")-- links = self.predictor.predict_links(single_node_graph, top_k=5)- assert links == []-- def test_complete_graph(self):- """Test link prediction on complete graph."""- complete_graph = nx.complete_graph(3)- complete_graph = nx.relabel_nodes(complete_graph, {i: str(i) for i in range(3)})-- links = self.predictor.predict_links(complete_graph, top_k=5, exclude_existing=True)- assert links == [] # No missing links in complete graph-- def test_disconnected_components(self):- """Test link prediction on disconnected graph."""- disconnected_graph = nx.Graph()- disconnected_graph.add_edges_from([("A", "B"), ("B", "C")]) # Component 1- disconnected_graph.add_edges_from([("X", "Y"), ("Y", "Z")]) # Component 2-- # Should predict links between components- links = self.predictor.predict_links(disconnected_graph, top_k=10)-- # Should include cross-component predictions- cross_component_links = [- link for link in links- if (link[0] in ["A", "B", "C"] and link[1] in ["X", "Y", "Z"]) or- (link[1] in ["A", "B", "C"] and link[0] in ["X", "Y", "Z"])- ]- assert len(cross_component_links) > 0-- def test_star_graph(self):- """Test link prediction on star graph."""- star_graph = nx.star_graph(5) # Central node 0, leaves 1-5- star_graph = nx.relabel_nodes(star_graph, {i: str(i) for i in range(6)})-- # Preferential attachment should favor connections to center- center_links = self.predictor.predict_links(- star_graph,- method="preferential_attachment",- top_k=10- )-- # Should predict leaf-leaf connections (center already connected to all)- leaf_links = [- link for link in center_links- if link[0] != "0" and link[1] != "0" # Both are leaves- ]- assert len(leaf_links) > 0-- def test_high_degree_node_bias(self):- """Test preferential attachment bias towards high-degree nodes."""- # Create graph with one high-degree node- biased_graph = nx.Graph()- biased_graph.add_node("hub")- for i in range(10):- biased_graph.add_node(f"leaf_{i}")- biased_graph.add_edge("hub", f"leaf_{i}")-- # Preferential attachment should favor hub-hub connections (if any)- # But since hub is already connected to all, should predict leaf-leaf- links = self.predictor.predict_links(- biased_graph,- method="preferential_attachment",- top_k=5- )-- # All predicted links should be between leaves- for node1, node2, score in links:- assert node1.startswith("leaf_")- assert node2.startswith("leaf_")- assert node1 != node2--class TestLinkPredictorEdgeCases:"""Edge case tests for LinkPredictor."""diff --git a/tests/kg/test_path_finder.py b/tests/kg/test_path_finder.pyindex 76e5b0b4..2fd343c3 100644--- a/tests/kg/test_path_finder.py+++ b/tests/kg/test_path_finder.py@@ -359,81 +359,6 @@ class TestPathFinder:assert weight == 1.0-class TestPathFinderEdgeCases:- """Edge case tests for PathFinder."""-- def setup_method(self):- """Set up test fixtures."""- self.finder = PathFinder()-- def test_empty_graph(self):- """Test path finding on empty graph."""- empty_graph = nx.Graph()-- with pytest.raises(ValueError, match="Source node A not found"):- self.finder.dijkstra_shortest_path(empty_graph, "A", "B")-- def test_single_node_graph(self):- """Test path finding on single node graph."""- single_node_graph = nx.Graph()- single_node_graph.add_node("A")-- # Same source and target- path = self.finder.dijkstra_shortest_path(single_node_graph, "A", "A")- assert path == ["A"]-- # Different nodes (target doesn't exist)- with pytest.raises(ValueError, match="Target node B not found"):- self.finder.dijkstra_shortest_path(single_node_graph, "A", "B")-- def test_cycle_graph(self):- """Test path finding on cycle graph."""- cycle_graph = nx.cycle_graph(4) # 0-1-2-3-0- # Convert to string nodes for consistency- cycle_graph = nx.relabel_nodes(cycle_graph, {i: str(i) for i in range(4)})-- path = self.finder.dijkstra_shortest_path(cycle_graph, "0", "2")- assert path in [["0", "1", "2"], ["0", "3", "2"]]-- def test_complete_graph(self):- """Test path finding on complete graph."""- complete_graph = nx.complete_graph(4)- complete_graph = nx.relabel_nodes(complete_graph, {i: str(i) for i in range(4)})-- path = self.finder.dijkstra_shortest_path(complete_graph, "0", "3")- assert path == ["0", "3"] # Direct edge in complete graph-- def test_large_graph_performance(self):- """Test path finding performance on larger graph."""- # Create a larger graph for performance testing- large_graph = nx.erdos_renyi_graph(100, 0.1)- large_graph = nx.relabel_nodes(large_graph, {i: str(i) for i in range(100)})-- # Test that it completes without error- path = self.finder.dijkstra_shortest_path(large_graph, "0", "99")- assert isinstance(path, list)-- def test_graph_with_loops(self):- """Test path finding on graph with self-loops."""- loop_graph = nx.Graph()- loop_graph.add_edges_from([("A", "B"), ("B", "C")])- loop_graph.add_edge("A", "A") # Self-loop-- path = self.finder.dijkstra_shortest_path(loop_graph, "A", "C")- assert path == ["A", "B", "C"]-- def test_graph_with_multiple_edges(self):- """Test path finding on multigraph."""- multigraph = nx.MultiGraph()- multigraph.add_edge("A", "B", weight=1)- multigraph.add_edge("A", "B", weight=2)- multigraph.add_edge("B", "C", weight=1)-- # PathFinder should handle multigraphs (use first edge)- path = self.finder.dijkstra_shortest_path(multigraph, "A", "C")- assert path == ["A", "B", "C"]--class TestPathFinderHeuristics:"""Test heuristic functions for A* search."""diff --git a/tests/kg/test_similarity_calculator.py b/tests/kg/test_similarity_calculator.pyindex 2cdf0955..25bb8a7b 100644--- a/tests/kg/test_similarity_calculator.py+++ b/tests/kg/test_similarity_calculator.py@@ -368,69 +368,6 @@ class TestSimilarityCalculator:assert abs(similarity_matrix[0, 2] - 1.0) < 1e-10 # vec1 and vec3 identical-class TestSimilarityCalculatorEdgeCases:- """Edge case tests for SimilarityCalculator."""-- def test_zero_vectors(self):- """Test similarity calculations with zero vectors."""- calculator = SimilarityCalculator()-- zero_vec = [0.0, 0.0, 0.0]- normal_vec = [1.0, 0.0, 0.0]-- # Cosine similarity with zero vector- similarity = calculator.cosine_similarity(zero_vec, normal_vec)- assert similarity == 0.0-- # Euclidean distance with zero vector- distance = calculator.euclidean_distance(zero_vec, normal_vec)- assert distance == 1.0-- # Manhattan distance with zero vector- distance = calculator.manhattan_distance(zero_vec, normal_vec)- assert distance == 1.0-- def test_single_dimension_vectors(self):- """Test similarity calculations with single dimension vectors."""- calculator = SimilarityCalculator()-- vec1 = [1.0]- vec2 = [2.0]-- # Cosine similarity- similarity = calculator.cosine_similarity(vec1, vec2)- assert similarity == 1.0 # Same direction-- # Euclidean distance- distance = calculator.euclidean_distance(vec1, vec2)- assert distance == 1.0-- # Manhattan distance- distance = calculator.manhattan_distance(vec1, vec2)- assert distance == 1.0-- def test_negative_values(self):- """Test similarity calculations with negative values."""- calculator = SimilarityCalculator()-- vec1 = [1.0, -1.0]- vec2 = [-1.0, 1.0]-- # Cosine similarity (opposite directions)- similarity = calculator.cosine_similarity(vec1, vec2)- assert abs(similarity + 1.0) < 1e-10 # Should be -1-- # Euclidean distance- distance = calculator.euclidean_distance(vec1, vec2)- expected = np.sqrt((1-(-1))**2 + (-1-1)**2)- assert abs(distance - expected) < 1e-10-- # Manhattan distance- distance = calculator.manhattan_distance(vec1, vec2)- expected = abs(1-(-1)) + abs(-1-1)- assert distance == expected--class TestSimilarityCalculatorEdgeCases:"""Edge case tests for SimilarityCalculator."""