view unit-tests/topo-test.py @ 254:07c7697e2aaa

Added tag 0.1.0 for changeset 505d7cdca198
author Augie Fackler <durin42@gmail.com>
date Sat, 17 Oct 2009 20:12:19 -0400
parents 312700177979
children
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

#   f
#  /\
# e  \
# |\  \
# | g |
# |/  |
# c   d
# |\ /
# h b 
# |/
# a 

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()