def test_size_binary_OC():
    # 6 = 0b00000110 -> 0b11111001
    size_binary = SizeBinary(8, 6)
    assert size_binary.oc() == SizeBinary(8, '11111001')

    # 7 = 0b00000111 -> 0b11111000
    size_binary = SizeBinary(8, 7)
    assert size_binary.oc() == SizeBinary(8, '11111000')
    
    # 15 = 0b00001111 -> 0b11110000
    size_binary = SizeBinary(8, 15)
    assert size_binary.oc() == SizeBinary(8, '11110000')

    # 15 = 0b0000000000001111 -> 0b1111111111110000
    size_binary = SizeBinary(16, 15)
    assert size_binary.oc() == SizeBinary(16, '1111111111110000')
Пример #2
0
def test_size_binary_init_int():
    size_binary = SizeBinary(8, 6)
    assert int(size_binary) == 6
Пример #3
0
def test_size_binary_init_intseq():
    size_binary = SizeBinary(8, [1, 1, 0])
    assert int(size_binary) == 6
Пример #4
0
def test_size_binary_init_binstr():
    size_binary = SizeBinary(8, '0b110')
    assert int(size_binary) == 6
Пример #5
0
def test_binary_shr_pos():
    assert SizeBinary(4, '1101') >> 5 == SizeBinary(4, '0')
Пример #6
0
def test_binary_shl_pos_drop():
    assert SizeBinary(4, '1101') << 4 == SizeBinary(4, '0000')
Пример #7
0
def test_binary_shl():
    assert SizeBinary(4, '1101') << 1 == SizeBinary(4, '1010')
def test_size_binary_set_overflow():
    size_binary = SizeBinary(8, 0)
    size_binary.set(512)
    assert str(size_binary) == '00000000'
    assert size_binary.overflow == True
Пример #9
0
def test_binary_division_rem_binary():
    assert SizeBinary(8, 21) / SizeBinary(8, 5) == SizeBinary(8, 4)
Пример #10
0
def test_binary_division_rem_int():
    assert SizeBinary(8, 21) / 4 == SizeBinary(8, 5)
Пример #11
0
def test_binary_multiplication_binary_different_size():
    assert SizeBinary(8, 5) * SizeBinary(16, 6) == SizeBinary(16, 30)
def test_size_binary_split_asymmetric():
    size_binary8 = SizeBinary(8, '01010110')
    size_binary9u, size_binary3l = size_binary8.split(9, 3)
    assert (size_binary9u, size_binary3l) == (SizeBinary(9, '000001010'), SizeBinary(3, '110'))
def test_size_binary_split():
    size_binary8 = SizeBinary(8, '01010110')
    size_binary4u, size_binary4l = size_binary8.split(4, 4)
    assert (size_binary4u, size_binary4l) == (SizeBinary(4, '0101'), SizeBinary(4, '0110'))
def test_size_binary_to_binary():
    register8 = SizeBinary(8, 126)
    assert register8.to_binary() == Binary('1111110')
Пример #15
0
def test_binary_equality_checks_bits():
    assert SizeBinary(8, 1) != SizeBinary(16, 1)
Пример #16
0
def test_binary_division_rem_binary_different_size():
    assert SizeBinary(8, 21) / SizeBinary(16, 5) == SizeBinary(16, 4)
Пример #17
0
def test_size_binary_bin():
    register8 = SizeBinary(8, 126)
    assert bin(register8) == '0b1111110'
Пример #18
0
def test_binary_get_bit():
    size_binary = SizeBinary(8, '01110001')
    assert size_binary[0] == '1'
    assert size_binary[5] == '1'
Пример #19
0
def test_binary_xor():
    assert SizeBinary(4, '1101') ^ SizeBinary(4, '1') == SizeBinary(4, '1100')
Пример #20
0
def test_binary_negative_index():
    size_binary = SizeBinary(8, '01110001')
    assert size_binary[-1] == '0'
    assert size_binary[-2] == '1'
Пример #21
0
def test_binary_shl_pos():
    assert SizeBinary(8, '1101') << 5 == SizeBinary(8, '10100000')
Пример #22
0
def test_binary_illegal_index():
    with pytest.raises(IndexError):
        SizeBinary(8, '01101010')[8]
Пример #23
0
def test_binary_shr():
    assert SizeBinary(4, '1101') >> 1 == SizeBinary(4, '110')
Пример #24
0
def test_binary_inappropriate_type_index():
    with pytest.raises(TypeError):
        SizeBinary(8, '01101010')['key']
Пример #25
0
def test_binary_slice():
    assert SizeBinary(8, '01101010')[0:3] == SizeBinary(2, '10')
    assert SizeBinary(8, '01101010')[1:4] == SizeBinary(3, '101')
    assert SizeBinary(8, '01101010')[4:] == SizeBinary(3, '110')
Пример #26
0
def test_size_binary_set_overflow():
    size_binary = SizeBinary(8, 0)
    size_binary.set(512)
    assert str(size_binary) == '00000000'
    assert size_binary.overflow == True
Пример #27
0
def test_size_binary_init_hexstr():
    size_binary = SizeBinary(8, '0x6')
    assert int(size_binary) == 6
Пример #28
0
def test_binary_for_loop():
    assert [int(i)
            for i in SizeBinary(8, '01101010')] == [0, 1, 0, 1, 0, 1, 1, 0]
Пример #29
0
def test_size_binary_init_strseq():
    size_binary = SizeBinary(8, ['1', '1', '0'])
    assert int(size_binary) == 6
Пример #30
0
def test_binary_not():
    assert ~SizeBinary(4, '1101') == SizeBinary(4, '0010')
Пример #31
0
def test_binary_equality_checks_value():
    assert SizeBinary(8, 1) != SizeBinary(8, 2)
Пример #32
0
def test_binary_and():
    assert SizeBinary(4, '1101') & SizeBinary(4, '1') == SizeBinary(4, '1')
Пример #33
0
def test_size_binary_eq():
    assert SizeBinary(8, 6) == SizeBinary(8, 6)
Пример #34
0
def test_binary_or():
    assert SizeBinary(4, '1101') | SizeBinary(4, '1') == SizeBinary(4, '1101')
Пример #35
0
def test_size_binary_str():
    register8 = SizeBinary(8, 126)
    assert str(register8) == '01111110'
def test_size_binary_set():
    size_binary = SizeBinary(8, 0)
    size_binary.set(22)
    assert str(size_binary) == '00010110'
    assert size_binary.overflow == False