Exemplo n.º 1
0
 public void Gas_Constructor2_WithValidData()
 {
     Gas target = new Gas(0.30, 0.60);
     Assert.Equal(0.30, target.OxygenPart);
     Assert.Equal(0.10, target.NitrogenPart);
     Assert.Equal(0.60, target.HeliumPart);
 }
        public static double ConstantDepth(Gas gas, double depth, double time)
        {
            if (depth < 0)
            {
                throw new ArgumentException("Depth need to be posetive");
            }

            if (time < 0)
            {
                throw new ArgumentException("Time need to be posetive");
            }

            var ppo2level = Calculations.PartialPressureofGas(gas.OxygenProcent, depth);

            if (ppo2level > 1.6)
            {
                throw new ArgumentException("PPO2 value above 1.6 can't calculate CNS");
            }

            if (ppo2level <= 0.5)
            {
                return 0;
            }

            var tlim = PO2Datas.Where(x => x.PO2Low < ppo2level && x.PO2Hight >= ppo2level)
                               .Select(x => x.Slope*ppo2level + x.Intercept)
                               .FirstOrDefault();

            return Math.Round((time/tlim)*100, 2);
        }
Exemplo n.º 3
0
 public void Gas_ToString()
 {
     Gas target = new Gas(0.1, 0.2, 0.7);
     string expected = "O2:10% N2:20% H:70%";
     string actual;
     actual = target.ToString();
     Assert.Equal(expected, actual);
 }
Exemplo n.º 4
0
 public void Gas_EqualsTest_True()
 {
     Gas target = new Gas(0.2, 0.2, 0.6);
     Gas obj = new Gas(0.2, 0.2, 0.6);
     bool expected = true;
     bool actual;
     actual = target.Equals(obj);
     Assert.Equal(expected, actual);
 }
        public void OTU_AscendDescend_RateNegative_ThrowsException()
        {
            var gas = new Gas(0.32, 0.68, 0);
            double startDepth = 10;
            double finalDepth = 20;
            double rate = -12;

            Assert.Throws<ArgumentException>(() => OxygenToxicityUnit.AscendDescend(gas, startDepth, finalDepth, rate));
        }
Exemplo n.º 6
0
 public void Gas_EqualsTest_False()
 {
     Gas target = new Gas(0.2, 0.2, 0.6);
     object obj = new Gas(0.2, 0.6, 0.2);
     bool expected = false;
     bool actual;
     actual = target.Equals(obj);
     Assert.Equal(expected, actual);
 }
        public void CNS_AscendDescend_RateZero_ThrowsException()
        {
            Gas gas = new Gas(0.32, 0.68, 0);
            double startDepth = 0;
            double finalDepth = 5;
            double rate = 0;

            Assert.Throws<ArgumentException>(() => CentralNervousSystem.AscendDescend(gas, startDepth, finalDepth, rate));
        }
Exemplo n.º 8
0
 public void ZH_L16_ChangeGas()
 {
     Gas gas = new Gas(0.21, 0.79, 0.0);
     ZH_L16 target = new ZH_L16();
     target.ActiveGas = gas;
     Gas newGas = new Gas(0.3, 0.7, 0.0);
     target.ActiveGas = newGas;
     Assert.Equal(newGas, target.ActiveGas);
 }
 public void OTU_AscendDescend_DescendFromSurface()
 {
     var gas = new Gas(0.32, 0.68, 0);
     double startDepth = 0;
     double finalDepth = 36;
     double rate = 12;
     var expected = 2.40;
     double actual;
     actual = Math.Round(OxygenToxicityUnit.AscendDescend(gas, startDepth, finalDepth, rate), 2);
     Assert.Equal(expected, actual);
 }
 public void OTU_AscendDescend_ChangeDepthWithinNoOtuScope()
 {
     var gas = new Gas(0.32, 0.68, 0);
     double startDepth = 0;
     double finalDepth = 4;
     double rate = 12;
     double expected = 0;
     double actual;
     actual = Math.Round(OxygenToxicityUnit.AscendDescend(gas, startDepth, finalDepth, rate), 2);
     Assert.Equal(expected, actual);
 }
Exemplo n.º 11
0
        public static double AscendDescend(Gas gas, double startDepth, double finalDepth, double rate)
        {
            if (startDepth < 0)
            {
                throw new ArgumentException("Start depth need to be posetive");
            }

            if (finalDepth < 0)
            {
                throw new ArgumentException("Final depth need to be posetive");
            }

            if (rate <= 0)
            {
                throw new ArgumentException("Rate need to be posetive number above 0");
            }

            if (Math.Abs(startDepth - finalDepth) < 0.001)
            {
                return 0;
            }

            // Going up. Hence invert rate
            if (finalDepth < startDepth)
            {
                rate = rate*-1.0;
            }

            double time = (finalDepth - startDepth)/rate;
            double po2End = gas.OxygenPart*(finalDepth + 10.0)/10.0;
            double po2Start = gas.OxygenPart*(startDepth + 10.0)/10.0;

            // OTU is only effective if pressure bigger then 0.5
            if (po2End < 0.5 & po2Start < 0.5)
            {
                return 0;
            }

            if (po2Start < 0.5)
            {
                time = time*((po2End - 0.5)/(po2End - po2Start));
                po2Start = 0.5;
            }
            else if (po2End < 0.5)
            {
                time = time*((po2Start - 0.5)/(po2Start - po2End));
                po2End = 0.5;
            }

            return
                Math.Round(
                    (((3.0/11.0)*time)/(po2End - po2Start))*
                    (Math.Pow(((po2End - 0.5)/0.5), (11.0/6.0)) - Math.Pow(((po2Start - 0.5)/0.5), (11.0/6.0))), 2);
        }
