示例#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)