예제 #1
0
    def test_compare_pairs(self):
        """compare_pairs: should work on simple case"""
        #all the same
        p1 = Pairs([(3, 10), (4, 9), (5, 8), (20, 24)])
        p2 = Pairs([(3, 10), (4, 9), (5, 8), (20, 24)])
        self.assertEqual(compare_pairs(p1, p2), 1)

        #all different
        p1 = Pairs([(3, 10), (4, 9), (5, 8), (20, 24)])
        p2 = Pairs([(1, 2), (3, 4), (5, 6)])
        self.assertEqual(compare_pairs(p1, p2), 0)

        #one empty
        p1 = Pairs([(3, 10), (4, 9), (5, 8), (20, 24)])
        p2 = Pairs([])
        self.assertEqual(compare_pairs(p1, p2), 0)

        #partially different
        p1 = Pairs([(1, 2), (3, 4), (5, 6), (7, 8)])
        p2 = Pairs([(1, 2), (3, 4), (9, 10), (11, 12)])
        self.assertFloatEqual(compare_pairs(p1, p2), .33333333333333333)

        #partially different
        p1 = Pairs([(1, 2), (3, 4), (5, 6)])
        p2 = Pairs([(1, 2), (3, 4), (9, 10)])
        self.assertFloatEqual(compare_pairs(p1, p2), .5)
예제 #2
0
    def test_compare_pairs(self):
        """compare_pairs: should work on simple case"""
        #all the same
        p1 = Pairs([(3,10),(4,9),(5,8),(20,24)])
        p2 = Pairs([(3,10),(4,9),(5,8),(20,24)])
        self.assertEqual(compare_pairs(p1,p2),1)
        
        #all different
        p1 = Pairs([(3,10),(4,9),(5,8),(20,24)])
        p2 = Pairs([(1,2),(3,4),(5,6)])
        self.assertEqual(compare_pairs(p1,p2),0)

        #one empty
        p1 = Pairs([(3,10),(4,9),(5,8),(20,24)])
        p2 = Pairs([])
        self.assertEqual(compare_pairs(p1,p2),0)

        #partially different
        p1 = Pairs([(1,2),(3,4),(5,6),(7,8)])
        p2 = Pairs([(1,2),(3,4),(9,10),(11,12)])
        self.assertFloatEqual(compare_pairs(p1,p2),.33333333333333333)

        #partially different
        p1 = Pairs([(1,2),(3,4),(5,6)])
        p2 = Pairs([(1,2),(3,4),(9,10)])
        self.assertFloatEqual(compare_pairs(p1,p2),.5)
예제 #3
0
    def test_compare_pairs_weird(self):
        """compare_pairs: should handle conflicts, duplicates, pseudo, None
        """
        #Should raise error on conflict
        p1 = Pairs([(1, 2), (3, 4), (5, 6), (2, None), (4, 3), (None, None)])
        p2 = Pairs([(1, 2), (3, 4), (9, 10)])
        self.assertRaises(ValueError, compare_pairs, p1, p2)

        p1 = Pairs([(1, 2), (3, 4), (5, 6), (4, 3), (None, None), (10, None)])
        p2 = Pairs([(1, 2), (3, 4), (9, 10)])
        self.assertFloatEqual(compare_pairs(p1, p2), .5)

        p1 = Pairs([(1, 8), (2, 10), (7, 3)])
        p2 = Pairs([(1, 8), (10, 2), (3, 7), (4, 6)])
        self.assertFloatEqual(compare_pairs(p1, p2), 0.75)
예제 #4
0
    def test_compare_pairs_weird(self):
        """compare_pairs: should handle conflicts, duplicates, pseudo, None
        """
        #Should raise error on conflict
        p1 = Pairs([(1,2),(3,4),(5,6),(2,None),(4,3),(None,None)])
        p2 = Pairs([(1,2),(3,4),(9,10)])
        self.assertRaises(ValueError, compare_pairs, p1, p2)

        p1 = Pairs([(1,2),(3,4),(5,6),(4,3),(None,None),(10,None)])
        p2 = Pairs([(1,2),(3,4),(9,10)])
        self.assertFloatEqual(compare_pairs(p1,p2),.5)

        p1 = Pairs([(1,8),(2,10),(7,3)])
        p2 = Pairs([(1,8),(10,2),(3,7),(4,6)])
        self.assertFloatEqual(compare_pairs(p1,p2), 0.75)
예제 #5
0
 def test_compare_pairs_both_empty(self):
     """compare_pairs: should return 1.0 when both lists are empty
     """
     p1 = Pairs([])
     p2 = Pairs([])
     self.assertEqual(compare_pairs(p1, p2), 1)
예제 #6
0
 def test_compare_pairs_both_empty(self):
     """compare_pairs: should return 1.0 when both lists are empty
     """
     p1 = Pairs([])
     p2 = Pairs([])
     self.assertEqual(compare_pairs(p1,p2),1)