Exemple #1
0
        public void TestKnots()
        {
            // initialize value.
            Knots ten = 10;

            // convert from.
            KilometerPerHour tenInKilometerPerHour = 18.52;
            MeterPerSecond   tenInMeterPerSecond   = 5.14444444444;
            MilesPerHour     tenInMilesPerHour     = 11.50779;

            // test converts to.
            Assert.AreEqual(ten.Value, ((Knots)tenInKilometerPerHour).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((Knots)tenInMeterPerSecond).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((Knots)tenInMilesPerHour).Value, 0.000001);

            // tests division of distance with time resulting in speed.
            Kilometer distance = ten * (Hour)2;

            Assert.AreEqual(18.52 * 2.0, distance.Value);

            // tests some parsing functions.
            Knots tenPointFive = 10.5;
            Knots tenPointFiveParsed;

            Assert.IsTrue(Knots.TryParse(tenPointFive.ToString(), out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(Knots.TryParse("10.5", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(Knots.TryParse("10.5 knots", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);

            Assert.IsFalse(Knots.TryParse("10.5 m/s", out tenPointFiveParsed));
            Assert.IsFalse(Knots.TryParse("10.5 mph", out tenPointFiveParsed));
            Assert.IsFalse(Knots.TryParse("10.5 k/h", out tenPointFiveParsed));
        }
Exemple #2
0
        public Tuple <Second[], Second[], MeterPerSecond[]> CheckPattern(List <Tuple <GeoLocationDecimalDegree, DateTime> > pings)
        {
            if (pings.Count < 2)
            {
                return(new Tuple <Second[], Second[], MeterPerSecond[]>(new Second[pings.Count], new Second[pings.Count], new MeterPerSecond[pings.Count]));
            }
            int ping_count = pings.Count;

            GeoLocationDecimalDegree[] ship_ping_locations = new GeoLocationDecimalDegree[ping_count];
            for (int ping_index = 0; ping_index < ping_count; ping_index++)
            {
                ship_ping_locations[ping_index] = pings[ping_index].Item1;
            }
            Second[]         ping_seconds    = new Second[ping_count];
            MeterPerSecond[] ping_velocities = new MeterPerSecond[ping_count];
            //double[] ping_areas = new double[ping_count];
            Second[] ping_seconds_in_range = new Second[ping_count];


            Meter[,] distance_matrix = ToolsMathFunction.FillArray <GeoLocationDecimalDegree, GeoLocationDecimalDegree, Meter>(new FunctionDistanceGeoLocation(), ship_ping_locations, ship_ping_locations);


            Meter ping_distance = new Meter();

            ping_seconds[0]    = (Second)((pings[1].Item2 - pings[0].Item2).TotalMilliseconds) / 2000.0;
            ping_distance      = distance_matrix[0, 1] / 2.0;
            ping_velocities[0] = ping_distance / ping_seconds[0];
            for (int ping_index = 1; ping_index < ping_count - 1; ping_index++)
            {
                ping_seconds[ping_index]   += new Second((pings[ping_index].Item2 - pings[ping_index - 1].Item2).TotalMilliseconds) / 2000.0;
                ping_seconds[ping_index]   += new Second((pings[ping_index + 1].Item2 - pings[ping_index].Item2).TotalMilliseconds) / 2000.0;
                ping_distance               = (distance_matrix[ping_index, ping_index - 1] + distance_matrix[ping_index, ping_index + 1]) / 2.0;
                ping_velocities[ping_index] = ping_distance / ping_seconds[ping_index];
            }
            ping_seconds[ping_count - 1] = new Second((pings[ping_count - 1].Item2 - pings[ping_count - 2].Item2).TotalMilliseconds) / 2000.0;
            ping_distance = distance_matrix[ping_count - 2, ping_count - 1] / 2.0;
            ping_velocities[ping_count - 1] = ping_distance / ping_seconds[ping_count - 1];


            for (int index_ping_0 = 0; index_ping_0 < ping_count; index_ping_0++)
            {
                for (int index_ping_1 = 0; index_ping_1 < ping_count; index_ping_1++)
                {
                    if (distance_matrix[index_ping_0, index_ping_1] < SurveyRangeInMeters)
                    {
                        ping_seconds_in_range[index_ping_0] += ping_seconds[index_ping_1];
                    }
                }
            }
            return(new Tuple <Second[], Second[], MeterPerSecond[]>(ping_seconds, ping_seconds_in_range, ping_velocities));
        }
Exemple #3
0
        public void TestKilometerPerHour()
        {
            // initialize value.
            KilometerPerHour ten = 10;

            // convert from.
            Knots          tenInKnots          = 5.39956803;
            MeterPerSecond tenInMeterPerSecond = 2.77777777778;
            MilesPerHour   tenInMilesPerHour   = 6.21371192;

            // test converts to.
            Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInKnots).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInMeterPerSecond).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInMilesPerHour).Value, 0.000001);

            // tests division of distance with time resulting in speed.
            Kilometer twenty = ten * (Hour)2;

            Assert.AreEqual(20, twenty.Value);

            // tests some parsing functions.
            KilometerPerHour tenPointFive = 10.5;
            KilometerPerHour tenPointFiveParsed;

            Assert.IsTrue(KilometerPerHour.TryParse(tenPointFive.ToString(), out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5 km/h", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5 kmh", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5 kph", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5 kmph", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5km/h", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5kmh", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5kph", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(KilometerPerHour.TryParse("10.5kmph", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);

            Assert.IsFalse(KilometerPerHour.TryParse("10.5 m/s", out tenPointFiveParsed));
            Assert.IsFalse(KilometerPerHour.TryParse("10.5 mph", out tenPointFiveParsed));
            Assert.IsFalse(KilometerPerHour.TryParse("10.5 knots", out tenPointFiveParsed));
        }
Exemple #4
0
        public void TestMeterPerSecond()
        {
            // initialize value.
            MeterPerSecond ten = 10;

            // convert from.
            Knots            tenInKnots            = 19.43844492440605;
            KilometerPerHour tenInKilometerPerHour = 36;
            MilesPerHour     tenInMilesPerHour     = 22.36936292054402;

            // test converts to.
            Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInKnots).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInKilometerPerHour).Value, 0.000001);
            Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInMilesPerHour).Value, 0.000001);

            // tests division of distance with time resulting in speed.
            Kilometer twenty = ten * (Hour)2;

            Assert.AreEqual(tenInKilometerPerHour.Value * 2.0, twenty.Value);

            // tests some parsing functions.
            MeterPerSecond tenPointFive = 10.5;
            MeterPerSecond tenPointFiveParsed;

            Assert.IsTrue(MeterPerSecond.TryParse(tenPointFive.ToString(), out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(MeterPerSecond.TryParse("10.5", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(MeterPerSecond.TryParse("10.5 m/s", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);
            Assert.IsTrue(MeterPerSecond.TryParse("10.5m/s", out tenPointFiveParsed));
            Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value);

            Assert.IsFalse(MeterPerSecond.TryParse("10.5 km/h", out tenPointFiveParsed));
            Assert.IsFalse(MeterPerSecond.TryParse("10.5 mph", out tenPointFiveParsed));
            Assert.IsFalse(MeterPerSecond.TryParse("10.5 knots", out tenPointFiveParsed));
        }