コード例 #1
0
def test_add_array_errors():
    with pytest.raises(TypeError):
        add_array()
    with pytest.raises(TypeError):
        add_array(100)
    with pytest.raises(TypeError):
        add_array(None, None, 0, 0)
    src_array = (c_uint16 * ARRAY_SIZE)()
    # negative length
    with pytest.raises(ValueError):
        add_array(addressof(src_array), addressof(src_array), -1, sizeof(c_uint16))
    # invalid word size
    with pytest.raises(ValueError):
        add_array(addressof(src_array), addressof(src_array), 0, 0)
コード例 #2
0
def check_add_array(int_type):
    src_array = (int_type * ARRAY_SIZE)()
    dst_array = (int_type * ARRAY_SIZE)()
    expect_added = 0
    for index in range(ARRAY_SIZE):
        src_array[index] = index
        expect_added += index
    added = add_array(addressof(dst_array), addressof(src_array), ARRAY_SIZE, sizeof(int_type))
    assert(added == expect_added)
    for index in range(ARRAY_SIZE):
        assert(dst_array[index] == index)
    # overflow
    src_array[0] = -1
    dst_array[0] = -1
    with pytest.raises(OverflowError):
        add_array(addressof(dst_array), addressof(src_array), ARRAY_SIZE, sizeof(int_type))
コード例 #3
0
ファイル: codec.py プロジェクト: yawnson/HdrHistogram_py
 def add(self, other_encoder):
     add_array(addressof(self.get_counts()),
               addressof(other_encoder.get_counts()),
               self.histogram.counts_len,
               self.histogram.word_size)