Skip to content

Commit

Permalink
unittests use undirected graph wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Jul 26, 2018
1 parent 967c9fe commit 7871c43
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions graphi_unittests/types_unittests/test_adjacency_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import graphi.types.adjacency_graph
import graphi.abc
from graphi import operators
from graphi.types.undirected import Undirected

from . import _graph_interface_mixins as mixins

Expand Down Expand Up @@ -51,16 +52,16 @@ def make_content_samples(self, lengths=range(5, 101, 20), connections=None, dist

def test_init_undirected(self):
with self.assertRaises(ValueError):
self.graph_cls({
Undirected(self.graph_cls({
1: {2: 1, 3: 1},
2: {1: 1},
3: {1: 2}
}, undirected=True)
}))

graph = self.graph_cls({
graph = Undirected(self.graph_cls({
1: {2: 1, 3: 1},
2: {1: 1}
}, undirected=True)
}))
self.assertEquals(graph[1:3], graph[3:1])

def test_containment(self):
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_containment(self):

def test_set(self):
"""Adjacency Graph: change/add elements"""
graph = self.graph_cls({
graph = Undirected(self.graph_cls({
1: {2: 1, 3: 1, 4: 1, 5: 1, 6: 2, 8: 1},
2: {1: 1},
3: {1: 1},
Expand All @@ -102,7 +103,7 @@ def test_set(self):
6: {1: 2, 7: 1},
7: {6: 1},
8: {1: 1}
}, undirected=True)
}))
self.assertFalse(slice(1, 7) in graph)
graph[1:7] = 2
self.assertEqual(2, graph[1:7])
Expand Down Expand Up @@ -182,12 +183,12 @@ def test_deletion(self):
graph[8:1]

def test_deletion_undirected(self):
graph = self.graph_cls({
graph = Undirected(self.graph_cls({
1: {2: 1, 3: 1, 4: 1},
2: {1: 1},
3: {1: 1},
4: {1: 1}
}, undirected=True)
}))
del graph[1:2]
with self.assertRaises(graphi.abc.EdgeError):
graph[1:2]
Expand Down Expand Up @@ -216,29 +217,29 @@ def test_neighbours(self):
operators.neighbours(graph, 9)

def test_update(self):
graph = self.graph_cls({
graph = Undirected(self.graph_cls({
1: {2: 1, 3: 1, 4: 1},
2: {1: 1},
3: {1: 1},
4: {1: 1}
}, undirected=True)
}))
graph.update((5, 6))
self.assertIn(5, graph)
self.assertIn(6, graph)

def test_clear(self):
graph = self.graph_cls({
graph = Undirected(self.graph_cls({
1: {2: 1, 3: 1, 4: 1},
2: {1: 1},
3: {1: 1},
4: {1: 1}
}, undirected=True)
}))
self.assertEquals(len(graph), 4)
graph.clear()
self.assertEquals(len(graph), 0)

def test_edge_view_undirected(self):
graph = self.graph_cls({1, 2, 3, 4}, undirected=True)
graph = Undirected(self.graph_cls({1, 2, 3, 4}))
nodes = [2, 3, 4]
for node in nodes:
graph[1:node] = 1
Expand Down Expand Up @@ -282,7 +283,7 @@ def test_edge_view_directed(self):
None in edge_view

def test_value_view_undirected(self):
graph = self.graph_cls({1, 2, 3, 4}, undirected=True)
graph = Undirected(self.graph_cls({1, 2, 3, 4}))
nodes = [2, 3, 4]
for value, node in enumerate(nodes):
graph[1:node] = value
Expand Down

0 comments on commit 7871c43

Please sign in to comment.