# Path: coloredcoinlib/toposort.py
# def toposorted(graph, parents):
#     """
#     Returns vertices of a directed acyclic graph in topological order.
# 
#     Arguments:
#     graph -- vetices of a graph to be toposorted
#     parents -- function (vertex) -> vertices to preceed
#                given vertex in output
#     """
#     result = []
#     used = set()
# 
#     def use(v, top):
#         if id(v) in used:
#             return
#         for parent in parents(v):
#             if parent is top:
#                 raise ValueError('Graph is cyclical!', graph)
#             use(parent, v)
#         used.add(id(v))
#         result.append(v)
#     for v in graph:
#         use(v, v)
#     return result


import os
import unittest
from coloredcoinlib.toposort import toposorted
#!/usr/bin/env python




class TestSort(unittest.TestCase):
    def setUp(self):
        self.a = 'a'
        self.b = 'b'
        self.l = [self.a, self.b]

    def test_toposort(self):
        def get_all(x):
            return self.l
        self.assertRaises(ValueError, toposorted, self.l, get_all)
        def get_a(x):
            if x == 'a':
                return ['b']
            return []

# Path: coloredcoinlib/toposort.py
# def toposorted(graph, parents):
#     """
#     Returns vertices of a directed acyclic graph in topological order.
# 
#     Arguments:
#     graph -- vetices of a graph to be toposorted
#     parents -- function (vertex) -> vertices to preceed
#                given vertex in output
#     """
#     result = []
#     used = set()
# 
#     def use(v, top):
#         if id(v) in used:
#             return
#         for parent in parents(v):
#             if parent is top:
#                 raise ValueError('Graph is cyclical!', graph)
#             use(parent, v)
#         used.add(id(v))
#         result.append(v)
#     for v in graph:
#         use(v, v)
#     return result


# Path: coloredcoinlib/tests/test_toposort.py
import os
import unittest
from coloredcoinlib.toposort import toposorted

#!/usr/bin/env python




class TestSort(unittest.TestCase):
    def setUp(self):
        self.a = 'a'
        self.b = 'b'
        self.l = [self.a, self.b]

    def test_toposort(self):
        def get_all(x):
            return self.l
        self.assertRaises(ValueError, toposorted, self.l, get_all)
        def get_a(x):
            if x == 'a':
                return ['b']
            return []

        self.assertEquals(toposorted(self.l, get_a), ['b', 'a'])