Add functionality to test topsort