Example #1
0
 def inplace_update(self):
     old = s = OrderedSet()
     with Assert.raises(TypeError):
         s |= 'abc'
     s |= OrderedSet('abc')
     Assert(s) == OrderedSet('abc')
     Assert(s).is_(old)
Example #2
0
 def symmetric_difference_update(self):
     old = s = OrderedSet('abc')
     s ^= OrderedSet('def')
     Assert(s) == OrderedSet('abcdef')
     Assert(s).is_(old)
     with Assert.raises(TypeError):
         s ^= 'ghi'
Example #3
0
 def intersection_update(self):
     old = s = OrderedSet('abc')
     with Assert.raises(TypeError):
         s &= 'ab'
     s &= OrderedSet('ab')
     Assert(s) == OrderedSet('ab')
     Assert(s).is_(old)
Example #4
0
 def equality(self):
     a = OrderedSet([1, 2, 3])
     b = OrderedSet([3, 2, 1])
     Assert(a) == a
     Assert(a) == set(b)
     Assert(b) == b
     Assert(b) == set(a)
     Assert(a) != b
Example #5
0
    def difference_update(self):
        s = OrderedSet('abcd')
        s -= s
        Assert(s) == OrderedSet()

        old = s = OrderedSet('abcd')
        s -= OrderedSet('abc')
        with Assert.raises(TypeError):
            s -= 'abc'
        Assert(s) == OrderedSet('d')
        Assert(s).is_(old)
Example #6
0
 def pop(self):
     s = OrderedSet()
     with Assert.raises(KeyError):
         s.pop()
     s = OrderedSet([1, 2, 3])
     Assert(s.pop()) == 3
     Assert(s.pop(last=False)) == 1
Example #7
0
 def difference(self):
     a = OrderedSet('abc')
     Assert(a.difference('abc')) == OrderedSet()
     Assert(a.difference('a', 'b', 'c')) == OrderedSet()
     Assert(a - OrderedSet('ab')) == OrderedSet('c')
     with Assert.raises(TypeError):
         a - 'abc'
Example #8
0
def normalize_words(ws):
    return list(
        OrderedSet(
            map(
                normalize_word,
                filter(lambda s: re.match('\w', s, flags=re.UNICODE),
                       re.split('\W', ws, flags=re.UNICODE)))))
Example #9
0
 def union(self):
     a = OrderedSet('abc')
     b = OrderedSet('def')
     Assert(a.union('def', 'ghi')) == OrderedSet('abcdefghi')
     Assert(a | b) == OrderedSet('abcdef')
     with Assert.raises(TypeError):
         a | 'abc'
Example #10
0
 def repr(self):
     Assert(repr(OrderedSet())) == 'OrderedSet()'
     s = OrderedSet([1, 2, 3])
     Assert(repr(s)) == 'OrderedSet([1, 2, 3])'
Example #11
0
    def symmetric_difference(self):
        for a, b in [('abc', 'def'), ('def', 'abc')]:
            OrderedSet(a).symmetric_difference(b) == OrderedSet(a + b)
            OrderedSet(a) ^ OrderedSet(b) == OrderedSet(a + b)

            OrderedSet(a).symmetric_difference(a + b) == OrderedSet(b)
            OrderedSet(a) ^ OrderedSet(a + b) == OrderedSet(b)

        with Assert.raises(TypeError):
            OrderedSet('abc') ^ 'def'
Example #12
0
    def issub_super_set(self):
        a = OrderedSet('abc')
        b = OrderedSet('abcdef')

        a.issubset(a)
        a.issuperset(a)
        a.issubset(a)
        a.issuperset(a)

        assert a <= a
        assert a >= a

        assert a <= b
        assert b >= a

        assert not (a < a)
        assert not (a > a)

        assert a < b
        assert not (a > b)
Example #13
0
 def update(self):
     s = OrderedSet()
     s.update('abc')
     Assert(s) == OrderedSet('abc')
Example #14
0
 def copy(self):
     s = OrderedSet('abc')
     Assert(s.copy()) == s
     Assert(s.copy()).is_not(s)
Example #15
0
 def iteration(self):
     s = OrderedSet([1, 2, 3])
     Assert(list(s)) == [1, 2, 3]
     Assert(list(reversed(s))) == [3, 2, 1]
Example #16
0
 def clear(self):
     s = OrderedSet([1, 2, 3])
     s.clear()
     assert not s
Example #17
0
 def remove(self):
     s = OrderedSet()
     with Assert.raises(KeyError):
         s.remove(1)
     s.add(1)
     s.remove(1)
Example #18
0
 def discard(self):
     s = OrderedSet()
     s.discard(1)
     s.add(1)
     s.discard(1)
     Assert(1).not_in(s)
Example #19
0
 def add(self):
     s = OrderedSet()
     s.add(1)
     Assert(1).in_(s)
Example #20
0
 def contains(self):
     s = OrderedSet([1, 2, 3])
     for element in s:
         Assert(element).in_(s)
     Assert(4).not_in(s)
Example #21
0
 def intersection(self):
     a = OrderedSet('abc')
     Assert(a.intersection('ab', 'a')) == OrderedSet('a')
     Assert(a & OrderedSet('ab')) == OrderedSet('ab')
     with Assert.raises(TypeError):
         a & 'ab'
Example #22
0
 def hashability(self):
     with Assert.raises(TypeError):
         hash(OrderedSet())
Example #23
0
 def length(self):
     Assert(len(OrderedSet([1, 2, 3]))) == 3