view unit-tests/topo-test.py @ 76:aa2dadf04144

fixed the topo sorting and added a unit test
author Scott Chacon <schacon@gmail.com>
date Fri, 01 May 2009 20:05:30 -0700
parents
children 71b07e16004f
line wrap: on
line source

import random, sys
import unittest

sys.path.append('../')

import toposort

class Ob:
    def __init__(self, eyedee, parents):
        self._id = eyedee
        self._parents = parents
        
    def id(self):
        return self._id

    def parents(self):
        return self._parents


class TestTopoSorting(unittest.TestCase):

    def testsort(self):
        data = {
         'f' : Ob('f', ['d', 'e']),
         'd' : Ob('d', ['b']),
         'e' : Ob('e', ['c', 'g']),
         'g' : Ob('g', ['c']),
         'c' : Ob('c', ['b', 'h']),
         'b' : Ob('b', ['a']),
         'h' : Ob('h', ['a']),
         'a' : Ob('a', []),
        }
        d = toposort.TopoSort(data).items()
        sort = ['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
        self.assertEquals(d, sort)

if __name__ == '__main__':
    unittest.main()