[test] adding testcases for get method of buffer
This commit is contained in:
parent
ff84d63fe1
commit
e3ed2fcc75
@ -1,18 +1,19 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
from IPython import embed
|
||||
|
||||
from usbdaq import RingBuffer
|
||||
from pyrelacs.dataio.circbuffer import CircBuffer
|
||||
|
||||
|
||||
def test_init():
|
||||
buff = RingBuffer(1000, 2)
|
||||
buff = CircBuffer(1000, 2)
|
||||
|
||||
assert buff.size == 1000
|
||||
assert buff.channel_count == 2
|
||||
|
||||
|
||||
def test_hasvalue():
|
||||
buff = RingBuffer(1000, 2)
|
||||
buff = CircBuffer(1000, 2)
|
||||
|
||||
assert buff.has_value(0, 0) == False
|
||||
assert buff.has_value(-1, 0) == False
|
||||
@ -39,18 +40,59 @@ def test_hasvalue():
|
||||
|
||||
|
||||
def test_validrange():
|
||||
pass
|
||||
buff = CircBuffer(1000, 2)
|
||||
|
||||
# without any values the range is (0, 0)
|
||||
assert buff.valid_range() == (0, 0)
|
||||
|
||||
def test_write():
|
||||
buff = RingBuffer(1000, 2)
|
||||
buff.append(0, 0)
|
||||
assert buff.valid_range() == (0, 1)
|
||||
|
||||
samplecount = 1000
|
||||
for i in range(100):
|
||||
buff.append(i, 0)
|
||||
|
||||
assert buff.valid_range() == (0, 101)
|
||||
|
||||
for i in range(1000):
|
||||
buff.append(i, 0)
|
||||
|
||||
assert buff.valid_range() == (0, 1000)
|
||||
|
||||
|
||||
def test_get():
|
||||
pass
|
||||
buff = CircBuffer(1000, 2)
|
||||
|
||||
# with no items written to the buffer
|
||||
with pytest.raises(IndexError):
|
||||
item = buff.get(index=-1)
|
||||
|
||||
buff.append(10, 0)
|
||||
item = buff.get(index=-1)
|
||||
assert item == 10
|
||||
|
||||
# Check if index is not written jet
|
||||
with pytest.raises(IndexError):
|
||||
item = buff.get(index=10)
|
||||
|
||||
for i in range(1000):
|
||||
buff.append(i, 0)
|
||||
item = buff.get(index=-1)
|
||||
# the first item should be 999.0 because of we append a value in the earlier test
|
||||
assert item == 999.0
|
||||
|
||||
with pytest.raises(IndexError):
|
||||
item = buff.get(10001)
|
||||
|
||||
|
||||
def test_read():
|
||||
pass
|
||||
|
||||
|
||||
def test_write():
|
||||
buff = CircBuffer(1000, 2)
|
||||
|
||||
samplecount = 1000
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_get()
|
||||
|
Loading…
Reference in New Issue
Block a user