Exemplo n.º 12
0
        public void ZH_L16_AscendDecsendTest_NegativeFinishDepth_ThrowException()
        {
            Gas gas = new Gas(0.11, 0.79, 0.1);
            ZH_L16 target = new ZH_L16();
            target.ActiveGas = gas;

            double start = 1;
            double finish = -1;
            double rate = 1;
            Assert.Throws<ArgumentException>(() => target.AscendDecsend(start, finish, rate));
        }
Exemplo n.º 13
0
 public DiveSegment(double depth, TimeSpan time, DiveState state, int startTime, int endTime, Gas gas, double cns,
     double otu)
 {
     Depth = depth;
     Time = time;
     State = state;
     StartTime = startTime;
     EndTime = endTime;
     CurrentGas = gas;
     Otu = otu;
     Cns = cns;
 }
Exemplo n.º 14
0
        public static double ConstantDepth(Gas gas, double depth, double time)
        {
            if (depth < 0)
            {
                throw new ArgumentException("Depth need to be posetive");
            }

            if (time < 0)
            {
                throw new ArgumentException("Time need to be posetive");
            }

            double po2 = Calculations.PartialPressureofGas(gas.OxygenProcent, depth);

            if (po2 <= 0.5)
            {
                return 0;
            }

            return Math.Round(time*Math.Pow((0.5/(po2 - 0.5)), (-5.0/6.0)), 2);
        }
        public static double AscendDescend(Gas gas, double startDepth, double finalDepth, double metersPerMinutes)
        {
            if (startDepth < 0)
            {
                throw new ArgumentException("Start depth need to be posetive");
            }

            if (finalDepth < 0)
            {
                throw new ArgumentException("Final depth need to be posetive");
            }

            if (metersPerMinutes <= 0)
            {
                throw new ArgumentException("Rate need to be posetive number above 0");
            }

            if (Math.Abs(startDepth - finalDepth) < 0.001)
            {
                return 0;
            }

            var depthDiff = Math.Abs(finalDepth - startDepth);
            var totalTime = depthDiff / metersPerMinutes;
            var timeAtDepth = totalTime / (depthDiff * 2);
            var lowestDepth = finalDepth > startDepth ? finalDepth : startDepth;
            var highestDepth = finalDepth > startDepth ? startDepth : finalDepth;

            double cns = 0;

            // calc for every half meter and sum
            for (var depth = lowestDepth; depth > highestDepth; depth -= 0.5)
            {
                cns += ConstantDepth(gas, depth, timeAtDepth);
            }

            return cns;
        }
 public void CNS_AscendDescend(double startDepth, double finalDepth, double rate, double expectedResult)
 {
     Gas gas = new Gas(0.32, 0.68, 0);
     var actual = Math.Round(CentralNervousSystem.AscendDescend(gas, startDepth, finalDepth, rate), 2);
     Assert.Equal(expectedResult, actual);
 }
 public void OTU_AscendDescend_StayingAtTheSameDepth()
 {
     var gas = new Gas(0.32, 0.68, 0);
     double startDepth = 10;
     double finalDepth = 10;
     double rate = 12;
     double expected = 0;
     double actual;
     actual = Math.Round(OxygenToxicityUnit.AscendDescend(gas, startDepth, finalDepth, rate), 2);
     Assert.Equal(expected, actual);
 }
Exemplo n.º 18
0
 public WayPoint(double depth, double time, Gas gas)
 {
     Depth = depth;
     Time = time;
     Gas = gas;
 }
 public void OTU_ConstantDepth()
 {
     var gas = new Gas(0.32, 0.68, 0);
     double depth = 36;
     double time = 22;
     var expected = 38.28;
     double actual;
     actual = Math.Round(OxygenToxicityUnit.ConstantDepth(gas, depth, time), 2);
     Assert.Equal(expected, actual);
 }
        public void OTU_ConstantDepth_TimeNegative_ThrowsException()
        {
            var gas = new Gas(0.32, 0.68, 0);
            double depth = 4;
            double time = -22;

            Assert.Throws<ArgumentException>(() => OxygenToxicityUnit.ConstantDepth(gas, depth, time));
        }
 public void OTU_ConstantDepth_TimeZero()
 {
     var gas = new Gas(0.32, 0.68, 0);
     double depth = 4;
     double time = 0;
     double expected = 0;
     double actual;
     actual = Math.Round(OxygenToxicityUnit.ConstantDepth(gas, depth, time), 2);
     Assert.Equal(expected, actual);
 }
 public void CNS_AscendDescend_StartDepthBiggerThanPoLowAndFinalDepthBiggerThanPoHighAndGoingDown()
 {
     Gas gas = new Gas(0.32, 0.68, 0);
     double startDepth = 20;
     double finalDepth = 30;
     double rate = 10;
     double expected = 0.43;
     double actual;
     actual = Math.Round(CentralNervousSystem.AscendDescend(gas, startDepth, finalDepth, rate), 2);
     Assert.Equal(expected, actual);
 }
 public void CNS_ConstantDepth(double oxygenPart, double depth, double time, double expectedResult)
 {
     var gas = new Gas(oxygenPart, 1- oxygenPart, 0);
     var actual = Math.Round(CentralNervousSystem.ConstantDepth(gas, depth, time), 2);
     Assert.Equal(expectedResult, actual);
 }
        public void CNS_ConstantDepth_ToHighPo_ThrowException()
        {
            Gas gas = new Gas(0.32, 0.68, 0);
            double depth = 50;
            double time = 50;

            Assert.Throws<ArgumentException>(() => CentralNervousSystem.ConstantDepth(gas, depth, time));
        }