def test_edge_satisfies_eq(self): constraints = {"weight": {"==": [10]}} edge = {"weight": 11} self.assertFalse(_edge_satisfies_constraints(edge, constraints)) constraints = {"weight": {"==": [-10.5]}} edge = {"weight": -21 / 3} self.assertFalse(_edge_satisfies_constraints(edge, constraints))
def test_edge_satisfies_lte(self): constraints = {"weight": {"<=": [10]}} edge = {"weight": 100} self.assertFalse(_edge_satisfies_constraints(edge, constraints)) constraints = {"weight": {"<=": [10]}} edge = {"weight": 100} self.assertFalse(_edge_satisfies_constraints(edge, constraints))
def test_edge_satisfies_gte(self): constraints = {"weight": {">=": [10]}} edge = {"weight": 10} self.assertTrue(_edge_satisfies_constraints(edge, constraints)) constraints = {"weight": {">=": [10]}} edge = {"weight": 100} self.assertTrue(_edge_satisfies_constraints(edge, constraints))
def test_edge_neq(self): constraints = {"weight": {"!=": [10]}} edge = {"weight": 11} self.assertTrue(_edge_satisfies_constraints(edge, constraints)) constraints = {"weight": {"!=": [10]}} edge = {"weight": "TURTLE"} self.assertTrue(_edge_satisfies_constraints(edge, constraints))
def test_in(self): constraints = {"name": {"in": [["A", "B"]]}} H = nx.DiGraph() H.add_edge("y", "z", name="A") H.add_edge("a", "b", name="B") for _, _, a in H.edges(data=True): self.assertTrue(_edge_satisfies_constraints(a, constraints)) H = nx.DiGraph() H.add_edge("y", "z", name="C") H.add_edge("a", "b", name="['A']") for _, _, a in H.edges(data=True): self.assertFalse(_edge_satisfies_constraints(a, constraints))
def test_contains(self): constraints = {"name": {"contains": ["oodle"]}} H = nx.DiGraph() H.add_edge("y", "z", name="poodle") H.add_edge("a", "b", name="Doodles") for _, _, a in H.edges(data=True): self.assertTrue(_edge_satisfies_constraints(a, constraints)) H = nx.DiGraph() H.add_edge("y", "z", name="puddle") H.add_edge("a", "b", name="DOodles") for _, _, a in H.edges(data=True): self.assertFalse(_edge_satisfies_constraints(a, constraints))
def test_nx_edges(self): constraints = {"weight": {">=": [7]}} H = nx.DiGraph() H.add_edge("y", "x", weight=10) H.add_edge("a", "x", weight=7.0) for _, _, a in H.edges(data=True): self.assertTrue(_edge_satisfies_constraints(a, constraints)) H = nx.DiGraph() H.add_edge("y", "x", weight=4) H.add_edge("a", "x", weight=3.0) for _, _, a in H.edges(data=True): self.assertFalse(_edge_satisfies_constraints(a, constraints))
def test_edge_many_some_not_satisfies(self): constraints = { "weight": { "!=": [10], "==": [9] }, "mode": { "==": "normal" } } edge = {"weight": 10.0} self.assertFalse(_edge_satisfies_constraints(edge, constraints)) edge = {"mode": "abnormal"} self.assertFalse(_edge_satisfies_constraints(edge, constraints))
def test_in_string(self): constraints = {"name": {"in": ["abcdefghijklmnopqrstuvwxyz"]}} H = nx.DiGraph() H.add_edge("y", "z", name="cde") H.add_edge("a", "b", name="jklm") for _, _, a in H.edges(data=True): self.assertTrue(_edge_satisfies_constraints(a, constraints))
def test_edge_satisfies_gt(self): constraints = {"weight": {">": [10]}} edge = {"weight": 1} self.assertFalse(_edge_satisfies_constraints(edge, constraints))
def test_edge_satisfies_lt(self): constraints = {"weight": {"<": [10]}} edge = {"weight": -100} self.assertTrue(_edge_satisfies_constraints(edge, constraints))
def test_edge_many_satisfies(self): constraints = {"weight": {"!=": [10], "==": [9]}} edge = {"weight": 9.0} self.assertTrue(_edge_satisfies_constraints(edge, constraints))