コード例 #1
0
ファイル: tests.py プロジェクト: wieden-kennedy/django-haikus
class MarkovEvaluatorsTest(TestCase):
    """
    Test the markov evaluator scores haikus according to their fit with a model for 'good' haiku line
    """
    def setUp(self):
        settings.REDIS.update({'db': 1})
        self.markov_evaluator = MarkovEvaluator(prefix="testevaluators")
        self.full_evaluator = FullTextMarkovEvaluator(prefix="testevaluators")
        self.good_lines = [
            ["jumped", "into", "the", "pool"],
            ["i", "jumped", "into", "it"],
            ["i", "jumped", "into", "mud"],
            ["it", "made", "a", "big", "sloppy","mess"],
            ["why", "did", "i", "do", "that"],
            ["why", "did", "we", "do", "that"]
            ]

        self.data = self.markov_evaluator.line_evaluator.markov_data
        for line in self.good_lines:
            self.data.add_line_to_index(line)

    def test_markov_evaluator(self):
        # this haiku matches our model perfectly
        comment = SimpleText.objects.create(text="i jumped into it, it made a big sloppy mess, why did i do that?")
        haiku = HaikuModel.objects.all_from_text(comment)[0]
        self.assertEqual(self.markov_evaluator(haiku), 100)

        #two lines in this haiku are "perfect"
        comment = SimpleText.objects.create(text="i jumped into it, it made a big sloppy mess, why did i do it?")
        haiku = HaikuModel.objects.all_from_text(comment)[0]
        self.assertEqual(self.markov_evaluator(haiku), 250.0/3)

    def test_markov_line_evaluator(self):
        comment = SimpleText.objects.create(text="i jumped into it, it made a big sloppy mess, why did i do that?")
        haiku = HaikuModel.objects.all_from_text(comment)[0]
        assert self.markov_evaluator.line_evaluator(haiku.lines.all()[0].text) == 100

        comment = SimpleText.objects.create(text="i jumped into it, it made a big sloppy mess, why did i do it?")
        haiku = HaikuModel.objects.all_from_text(comment)[0]
        assert self.markov_evaluator.line_evaluator(haiku.lines.all()[2].text) == 50

    def test_full_text_markov_evaluator(self):
        comment = SimpleText.objects.create(text="i jumped into it, it made a big sloppy mess, why did i do that?")
        haiku = HaikuModel.objects.all_from_text(comment)[0]
        self.assertEqual(self.full_evaluator(haiku), 1000.0/14)

        
    def tearDown(self):
        self.data.client.flushdb()
コード例 #2
0
ファイル: tests.py プロジェクト: wieden-kennedy/django-haikus
    def setUp(self):
        settings.REDIS.update({'db': 1})
        self.markov_evaluator = MarkovEvaluator(prefix="testevaluators")
        self.full_evaluator = FullTextMarkovEvaluator(prefix="testevaluators")
        self.good_lines = [
            ["jumped", "into", "the", "pool"],
            ["i", "jumped", "into", "it"],
            ["i", "jumped", "into", "mud"],
            ["it", "made", "a", "big", "sloppy","mess"],
            ["why", "did", "i", "do", "that"],
            ["why", "did", "we", "do", "that"]
            ]

        self.data = self.markov_evaluator.line_evaluator.markov_data
        for line in self.good_lines:
            self.data.add_line_to_index(line)