~maxb/ubuntu/maverick/hg-git/mercurialppa

« back to all changes in this revision

Viewing changes to unit-tests/topo-test.py

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk
  • Date: 2009-06-30 14:19:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090630141910-d7p0gfgih2ez7pg0
Tags: upstream-0+hg20090603
ImportĀ upstreamĀ versionĀ 0+hg20090603

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import random, sys
 
2
import unittest
 
3
 
 
4
sys.path.append('../')
 
5
 
 
6
import toposort
 
7
 
 
8
class Ob:
 
9
    def __init__(self, eyedee, parents):
 
10
        self._id = eyedee
 
11
        self.parents = parents
 
12
        
 
13
    def id(self):
 
14
        return self._id
 
15
 
 
16
#   f
 
17
#  /\
 
18
# e  \
 
19
# |\  \
 
20
# | g |
 
21
# |/  |
 
22
# c   d
 
23
# |\ /
 
24
# h b 
 
25
# |/
 
26
# a 
 
27
 
 
28
class TestTopoSorting(unittest.TestCase):
 
29
 
 
30
    def testsort(self):
 
31
        data = {
 
32
         'f' : Ob('f', ['d', 'e']),
 
33
         'd' : Ob('d', ['b']),
 
34
         'e' : Ob('e', ['c', 'g']),
 
35
         'g' : Ob('g', ['c']),
 
36
         'c' : Ob('c', ['b', 'h']),
 
37
         'b' : Ob('b', ['a']),
 
38
         'h' : Ob('h', ['a']),
 
39
         'a' : Ob('a', []),
 
40
        }
 
41
        d = toposort.TopoSort(data).items()
 
42
        sort = ['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
 
43
        self.assertEquals(d, sort)
 
44
 
 
45
if __name__ == '__main__':
 
46
    unittest.main()