예제 #1
0
 def test_reversed(self):
     s = SortedFrozenSet([1, 3, 5, 7])
     r = reversed(s)
     self.assertEqual(next(r), 7)
     self.assertEqual(next(r), 5)
     self.assertEqual(next(r), 3)
     self.assertEqual(next(r), 1)
     self.assertRaises(StopIteration, lambda: next(r))
예제 #2
0
 def test_reversed(self):
     s = SortedFrozenSet([1, 3, 5, 7])
     r = reversed(s)
     assert next(r) == 7
     assert next(r) == 5
     assert next(r) == 3
     assert next(r) == 1
     with pytest.raises(StopIteration):
         next(r)
예제 #3
0
    def test_from_iterable(self):
        def gen6842():
            yield 6
            yield 8
            yield 4
            yield 2

        g = gen6842()
        s = SortedFrozenSet(g)
예제 #4
0
파일: catalog.py 프로젝트: wassname/segpy
    def __init__(self, keys, value):
        """Initialize a RegularConstantCatalog.

        The catalog is initialized by a description with an iterable series of
        keys and a constant value to be associated with all the keys.

        Args:
            keys: An iterable series of distinct keys.
            key_max: The maximum key.
            key_stride: The difference between successive keys.
            value: A value associated with all keys.
        """
        self._keys = SortedFrozenSet(keys)
        self._value = value
예제 #5
0
def make_sorted_distinct_sequence(iterable):
    """Create a sorted immutable sequence from an iterable series.

    Args:
        iterable: An iterable series of comparable values.

    Returns:
        An immutable collection which supports the Sized, Iterable,
        Container and Sequence protocols.
    """
    if isinstance(iterable, range):
        if iterable.step > 0:
            return iterable
        else:
            return reversed(iterable)
    sorted_set = SortedFrozenSet(iterable)
    if len(sorted_set) == 1:
        return single_item_range(sorted_set[0])
    stride = measure_stride(sorted_set)
    if stride is not None:
        start = sorted_set[0]
        stop = sorted_set[-1] + stride
        return range(start, stop, stride)
    return sorted_set
예제 #6
0
 def setUp(self):
     self.s = SortedFrozenSet([7, 2, 1, 1, 9])
예제 #7
0
 def test_with_duplicates(self):
     s = SortedFrozenSet([5, 5, 5])
     self.assertEqual(len(s), 1)
예제 #8
0
 def test_one(self):
     s = SortedFrozenSet([42])
     self.assertEqual(len(s), 1)
예제 #9
0
 def test_issuperset_negative(self):
     s = SortedFrozenSet({1, 2})
     t = [1, 2, 3]
     self.assertFalse(s.issuperset(t))
예제 #10
0
 def test_union(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({2, 3, 4})
     self.assertEqual(s | t, SortedFrozenSet({1, 2, 3, 4}))
예제 #11
0
 def test_isdisjoint_negative(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [3, 4, 5]
     self.assertFalse(s.isdisjoint(t))
예제 #12
0
 def test_issuperset_negative(self):
     s = SortedFrozenSet({1, 2})
     t = [1, 2, 3]
     self.assertFalse(s.issuperset(t))
예제 #13
0
 def test_count_one(self):
     s = SortedFrozenSet([1, 5, 7, 9])
     self.assertEqual(s.count(7), 1)
예제 #14
0
 def test_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.difference(t), SortedFrozenSet({1}))
예제 #15
0
 def test_symmetric_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.symmetric_difference(t), SortedFrozenSet({1, 4}))
예제 #16
0
 def test_union(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.union(t), SortedFrozenSet({1, 2, 3, 4}))
예제 #17
0
 def test_intersection(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.intersection(t), SortedFrozenSet({2, 3}))
예제 #18
0
 def test_isdisjoint_negative(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [3, 4, 5]
     self.assertFalse(s.isdisjoint(t))
예제 #19
0
 def test_isdisjoint_positive(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [4, 5, 6]
     self.assertTrue(s.isdisjoint(t))
예제 #20
0
 def test_count_zero(self):
     s = SortedFrozenSet([1, 5, 7, 9])
     self.assertEqual(s.count(11), 0)
예제 #21
0
 def test_index_negative(self):
     s = SortedFrozenSet([1, 5, 8, 9])
     self.assertRaises(ValueError, lambda: s.index(15))
예제 #22
0
 def test_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({2, 3, 4})
     self.assertEqual(s - t, SortedFrozenSet({1}))
예제 #23
0
 def test_isdisjoint_positive(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [4, 5, 6]
     self.assertTrue(s.isdisjoint(t))
예제 #24
0
 def test_union(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.union(t), SortedFrozenSet({1, 2, 3, 4}))
예제 #25
0
 def test_intersection(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({2, 3, 4})
     self.assertEqual(s & t, SortedFrozenSet({2, 3}))
예제 #26
0
 def test_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.difference(t), SortedFrozenSet({1}))
예제 #27
0
 def test_symmetric_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({2, 3, 4})
     self.assertEqual(s ^ t, SortedFrozenSet({1, 4}))
예제 #28
0
 def test_issuperset_positive(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [1, 2, 3]
     self.assertTrue(s.issuperset(t))
예제 #29
0
 def test_intersection(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.intersection(t), SortedFrozenSet({2, 3}))
예제 #30
0
 def test_identical(self):
     s = SortedFrozenSet([10, 11, 12])
     self.assertFalse(s != s)
예제 #31
0
 def test_symmetric_difference(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [2, 3, 4]
     self.assertEqual(s.symmetric_difference(t), SortedFrozenSet({1, 4}))
예제 #32
0
 def test_lt_negative(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({1, 2, 3})
     self.assertFalse(s < t)
예제 #33
0
 def test_empty(self):
     s = SortedFrozenSet()
     self.assertEqual(len(s), 0)
예제 #34
0
 def test_le_lt_positive(self):
     s = SortedFrozenSet({1, 2})
     t = SortedFrozenSet({1, 2, 3})
     self.assertTrue(s <= t)
예제 #35
0
 def test_ten(self):
     s = SortedFrozenSet(range(10))
     self.assertEqual(len(s), 10)
예제 #36
0
 def test_ge_eq_positive(self):
     s = SortedFrozenSet({1, 2, 3})
     t = SortedFrozenSet({1, 2, 3})
     self.assertTrue(s >= t)
예제 #37
0
 def test_empty(self):
     s = SortedFrozenSet()
예제 #38
0
 def test_ge_negative(self):
     s = SortedFrozenSet({1, 2})
     t = SortedFrozenSet({1, 2, 3})
     self.assertFalse(s >= t)
예제 #39
0
 def setUp(self):
     self.s = SortedFrozenSet([1, 4, 9, 13, 15])
예제 #40
0
 def test_issuperset_positive(self):
     s = SortedFrozenSet({1, 2, 3})
     t = [1, 2, 3]
     self.assertTrue(s.issuperset(t))
예제 #41
0
 def setUp(self):
     self.s = SortedFrozenSet([6, 7, 3, 9])
예제 #42
0
 def test_index_positive(self):
     s = SortedFrozenSet([1, 5, 8, 9])
     self.assertEqual(s.index(8), 2)