class TestRepetitiveDive1(TestDive):

    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(40, 20 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(20 * 60)
        self.profile1.do_dive()

    def test_rt(self):
        assert seconds_to_mmss(self.profile1.run_time) == ' 68:09', \
            'bad dive runtime ? (%s)' \
            % seconds_to_mmss(self.profile1.run_time)

    def test_otu(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.otu,
                               40.0702502936, 7, 'bad dive OTU ? (%s)'
                               % self.profile1.model.ox_tox.otu)

    def test_cns(self):
        self.assertAlmostEqual(self.profile1.model.ox_tox.cns * 100,
                               14.3091665925, 7, 'bad dive CNS ? (%s)'
                               % (self.profile1.model.ox_tox.cns * 100))

    def test_tank_cons(self):
        self.assertAlmostEqual(self.airtank12.used_gas, 2115.5196384,
                               7, 'bad used gas (%s)'
                               % self.airtank12.used_gas)

    def test_tank_cons_rule(self):
        self.assertEqual(self.profile1.tanks[0].check_rule(), True,
                         'Wrong tank status : it should pass the remaining '
                         'gas rule test (result:%s)'
                         % self.profile1.tanks[0].check_rule())

    def test_no_flight(self):
        no_flight_time = self.profile1.no_flight_time()
        self.assertEqual(no_flight_time, 5460, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_no_flight_wo_exc(self):
        no_flight_time = self.profile1.no_flight_time_wo_exception()
        self.assertEqual(no_flight_time, 5460, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_surfaceint(self):
        self.assertEqual(self.profile1.get_surface_interval(),
                         ' 20:00',
                         'wrong surface interval:%s'
                         % self.profile1.get_surface_interval())
class TestRepetitiveDive3(TestDive):

    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(30, 40 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(30 * 60)
        self.profile1.do_dive()

        diveseg3 = SegmentDive(25, 35 * 60, self.airtank, 0)
        self.profile2 = Dive([diveseg3], [self.airtank], self.profile1)
        self.profile2.do_surface_interval(60 * 60)

        # self.profile2.refill_tanks()

        self.profile2.do_dive()

        diveseg4 = SegmentDive(40, 20 * 60, self.airtank, 0)
        self.profile3 = Dive([diveseg4], [self.airtank], self.profile2)
        self.profile3.do_surface_interval(12 * 60 * 60)

        # self.profile3.refill_tanks()

        self.profile3.do_dive()

    def test_rt(self):
        assert seconds_to_mmss(self.profile3.run_time) == ' 38:36', \
            'bad dive runtime ? (%s)' \
            % seconds_to_mmss(self.profile3.run_time)

    def test_otu(self):
        self.assertAlmostEqual(self.profile3.model.ox_tox.otu,
                               86.8657204829, 7, 'bad dive OTU ? (%s)'
                               % self.profile3.model.ox_tox.otu)

    def test_cns(self):
        self.assertAlmostEqual(self.profile3.model.ox_tox.cns * 100,
                               7.75546902304, 7, 'bad dive CNS ? (%s)'
                               % (self.profile3.model.ox_tox.cns * 100))

    def test_tank_cons(self):
        self.assertAlmostEqual(self.airtank.used_gas, 2115.5196384, 7,
                               'bad used gas (%s)'
                               % self.airtank.used_gas)

    def test_tank_cons_rule(self):
        self.assertEqual(self.profile3.tanks[0].check_rule(), True,
                         'Wrong tank status : it should pass the remaining '
                         'gas rule test (result:%s)'
                         % self.profile2.tanks[0].check_rule())

    def test_no_flight(self):
        no_flight_time = self.profile3.no_flight_time()
        self.assertEqual(no_flight_time, 1620, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_no_flight_wo_exc(self):
        no_flight_time = self.profile3.no_flight_time_wo_exception()
        self.assertEqual(no_flight_time, 1620, 'Bad no flight time: %s'
        % no_flight_time)

    def test_surfaceint(self):
        self.assertEqual(self.profile3.get_surface_interval(),
                         '720:00',
                         'wrong surface interval:%s'
                         % self.profile3.get_surface_interval())
class TestRepetitiveDive2(TestDive):

    def setUp(self):
        TestDive.setUp(self)

        diveseg1 = SegmentDive(40, 20 * 60, self.airtank12, 0)
        self.profile0 = Dive([diveseg1], [self.airtank12])
        self.profile0.do_dive()

        diveseg2 = SegmentDive(30, 40 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg2], [self.airtank], self.profile0)
        self.profile1.do_surface_interval(30 * 60)
        self.profile1.do_dive()

        diveseg3 = SegmentDive(25, 35 * 60, self.airtank, 0)
        self.profile2 = Dive([diveseg3], [self.airtank], self.profile1)
        self.profile2.do_surface_interval(60 * 60)

        # self.profile2.refill_tanks()

        self.profile2.do_dive()

    def test_rt(self):
        assert seconds_to_mmss(self.profile2.run_time) == ' 70:18', \
            'bad dive runtime ? (%s)' \
            % seconds_to_mmss(self.profile2.run_time)

    def test_otu(self):
        self.assertAlmostEqual(self.profile2.model.ox_tox.otu,
                               66.8427163401, 7, 'bad dive OTU ? (%s)'
                               % self.profile2.model.ox_tox.otu)

    def test_cns(self):
        self.assertAlmostEqual(self.profile2.model.ox_tox.cns * 100,
                               18.1490350581, 7, 'bad dive CNS ? (%s)'
                               % (self.profile2.model.ox_tox.cns * 100))

    def test_tank_cons(self):
        self.assertAlmostEqual(self.airtank.used_gas, 2701.73162947, 7,
                               'bad used gas (%s)'
                               % self.airtank.used_gas)

    def test_tank_cons_rule(self):
        self.assertEqual(self.profile2.tanks[0].check_rule(), True,
                         'Wrong tank status : it should pass the remaining '
                         'gas rule test (result:%s)'
                         % self.profile2.tanks[0].check_rule())

    def test_no_flight(self):
        no_flight_time = self.profile2.no_flight_time()
        self.assertEqual(no_flight_time, 18360, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_no_flight_wo_exc(self):
        no_flight_time = self.profile2.no_flight_time_wo_exception()
        self.assertEqual(no_flight_time, 18360, 'Bad no flight time: %s'
                         % no_flight_time)

    def test_surfaceint(self):
        self.assertEqual(self.profile2.get_surface_interval(),
                         ' 60:00',
                         'wrong surface interval:%s'
                         % self.profile2.get_surface_interval())