示例#1
0
    def test_weight_higher_better(self):
        disc = DiscoverPath(score=get_score(), next_result=get_next_result(), prev_result=get_prev_result(),
                            answers=get_answers(), other_answers=get_other_answers())
        weights = disc._weight_all()
        self.assertEqual(len(weights), 2)

        self.assertEqual(weights[1][1].val, 1)
        self.assertEqual(weights[1][1].pg, 1)
        self.assertEqual(weights[1][1].score, 10)
        self.assertEqual(weights[1][1].rm, [])
        self.assertEqual(len(weights[1][1].add), 1)

        self.assertEqual(weights[1][2].val, 1)
        self.assertEqual(weights[1][2].pg, 2)
        self.assertEqual(weights[1][2].score, 3)
        self.assertEqual(weights[1][2].rm, [])
        self.assertEqual(len(weights[1][2].add), 1)

        self.assertEqual(weights[2][1].val, 2)
        self.assertEqual(weights[2][1].pg, 1)
        self.assertEqual(weights[2][1].score, 15)
        self.assertEqual(len(weights[2][1].rm), 1)
        self.assertEqual(len(weights[2][1].add), 1)

        self.assertEqual(weights[2][2].val, 2)
        self.assertEqual(weights[2][2].pg, 2)
        self.assertEqual(weights[2][2].score, 4)
        self.assertEqual(weights[2][2].rm, [])
        self.assertEqual(len(weights[2][2].add), 2)
示例#2
0
    def test_final_for_better(self):
        next_result = get_next_result()
        prev_result = get_prev_result()
        disc = DiscoverPath(score=get_score(), next_result=next_result, prev_result=prev_result,
                            answers=get_answers(), other_answers=get_other_answers())
        result = disc._get_changes(next_result.min_score - get_score())

        self.assertEqual(len(result), 1)
        self.assertTrue(1 in result)
        self.assertEqual(result[1].val, 1)
        self.assertEqual(result[1].rm, [])
        self.assertEqual(result[1].add[0], AnsTuple(id=3, score=10))
        self.assertEqual(result[1].q, 1)
        self.assertEqual(result[1].pg, 1)
        self.assertEqual(result[1].score, 10)
示例#3
0
    def test_weight_lower_better(self):
        disc = DiscoverPath(score=get_score(), next_result=get_next_result(), prev_result=get_prev_result(),
                            answers=get_answers(), other_answers=get_other_answers())
        disc.higher_is_better = False
        weights = disc._weight_all()
        self.assertEqual(len(weights), 2, 'Not enough weights.')

        self.assertEqual(len(weights[1]), 1, 'Only page one can have improvements with weight=1')
        self.assertEqual(weights[1][1].val, 1)
        self.assertEqual(weights[1][1].score, -10)
        self.assertEqual(len(weights[1][1].rm), 1)
        self.assertEqual(weights[1][1].add, [])

        self.assertEqual(len(weights[2]), 1, 'Only page two can have improvements with weight=2')
        self.assertEqual(weights[2][2].val, 2)
        self.assertEqual(weights[2][2].score, -1)
        self.assertEqual(len(weights[2][2].rm), 1)
        self.assertEqual(len(weights[2][2].add), 1)