Skip to content

Commit

Permalink
Merge branch 'iblrigv8dev' of https://github.com/int-brain-lab/iblrig
Browse files Browse the repository at this point in the history
…into iblrigv8dev
  • Loading branch information
bimac committed Sep 23, 2024
2 parents 84c77d6 + d7e21f8 commit 7cba05e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions iblrig/test/test_valve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest
from datetime import date

import numpy as np
from pydantic import ValidationError

from iblrig.pydantic_definitions import HardwareSettingsValve
from iblrig.valve import Valve


class TestValve(unittest.TestCase):
def test_valve(self):
range_t = range(50, 201, 50)
range_v = range(4, 21, 5)
assert len(range_t) == len(range_v)

settings = HardwareSettingsValve(
WATER_CALIBRATION_DATE=date.today(),
WATER_CALIBRATION_RANGE=[min(range_t), max(range_t)],
WATER_CALIBRATION_N=len(range_t),
WATER_CALIBRATION_OPEN_TIMES=[t for t in range_t],
WATER_CALIBRATION_WEIGHT_PERDROP=[v for v in range_v],
FREE_REWARD_VOLUME_UL=1.5,
)
valve = Valve(settings)

t = np.arange(range_t[0], range_t[-1], 25)
v = np.arange(range_v[0], range_v[-1], 2.5)
for i in range(0, len(t)):
self.assertAlmostEqual(valve.values.ms2ul(t[i]), v[i], places=3)
self.assertAlmostEqual(valve.values.ul2ms(v[i]), t[i], places=3)
assert np.allclose(valve.values.ms2ul(t), v)
assert np.allclose(valve.values.ul2ms(v), t)
assert valve.values.ul2ms(0) == 0.0
assert valve.values.ms2ul(0) == 0.0
assert valve.values.ms2ul(5) == 0.0
with self.assertRaises(ValidationError):
valve.values.ms2ul(-1)
with self.assertRaises(ValidationError):
valve.values.ms2ul([-1, 1])
with self.assertRaises(ValidationError):
valve.values.ul2ms(-1)
with self.assertRaises(ValidationError):
valve.values.ul2ms([-2, 1])

0 comments on commit 7cba05e

Please sign in to comment.