Example #1
0
def test_popcnt_all_ones(num_bytes):
    data = bitarray("1" * 8 * num_bytes)
    carr = array.array('b', data.tobytes())
    output_counts = _dice.popcount_arrays(carr, 8)
    assert output_counts[0] == 64
    assert output_counts[-1] == 64
    assert sum(output_counts) == 8 * num_bytes
Example #2
0
def test_data_length_not_multiple_of_64():
    # 32 bits of data, array_size of 8 bits (1 byte)
    data = bitarray("10101010" * 4)
    carr = array.array('b', data.tobytes())
    output_counts = _dice.popcount_arrays(carr, 1)
    assert len(output_counts) == 4
    assert sum(output_counts) == data.count()
Example #3
0
def test_data_not_multiple_of_element_size(num_bytes):
    data = bitarray("10101010" * num_bytes)
    carr = array.array('b', data.tobytes())
    # Use an element size of 8 bytes
    with pytest.raises(AssertionError):
        output_counts = _dice.popcount_arrays(carr, 8)
        assert output_counts[0] == data[:64].count()
        assert sum(output_counts) == data.count()
Example #4
0
def test_popcnt_large(num_bytes):
    data = bitarray("10101010" * num_bytes)
    carr = array.array('b', data.tobytes())
    # Use an element size of 1024 bytes
    output_counts = _dice.popcount_arrays(carr, 1024)
    assert output_counts[0] == data[:1024*8].count()
    assert output_counts[-1] == data[-1024*8:].count()
    assert sum(output_counts) == data.count()

    for array_size in [8, 4096, 8192]:
        if array_size < num_bytes:
            assert sum(_dice.popcount_arrays(carr, array_size)) == data.count()
Example #5
0
def test_popcnt_all_zeros(num_bytes):
    data = bitarray("0" * 8 * num_bytes)
    carr = array.array('b', data.tobytes())
    output_counts = _dice.popcount_arrays(carr, 8)
    assert sum(output_counts) == 0