コード例 #1
0
    def test_corresponds(self):
        template = "solution|sol|so"
        command_list = template.split("|")
        word_template = WordTemplate(template)
        for command in command_list:
            self.assertTrue(word_template.corresponds(command))

        template = "create|creat|cr"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.corresponds("cr"))

        template = "create"
        command_list = template.split("|")
        word_template = WordTemplate(template)
        for i in command_list:
            self.assertTrue(word_template.corresponds(i))

        template = "add|ad"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.corresponds("add"))
コード例 #2
0
    def test_mistake_corresponds(self):
        #different symbol mistake
        template = "solution|sol|so"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.mistake_corresponds("solption"))
        self.assertTrue(word_template.mistake_corresponds("solutiop"))
        self.assertTrue(word_template.mistake_corresponds("zolution"))

        #swap mistake
        """template = "solution|sol|so"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.mistake_corresponds("soultion"))
        self.assertTrue(word_template.mistake_corresponds("oslution"))
        self.assertTrue(word_template.mistake_corresponds("solutino"))
        print("---")
        """

        #missed symbol mistake
        template = "solution|sol|so"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.mistake_corresponds("soltion"))
        self.assertTrue(word_template.mistake_corresponds("olution"))
        self.assertTrue(word_template.mistake_corresponds("solutio"))
        self.assertTrue(word_template.mistake_corresponds("slution"))

        #added symbol mistake
        template = "solution|sol|so|create"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.mistake_corresponds("soluztion"))
        self.assertTrue(word_template.mistake_corresponds("szolution"))
        self.assertTrue(word_template.mistake_corresponds("zsolution"))
        self.assertTrue(word_template.mistake_corresponds("creates"))
        self.assertTrue(word_template.mistake_corresponds("sols"))

        #if the word isn't rightit works
        template = "solution|sol|so"
        word_template = WordTemplate(template)

        self.assertFalse(word_template.mistake_corresponds("oslutiop"))

        #if the word isn't right

        template = "solution|create|add|megalongword|problem|gets|task"
        word_template = WordTemplate(template)
        #We don't look for mistakes in words with len less, than 3 symbols
        self.assertFalse(word_template.mistake_corresponds("ad"))
        self.assertFalse(word_template.mistake_corresponds("adb"))
        self.assertFalse(word_template.mistake_corresponds("get"))
        self.assertFalse(word_template.mistake_corresponds("abb"))

        self.assertFalse(word_template.mistake_corresponds("adddddddd"))
        self.assertTrue(word_template.mistake_corresponds("tasc"))
        self.assertFalse(word_template.mistake_corresponds("soluti"))
        self.assertTrue(word_template.mistake_corresponds("creat"))
        self.assertTrue(word_template.mistake_corresponds("gets"))
        self.assertFalse(word_template.mistake_corresponds("megalongwo"))
        self.assertFalse(word_template.mistake_corresponds("ssprbolem"))

        #the  corresponds take it
        template = "solution"
        word_template = WordTemplate(template)
        self.assertTrue(word_template.mistake_corresponds("solution"))

        #if there is no word in template (with mistake)
        template = "get"
        word_template = WordTemplate(template)
        self.assertFalse(word_template.mistake_corresponds("Do"))
コード例 #3
0
ファイル: template.py プロジェクト: parallel-p/please
 def __match(self, template, arg):
     return WordTemplate(template).mistake_corresponds(arg)