Exemplo n.º 1
0
    def testDiscard(self):
        ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
        for item in ["apple", "acacia", "banana", "cheese"]:
            ks.discard(item)
        self.assertEqual(ks, set(["avocado"]))

        # Proper key sets
        self.assertEqual(ks.keys(), ['a'])
        self.assertEqual(ks.subset_by_key("a"), set(["avocado"]))
        self.assertEqual(ks.subset_by_key("b"), set())
        self.assertEqual(ks.subset_by_key("c"), set())
Exemplo n.º 2
0
    def testDiscard(self):
        ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
        for item in ["apple", "acacia", "banana", "cheese"]:
            ks.discard(item)
        self.assertEqual(ks, set(["avocado"]))

        # Proper key sets
        self.assertEqual(ks.keys(), ["a"])
        self.assertEqual(ks.subset_by_key("a"), set(["avocado"]))
        self.assertEqual(ks.subset_by_key("b"), set())
        self.assertEqual(ks.subset_by_key("c"), set())
Exemplo n.º 3
0
    def testAdd(self):
        ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
        for item in ["apple", "acacia", "cheese"]:
            ks.add(item)
        self.assertEqual(
            ks, set(["apple", "avocado", "banana", "acacia", "cheese"]))

        # Proper key sets
        self.assertEqual(sorted(ks.keys()), ['a', 'b', 'c'])
        self.assertEqual(ks.subset_by_key("a"),
                         set(["apple", "avocado", "acacia"]))
        self.assertEqual(ks.subset_by_key("b"), set(["banana"]))
        self.assertEqual(ks.subset_by_key("c"), set(["cheese"]))
        self.assertEqual(ks.subset_by_key("d"), set())
Exemplo n.º 4
0
 def testPop(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     popped = []
     while ks:
         popped.append(ks.pop())
     self.assertEqual(sorted(popped), ["apple", "avocado", "banana"])
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks.subset_by_key("b"), set())
Exemplo n.º 5
0
 def testPop(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     popped = []
     while ks:
         popped.append(ks.pop())
     self.assertEqual(sorted(popped), ["apple", "avocado", "banana"])
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks.subset_by_key("b"), set())
Exemplo n.º 6
0
 def testClear(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     self.assertFalse(not ks)
     self.assertEqual(len(ks), 3)
     ks.clear()
     self.assertEqual(len(ks), 0)
     self.assertTrue(not ks)
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks.subset_by_key("b"), set())
Exemplo n.º 7
0
 def testClear(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     self.assertFalse(not ks)
     self.assertEqual(len(ks), 3)
     ks.clear()
     self.assertEqual(len(ks), 0)
     self.assertTrue(not ks)
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks.subset_by_key("b"), set())
Exemplo n.º 8
0
    def testRemove(self):
        ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
        for item in ["apple", "banana"]:
            ks.remove(item)
        for item in ["acacia", "cheese"]:
            try:
                ks.remove(item)
            except KeyError:
                self.assertTrue(True)
            except:
                self.assertTrue(False)
            else:
                self.assertTrue(False)
        self.assertEqual(ks, set(["avocado"]))

        # Proper key sets
        self.assertEqual(ks.keys(), ["a"])
        self.assertEqual(ks.subset_by_key("a"), set(["avocado"]))
        self.assertEqual(ks.subset_by_key("b"), set())
        self.assertEqual(ks.subset_by_key("c"), set())
Exemplo n.º 9
0
    def testRemove(self):
        ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
        for item in ["apple", "banana"]:
            ks.remove(item)
        for item in ["acacia", "cheese"]:
            try:
                ks.remove(item)
            except KeyError:
                self.assertTrue(True)
            except:
                self.assertTrue(False)
            else:
                self.assertTrue(False)
        self.assertEqual(ks, set(["avocado"]))

        # Proper key sets
        self.assertEqual(ks.keys(), ['a'])
        self.assertEqual(ks.subset_by_key("a"), set(["avocado"]))
        self.assertEqual(ks.subset_by_key("b"), set())
        self.assertEqual(ks.subset_by_key("c"), set())
Exemplo n.º 10
0
 def testDiscardByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     discarded = ks.discard_by_key("a")
     self.assertEqual(discarded, set(["apple", "avocado"]))
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks, set(["banana"]))
     self.assertEqual(ks.discard_by_key("b"), set(["banana"]))
     self.assertTrue(not ks)
     try:
         self.assertEqual(ks.discard_by_key("a"), set())
     except:
         self.assertTrue(False)
Exemplo n.º 11
0
 def testDiscardByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     discarded = ks.discard_by_key('a')
     self.assertEqual(discarded, set(['apple', 'avocado']))
     self.assertEqual(ks.subset_by_key('a'), set())
     self.assertEqual(ks, set(['banana']))
     self.assertEqual(ks.discard_by_key('b'), set(['banana']))
     self.assertTrue(not ks)
     try:
         self.assertEqual(ks.discard_by_key('a'), set())
     except:
         self.assertTrue(False)
Exemplo n.º 12
0
 def testPopByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     popped = []
     popped.append(ks.pop_by_key("a"))
     popped.append(ks.pop_by_key("a"))
     self.assertEqual(sorted(popped), ["apple", "avocado"])
     self.assertEqual(ks.subset_by_key("a"), set())
     self.assertEqual(ks, set(["banana"]))
     self.assertEqual(ks.pop_by_key("b"), "banana")
     self.assertTrue(not ks)
     try:
         ks.pop_by_key("a")
     except KeyError:
         self.assertTrue(True)
     except:
         self.assertTrue(False)
     else:
         self.assertTrue(False)
Exemplo n.º 13
0
 def testPopByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     popped = []
     popped.append(ks.pop_by_key('a'))
     popped.append(ks.pop_by_key('a'))
     self.assertEqual(sorted(popped), ['apple', 'avocado'])
     self.assertEqual(ks.subset_by_key('a'), set())
     self.assertEqual(ks, set(['banana']))
     self.assertEqual(ks.pop_by_key('b'), 'banana')
     self.assertTrue(not ks)
     try:
         ks.pop_by_key('a')
     except KeyError:
         self.assertTrue(True)
     except:
         self.assertTrue(False)
     else:
         self.assertTrue(False)
Exemplo n.º 14
0
 def testSubsetByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     self.assertEqual(ks.subset_by_key("a"), set(["apple", "avocado"]))
     self.assertEqual(ks.subset_by_key("b"), set(["banana"]))
     self.assertEqual(ks.subset_by_key("c"), set())
Exemplo n.º 15
0
 def testSubsetByKey(self):
     ks = KeyedSet(firstLetter, ["apple", "avocado", "banana"])
     self.assertEqual(ks.subset_by_key('a'), set(['apple', 'avocado']))
     self.assertEqual(ks.subset_by_key('b'), set(['banana']))
     self.assertEqual(ks.subset_by_key('c'), set())