예제 #1
0
def test_union_iterable_multiple():
    s = UintSet([1, 3, 5])
    it1 = [2, 4, 6]
    it2 = {10, 11, 12}
    want = UintSet({1, 2, 3, 4, 5, 6, 10, 11, 12})
    got = s.union(it1, it2)
    assert got == want
예제 #2
0
def test_repr_empty():
    s = UintSet()
    assert repr(s) == 'UintSet()'
예제 #3
0
def test_iter():
    s = UintSet([1, 5, 0, 3, 2, 4])
    assert list(s) == [0, 1, 2, 3, 4, 5]
예제 #4
0
def test_len():
    s = UintSet()
    assert len(s) == 0
예제 #5
0
def test_new_from_empty_iterable():
    s = UintSet([])
    assert len(s) == 0
예제 #6
0
def test_new_from_iterable():
    s = UintSet([1, 100, 3])  # beyond word 0
    assert len(s) == 3
    assert 1 in s
    assert 3 in s
    assert 100 in s
예제 #7
0
def test_contains_zero():
    s = UintSet()
    s.add(0)
    assert 0 in s
예제 #8
0

def test_len():
    assert len(Empty) == 0


def test_contains():
    assert 0 not in Empty
    assert 1 not in Empty
    assert -1 not in Empty
    assert 42 not in Empty
    assert sys.maxsize not in Empty


union_cases = [
    (Empty, UintSet(), UintSet()),
    (Empty, UintSet([1]), UintSet([1])),
    (UintSet([1]), Empty, UintSet([1])),
    (UintSet([1, 100]), Empty, UintSet([1, 100])),
]


@pytest.mark.parametrize("first, second, want", union_cases)
def test_or_op(first, second, want):
    got = first | second
    assert got == want


intersection_cases = [
    (Empty, UintSet()),
    (Empty, UintSet([1])),
예제 #9
0
def test_add_negative():
    s = UintSet()
    with pytest.raises(ValueError) as e:
        s.add(-1)
    assert e.value.args[0] == INVALID_ELEMENT_MSG 
예제 #10
0
def test_not_number():
    s = UintSet()
    with pytest.raises(TypeError) as e:
        s.add('A')
    assert e.value.args[0] == INVALID_ELEMENT_MSG  
예제 #11
0
def test_add_multiple():
    s = UintSet()
    s.add(1)
    s.add(3)
    s.add(1)
    assert len(s) == 2
예제 #12
0
def test_union_not_iterable():
    first = UintSet()
    with pytest.raises(TypeError) as e:
        first.union(1)
    assert e.value.args[0] == INVALID_ITER_ARG_MSG  
예제 #13
0
def test_add():
    s = UintSet()
    s.add(0)
    assert len(s) == 1
예제 #14
0
    s = UintSet([1, 5, 0, 3, 2, 4])
    assert list(s) == [0, 1, 2, 3, 4, 5]


def test_repr_empty():
    s = UintSet()
    assert repr(s) == 'UintSet()'


def test_repr():
    s = UintSet([1, 5, 0, 3, 2, 4])
    assert repr(s) == 'UintSet({0, 1, 2, 3, 4, 5})'


@pytest.mark.parametrize("first, second, want", [
    (UintSet(), UintSet(), True),
    (UintSet([1]), UintSet(), False),
    (UintSet(), UintSet([1]), False),
    (UintSet([1, 100]), UintSet([1, 101]), False),
    (UintSet([1, 100]), [1, 101], False),
])
def test_eq(first, second, want):
    assert (first == second) is want


union_cases = [
        (UintSet(), UintSet(), UintSet()),
        (UintSet([1]), UintSet(), UintSet([1])),
        (UintSet(), UintSet([1]), UintSet([1])),
        (UintSet([1, 100]), UintSet([100, 1]), UintSet([100, 1])), # beyond word 0
        (UintSet([1, 100]), UintSet([2]), UintSet([1, 2, 100])),
예제 #15
0
def test_repr():
    s = UintSet([1, 5, 0, 3, 2, 4])
    assert repr(s) == 'UintSet({0, 1, 2, 3, 4, 5})'
예제 #16
0
def test_contains_zero_not():
    s = UintSet()
    assert 0 not in s
예제 #17
0

def test_len():
    assert len(N) == sys.maxsize


def test_contains():
    assert 0 in N
    assert 1 in N
    assert -1 not in N
    assert 42 in N
    assert sys.maxsize in N


union_cases = [
    (N, UintSet()),
    (N, UintSet([1])),
    (UintSet([1]), N),
    (UintSet([1, 100]), N),
]


@pytest.mark.parametrize("first, second", union_cases)
def test_or_op(first, second):
    got = first | second
    assert got == N


intersection_cases = [
    (N, UintSet(), UintSet()),
    (N, UintSet([1]), UintSet([1])),
예제 #18
0
# In[1]:

from uintset import UintSet


def dump(u):
    top = '┌' + '─┬' * len(bin(u._bits)[3:]) + '─┐'
    bits = '│' + '│'.join(list(bin(u._bits)[2:])) + '│'
    bottom = '└' + '─┴' * len(bin(u._bits)[3:]) + '─┘'
    #print(f'{u} → {u._bits}\n{bits:>64}\n{bottom:>64}')
    print(f'{u} → {u._bits}\n{bin(u._bits)[2:]}')


# In[2]:

empty = UintSet()
dump(empty)

# In[3]:

zero = UintSet([0])
dump(zero)

# In[4]:

one = UintSet([1])
dump(one)

# In[5]:

# In[6]: