예제 #1
0
    def test_add_response(self):
        r = Responder()
        r.add_response("abc*", 8)
        r.add_response("def+", 9)

        self.assertEqual(r.get_response("ab")[0], 8)
        self.assertEqual(r.get_response("abc")[0], 8)
        self.assertEqual(r.get_response("abccccc")[0], 8)

        self.assertEqual(r.get_response("def")[0], 9)
        self.assertEqual(r.get_response("deff")[0], 9)
        self.assertEqual(r.get_response("deffff")[0], 9)
예제 #2
0
    def test_add_response_list_or_string(self):
        r1 = Responder()
        r2 = Responder()

        r1.add_response("a|b", 1)
        r1.add_default_response(2)

        r2.add_response(["a", "b"], 1)
        r2.add_default_response(2)

        for r in [r1, r2]:
            self.assertEqual(r.get_response("a")[0], 1)
            self.assertEqual(r.get_response("b")[0], 1)
            self.assertEqual(r.get_response("e")[0], 2)
            self.assertEqual(r.get_response("gfnhvmnbvjm")[0], 2)