def test_exp(self): """ Test calculation of exponential function value for time and tissue compartment """ m = ZH_L16B_GF() v = m._exp(1, 0.6 / 5) self.assertAlmostEqual(0.88692043, v)
def test_gf_limit(self, f): """ Test deco model gradient factor limit calculation Check if appropriate parameters are passed from ZH_L16B_GF.gf_limit to eq_gf_limit function. """ f.side_effect = list(range(1, 17)) m = ZH_L16B_GF() data = Data(tuple((v, 0.1) for v in range(1, 17)), 0.3) v = m.gf_limit(0.3, data) self.assertEquals(v, tuple(range(1, 17))) self.assertEquals(m.NUM_COMPARTMENTS, f.call_count) result = tuple(t[0][0] for t in f.call_args_list) self.assertEquals(tuple([0.3]) * 16, result) result = tuple(t[0][1] for t in f.call_args_list) self.assertEquals(tuple(range(1, 17)), result) result = tuple(t[0][2] for t in f.call_args_list) self.assertEquals(tuple([0.1]) * 16, result) result = tuple(t[0][3] for t in f.call_args_list) self.assertEquals(m.N2_A, result) result = tuple(t[0][4] for t in f.call_args_list) self.assertEquals(m.N2_B, result) result = tuple(t[0][5] for t in f.call_args_list) self.assertEquals(m.HE_A, result) result = tuple(t[0][6] for t in f.call_args_list) self.assertEquals(m.HE_B, result)
def test_model_init(self): """ Test deco model initialization """ m = ZH_L16B_GF() data = m.init(1.013) tissues = data.tissues self.assertEquals(m.NUM_COMPARTMENTS, len(tissues)) expected = tuple([(0.75092706, 0.0)] * m.NUM_COMPARTMENTS) self.assertEquals(expected, tissues)
def test_ceiling_limit_gf(self, f): """ Test calculation of pressure limit (with gf) """ m = ZH_L16B_GF() data = Data( ((1.5, 0.0), (2.5, 0.), (2.0, 0.0), (2.9, 0.0), (2.6, 0.0)), 0.3) limit = (1.0, 2.0, 1.5, 2.4, 2.1) f.side_effect = limit v = m.ceiling_limit(data, gf=0.2) self.assertEquals(2.4, v)
def test_dive_step_info(self): """ Test dive step info mod """ model = ZH_L16B_GF() engine = _engine() engine.model = model d = _data(0.3, 2.2, 2.3) s1 = Step(Phase.CONST, 3.0, 100, AIR, d) d = _data(0.4, 1.2, 1.3) s2 = Step(Phase.DECO_STOP, 2.5, 145, AIR, d) data = [] @coroutine def sink(): while True: v = (yield) data.append(v) info = DiveStepInfoGenerator(engine, sink())() info.send(s1) info.send(s2) self.assertEquals(2, len(data)) i1, i2 = data self.assertEquals(20, i1.depth) self.assertEquals(100, i1.time) self.assertEquals(3.0, i1.pressure) self.assertEquals(AIR, i1.gas) self.assertEquals('const', i1.phase) self.assertEquals(2, len(i1.tissues)) self.assertEquals(15, i2.depth) self.assertEquals(145, i2.time) self.assertEquals(2.5, i2.pressure) self.assertEquals(AIR, i2.gas) self.assertEquals('deco_stop', i2.phase) self.assertEquals(2, len(i2.tissues)) t1, t2 = i1.tissues self.assertEquals(1, t1.no) self.assertEquals(2.2, t1.pressure) self.assertAlmostEqual(0.57475712, t1.limit) self.assertAlmostEqual(0.3, t1.gf) self.assertAlmostEqual(1.49384343, t1.gf_limit) self.assertEquals(2, t2.no) self.assertEquals(2.3, t2.pressure) self.assertAlmostEqual(0.84681999, t2.limit) self.assertAlmostEqual(0.3, t2.gf) self.assertAlmostEqual(1.72332601, t2.gf_limit)
def test_tissues_load(self): """ Test deco model all tissue compartments loading with inert gas """ m = ZH_L16B_GF() n = m.NUM_COMPARTMENTS data = Data([(0.79, 0.0)] * n, None) result = m.load(4, 1, AIR, -1, data) tissues = result.tissues self.assertTrue(all(v[0] > 0.79 for v in tissues), tissues) self.assertTrue(all(v[1] == 0 for v in tissues), tissues)
def test_ceiling_limit(self, f): """ Test calculation of pressure limit (default gf) """ m = ZH_L16B_GF() data = Data( ((1.5, 0.0), (2.5, 0.), (2.0, 0.0), (2.9, 0.0), (2.6, 0.0)), 0.3) limit = (1.0, 2.0, 1.5, 2.4, 2.1) f.side_effect = limit m.gf_low = 0.1 v = m.ceiling_limit(data) self.assertEquals(2.4, v)
def setUp(self): self.model = ZH_L16B_GF() self.k_const = self.model.n2_k_const