-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_edge.py
98 lines (83 loc) · 4.03 KB
/
test_edge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from edge import Edge
import unittest
from node import Node
class TestEdgeMethods(unittest.TestCase):
""" Teste les differentes fonctions de la classe Edge."""
n1 = Node(name="test1")
n2 = Node(name="test2")
n3 = Node(name="test3")
def setUp(self):
""" Liste de commandes qui sera lancee a chaque test """
self.edg_test1 = Edge("edge_test1", [self.n1, self.n2, 79])
self.edg_test2 = Edge(data=[self.n2, self.n3], name="edge_test2")
self.edg_test3 = Edge("edge_test2")
self.edg_test4 = Edge("edge_test4", [])
self.edg_test5 = Edge("edge_test5", [])
self.edg_def = Edge()
def test_get_name(self):
""" Verification du nom renvoye par la fonction get_name. """
self.assertEqual('Sans nom', self.edg_def.get_name())
self.assertEqual('edge_test1', self.edg_test1.get_name())
self.assertEqual('edge_test2', self.edg_test2.get_name())
def test_get_data(self):
""" Verification que le pointeur de donnees renvoie vers quelque chose. """
self.failUnless(self.edg_def.get_data() is not None)
self.failUnless(self.edg_test2.get_data() is not None)
def test_get_start(self):
""" Verification que le pointeur de donnees renvoie vers quelque chose. """
self.failUnless(self.edg_def.start is None)
self.failUnless(self.edg_test3.start is None)
self.failUnless(self.edg_test4.start is None)
self.failUnless(self.edg_test2.start is not None)
def test_get_end(self):
""" Verification que le pointeur de donnees renvoie vers quelque chose. """
self.failUnless(self.edg_def.end is None)
self.failUnless(self.edg_test2.end is not None)
self.failUnless(self.edg_test4.end is None)
def test_get_weight(self):
""" Verification que le pointeur de donnees renvoie vers quelque chose. """
self.failUnless(self.edg_def.weight is None)
self.failUnless(self.edg_test2.weight is None)
def test_set_start(self):
""" Verification que le pointeur de donnees renvoie vers quelque chose. """
self.edg_def.start = Node()
self.edg_test2.start = Node()
self.edg_test5.start = Node()
self.failUnless(self.edg_def.start is not None)
self.failUnless(self.edg_test2.start is not None)
def test_set_end(self):
""" Verification que le noeud d'arrivee est bien affecte"""
self.edg_def.end = self.n1
self.edg_test2.end = self.n2
self.edg_test4.end = []
self.failUnless(self.edg_def.end == self.n1)
self.failUnless(self.edg_test2.end == self.n2)
self.failUnless(self.edg_test3.end is None)
self.failUnless(self.edg_test4.end is None)
def test_set_weight(self):
""" Verification que le poids est bien affecte"""
self.edg_def.weight = 5
self.edg_test2.weight = 79
self.failUnless(self.edg_def.weight == 5)
self.failUnless(self.edg_test2.weight == 79)
def test_repr(self):
""" Verification qu'une chaine de caracteres est bien renvoyee a l'affichage par le module print """
self.assertTrue(isinstance(self.edg_test1.__repr__(), str))
def test_comparison(self):
""" Verification des comparaisons entre les differentes aretes"""
self.edg_def.weight = 5
self.edg_test2.weight = 79
self.failUnless(self.edg_test1 >= self.edg_def)
self.failIf(self.edg_def >= self.edg_test1)
self.failUnless(self.edg_test1 > self.edg_def)
self.failIf(self.edg_def > self.edg_test1)
self.failUnless(self.edg_def <= self.edg_test1)
self.failIf(self.edg_test1 <= self.edg_def)
self.failUnless(self.edg_def < self.edg_test1)
self.failIf(self.edg_test1 < self.edg_def)
self.failUnless(self.edg_test1 == self.edg_test2)
self.failIf(self.edg_test2.weight == self.edg_def.weight)
self.failUnless(self.edg_test1 != self.edg_def)
self.failIf(self.edg_test2.weight != self.edg_test1.weight)
if __name__ == '__main__':
unittest.main()