File size: 1,381 Bytes
f55fed4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest

from programmatic_solvers import try_programmatic_answer


class ProgrammaticSolverTests(unittest.TestCase):
    def test_solves_reversed_instruction_without_task_id(self):
        question = '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI'

        self.assertEqual(try_programmatic_answer(question), "Right")

    def test_solves_noncommutative_elements_from_markdown_table(self):
        question = """
        Given this table defining * on the set S = {a, b, c}

        |*|a|b|c|
        |---|---|---|---|
        |a|a|b|c|
        |b|c|b|a|
        |c|c|a|c|

        Provide the list of elements involved in making * not commutative.
        """

        self.assertEqual(try_programmatic_answer(question), "a, b")

    def test_filters_botanical_vegetables_and_alphabetizes(self):
        question = """
        I'm making a grocery list. Please alphabetize the list of vegetables:
        apples, broccoli, celery, fresh basil, lettuce, strawberries, sweet potatoes, tomatoes.
        """

        self.assertEqual(
            try_programmatic_answer(question),
            "broccoli, celery, fresh basil, lettuce, sweet potatoes",
        )

    def test_unknown_question_returns_none(self):
        self.assertIsNone(try_programmatic_answer("Who wrote Hamlet?"))


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