Skip to content

Commit

Permalink
Check on real length of binary eventrecord
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCerina committed Feb 16, 2024
1 parent e4f976e commit 81fe1fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion physio_cassette/physio_cassette.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ def __len__(self):
if not self.is_binary:
return self.data.n_measurements()
elif self.data.n_measurements()>1:
return (self.data.n_measurements()-1)//2
remainder = self.data.n_measurements() % 2 # Assess that the start/0 value may be overwritten
return (self.data.n_measurements()-remainder)//2
else:
return 0 # Assuming a binary EventRecord with only the start/0 value to be empty

Expand Down
32 changes: 32 additions & 0 deletions tests/test_eventrecord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from datetime import datetime, timedelta

import pytest

from physio_cassette.physio_cassette import EventRecord


class TestEventRecord:
@pytest.fixture
def len_binary(self):
yield 10

@pytest.fixture
def simple_binary_record(self, len_binary):
# Simple binary array
t0 = datetime.fromtimestamp(0)
input_array = [1,0]*len_binary
yield EventRecord.from_state_array('simple_binary', t0=t0, input_array=input_array, start_value=0)

@pytest.fixture
def simple_binary_nostart_record(self, len_binary):
# Binary array with start value covered by data
t0 = datetime.fromtimestamp(0)
input_array = [1,0]*len_binary
ts = [t0+timedelta(seconds=i) for i in range(len(input_array))]
yield EventRecord.from_state_array('simple_binary', t0=t0, input_array=input_array, ts_array=ts, start_value=0)

def test_length(self, simple_binary_record, simple_binary_nostart_record, len_binary):

# Binary records return correct number of events even if start value changes
assert simple_binary_record.n_events==len_binary
assert simple_binary_nostart_record.n_events==len_binary

0 comments on commit 81fe1fe

Please sign in to comment.