コード例 #1
0
        public void DurationCompareAutoTest()
        {
            UnitsNet.Duration         A1 = new UnitsNet.Duration(65.743, UnitsNet.Units.DurationUnit.Hour);
            EngineeringUnits.Duration A2 = new EngineeringUnits.Duration(65.743, EngineeringUnits.DurationUnit.Hour);

            for (int i = 0; i < UnitsNet.Duration.Units.Length; i++)
            {
                //Getting Units
                var EU = EngineeringUnits.DurationUnit.List().ToList()[i];
                var UN = UnitsNet.Duration.Units[i];

                //All units absolute difference
                Assert.AreEqual(0, A2.As(EU) - A1.As(UN), 0.04);

                //All units relative difference
                Assert.AreEqual(0, HelperClass.Percent(A2.As(EU),
                                                       A1.As(UN)),
                                1E-10);
                //All units symbol compare
                Assert.AreEqual(A2.ToUnit(EU).DisplaySymbol(),
                                A1.ToUnit(UN).ToString("a"));
            }
        }
コード例 #2
0
        public void DurationCompare()
        {
            UnitsNet.Duration         A1 = new UnitsNet.Duration(6544444.743, UnitsNet.Units.DurationUnit.Minute);
            EngineeringUnits.Duration A2 = new EngineeringUnits.Duration(6544444.743, EngineeringUnits.DurationUnit.Minute);



            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Day) - A1.As(UnitsNet.Units.DurationUnit.Day), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Hour) - A1.As(UnitsNet.Units.DurationUnit.Hour), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Microsecond) - A1.As(UnitsNet.Units.DurationUnit.Microsecond), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Millisecond) - A1.As(UnitsNet.Units.DurationUnit.Millisecond), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Minute) - A1.As(UnitsNet.Units.DurationUnit.Minute), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Nanosecond) - A1.As(UnitsNet.Units.DurationUnit.Nanosecond), 65);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Second) - A1.As(UnitsNet.Units.DurationUnit.Second), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Week) - A1.As(UnitsNet.Units.DurationUnit.Week), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Month30) - A1.As(UnitsNet.Units.DurationUnit.Month30), 0);
            Assert.AreEqual(0, A2.As(EngineeringUnits.DurationUnit.Year365) - A1.As(UnitsNet.Units.DurationUnit.Year365), 0);


            Assert.AreEqual(0, UnitsNet.Duration.FromDays(435).Days - EngineeringUnits.Duration.FromDays(435).Days, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromHours(435).Hours - EngineeringUnits.Duration.FromHours(435).Hours, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromMicroseconds(435).Microseconds - EngineeringUnits.Duration.FromMicroseconds(435).Microseconds, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromMilliseconds(435).Milliseconds - EngineeringUnits.Duration.FromMilliseconds(435).Milliseconds, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromMinutes(435).Minutes - EngineeringUnits.Duration.FromMinutes(435).Minutes, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromMonths30(435).Months30 - EngineeringUnits.Duration.FromMonths30(435).Months30, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromNanoseconds(435).Nanoseconds - EngineeringUnits.Duration.FromNanoseconds(435).Nanoseconds, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromSeconds(435).Seconds - EngineeringUnits.Duration.FromSeconds(435).Seconds, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromWeeks(435).Weeks - EngineeringUnits.Duration.FromWeeks(435).Weeks, 0);
            Assert.AreEqual(0, UnitsNet.Duration.FromYears365(435).Years365 - EngineeringUnits.Duration.FromYears365(435).Years365, 0);



            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Day),
                                                   A1.As(UnitsNet.Units.DurationUnit.Day)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Hour),
                                                   A1.As(UnitsNet.Units.DurationUnit.Hour)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Microsecond),
                                                   A1.As(UnitsNet.Units.DurationUnit.Microsecond)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Millisecond),
                                                   A1.As(UnitsNet.Units.DurationUnit.Millisecond)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Minute),
                                                   A1.As(UnitsNet.Units.DurationUnit.Minute)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Month30),
                                                   A1.As(UnitsNet.Units.DurationUnit.Month30)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Nanosecond),
                                                   A1.As(UnitsNet.Units.DurationUnit.Nanosecond)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Second),
                                                   A1.As(UnitsNet.Units.DurationUnit.Second)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Week),
                                                   A1.As(UnitsNet.Units.DurationUnit.Week)), 1E-10);
            Assert.AreEqual(0, HelperClass.Percent(A2.As(EngineeringUnits.DurationUnit.Year365),
                                                   A1.As(UnitsNet.Units.DurationUnit.Year365)), 1E-10);



            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Day).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Day).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Hour).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Hour).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Microsecond).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Microsecond).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Millisecond).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Millisecond).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Minute).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Minute).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Month30).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Month30).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Nanosecond).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Nanosecond).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Second).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Second).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Week).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Week).ToString("a"));
            Assert.AreEqual(A2.ToUnit(EngineeringUnits.DurationUnit.Year365).DisplaySymbol(),
                            A1.ToUnit(UnitsNet.Units.DurationUnit.Year365).ToString("a"));
        }