Exemplo n.º 1
0
def run(args):
    """Runs the core of the script; builds the graph and performs the required
    search type

    Split out as a separate function to facilitate optional profiling

    :param args: the arguments object generated by the script call
    """

    io = IO()

    reader = io.read_dictionary(args.dictionary_path)

    graph = WordGraph()

    for word in reader:
        graph.add(word)

    if args.all_paths:
        paths = graph.find_all_paths(args.word_from, args.word_to)
        for path in paths:
            print io.format_word_path(path)
    else:
        path = graph.find_path(args.word_from, args.word_to)
        print io.format_word_path(path)
Exemplo n.º 2
0
    def test_path_output_format(self):
        io = IO()
        word_path = ["hat", "mat", "bat"]
        formatted_path = io.format_word_path(word_path)

        self.assertEqual(formatted_path, "hat -> mat -> bat")