示例#1
0
 def setUp(self): self.clusterer = ItemsClusterer()
 def test_addNewCluster(self):
示例#2
0
class ItemsClustererTests(unittest.TestCase):
    def setUp(self): self.clusterer = ItemsClusterer()
    def test_addNewCluster(self):
        items = set([1,2,3])
        self.clusterer.add(items)
        self.assertEqual([items], [cluster for cluster in self.clusterer.iterateClusters()])
        self.assertEqual(1, len(set([self.clusterer.itemToClusterMap[i] for i in items])))
    def test_addItemsToExistingCluster(self):
        items = set([1,2,3])
        newItems = set([1,4,5])
        self.clusterer.add(items)
        self.clusterer.add(newItems)
        self.assertEqual([items.union(newItems)], [cluster for cluster in self.clusterer.iterateClusters()])
        self.assertEqual(1, len(set([self.clusterer.itemToClusterMap[i] for i in items.union(newItems)])))
    def test_addItemsWithMultiplePossibleClusters(self):
        items1 = set([1,2,3])
        items2 = set([6,4,5])
        items3 = set([7, 1, 6])
        self.clusterer.add(items1), self.clusterer.add(items2), self.clusterer.add(items3)
        self.assertEqual(1, len(list(self.clusterer.iterateClusters())))
        self.assertEqual(7, len(list(self.clusterer.iterateClusters())[0]))
        self.assertEqual(7, len(self.clusterer.itemToClusterMap))
        self.assertEqual(1, len(set([self.clusterer.itemToClusterMap[i] for i in items1.union(items2).union(items3)])))