Exemple #1
0
class PaperWriterTest(unittest.TestCase):
    def setUp(self):
        self.paperwriter = PaperWriter(None)  # TODO: give topic
        self.n = 5
        self.context = "Alice said"

    #  def test_ngram_generator(self):
    #    self.assertTrue(re.match(self.context.lower().strip() + ".+", self.paperwriter.get_ngram_generator(2, 1)(self.n, self.context)))

    def test_ngram_scorer(self):
        self.assertEqual(self.paperwriter.get_ngram_scorer(self.n, self.context)(""), 0)  # TODO: set n-gram to score

    def test_interactive(self):
        k = 3
        l = 2
        n = 5
        generator = self.paperwriter.get_ngram_generator(k, l)

        words = raw_input("input at least %d word(s): " % (l))
        while True:
            choices = []
            for i in range(3):
                choices.append(generator(n, words))
                print str(i + 1) + ") " + choices[i]
            resp = None
            nums = range(1, 4)
            while resp not in nums + [True, False]:
                try:
                    resp = input("does the test pass? (1|2|3|True|False): ")
                except NameError:
                    resp = None
            if resp == True:
                break
            if resp in nums:
                words = choices[resp - 1]
                continue
            self.fail()
Exemple #2
0
 def setUp(self):
     self.paperwriter = PaperWriter(None)  # TODO: give topic
     self.n = 5
     self.context = "Alice said"