Exemplo n.º 1
0
 public void Indexer_SameQuantityNonGenericInterface_YieldsValidMeasureOBject()
 {
     var expected = new Measure<Volume>(5000.0, Volume.Liter);
     IMeasure meas = new StandardMeasure<Volume>(5.0);
     var actual = meas[Volume.Liter];
     MeasureAssert.MeasuresAreEqual(expected, actual);
 }
Exemplo n.º 2
0
 public void GetAmount_StandardMeasureToKmph_Factor3point6Larger()
 {
     var expected = AmountConverter.ToAmountType(90.0);
     var velocity = new StandardMeasure<Velocity>(25.0);
     var actual = velocity.GetAmount(Velocity.KiloMeterPerHour);
     AmountAssert.AreEqual(expected, actual);
 }
 public void ToStandardMeasures_DoubleNoUnitConversion_ReturningNonConvertedStandardMeasures()
 {
     var measures = new[] { 1.0, 2.0, 3.0, -2.0 }.ToStandardMeasures<Length>();
     var expected = new StandardMeasure<Length>(3.0);
     var actual = measures.ElementAt(2);
     MeasureAssert.MeasuresAreEqual(expected, actual);
 }
 public void ToStandardMeasures_DecimalWithUnitConversion_ReturningConvertedStandardMeasures()
 {
     var measures = new[] { 1.0m, 2.0m, 3.0m, -2.0m }.ToStandardMeasures(ElectricCurrent.MilliAmpere);
     var expected = new StandardMeasure<ElectricCurrent>(0.002m);
     var actual = measures.ElementAt(1);
     MeasureAssert.MeasuresAreEqual(expected, actual);
 }
Exemplo n.º 5
0
        public void Example1()
        {
            StandardMeasure<Mass> initialWgt = new StandardMeasure<Mass>(75.0);
            StandardMeasure<Mass> gainedWgt = new StandardMeasure<Mass>(2.5, Mass.HectoGram);
            StandardMeasure<Mass> newWgt = initialWgt + gainedWgt;

            Measure<Mass> newWgtInGram = newWgt[Mass.Gram];
            Measure<Mass> initialWgtInGram = newWgtInGram - gainedWgt;

            Console.WriteLine("Initial weight: {0}", initialWgtInGram);

            Measure<Length> height = new Measure<Length>(30.0, Length.CentiMeter);
            StandardMeasure<Area> area = (StandardMeasure<Area>)0.02;

            StandardMeasure<Volume> vol; ArithmeticOperations.Times(height, area, out vol);
            var maxVol = new StandardMeasure<Volume>(10.0, Volume.Liter);

            if (vol < maxVol)
            {
                Console.WriteLine("Calculated volume is within limits, actual volume: {0}", vol[Volume.Liter]);
            }

            #if NUNIT24
            Assert.Ignore();
            #else
            Assert.Pass();
            #endif
        }
Exemplo n.º 6
0
        public void StandardMeasureIndexer_ReciprocalCentiMeter_ReturnsHundredthValue()
        {
            var expected = new Measure <WaveNumber>(1.0, WaveNumber.ReciprocalCentiMeter);
            var actual   = new StandardMeasure <WaveNumber>(100.0)[WaveNumber.ReciprocalCentiMeter];

            MeasureAssert.MeasuresAreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void ToStandardMeasures_DoubleNoUnitConversion_ReturningNonConvertedStandardMeasures()
        {
            var measures = new[] { 1.0, 2.0, 3.0, -2.0 }.ToStandardMeasures <Length>();
            var expected = new StandardMeasure <Length>(3.0);
            var actual   = measures.ElementAt(2);

            MeasureAssert.MeasuresAreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void ToStandardMeasures_DecimalWithUnitConversion_ReturningConvertedStandardMeasures()
        {
            var measures = new[] { 1.0m, 2.0m, 3.0m, -2.0m }.ToStandardMeasures(ElectricCurrent.MilliAmpere);
            var expected = new StandardMeasure <ElectricCurrent>(0.002m);
            var actual   = measures.ElementAt(1);

            MeasureAssert.MeasuresAreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void GetAmount_StandardMeasureToKmph_Factor3point6Larger()
        {
            var expected = AmountConverter.ToAmountType(90.0);
            var velocity = new StandardMeasure <Velocity>(25.0);
            var actual   = velocity.GetAmount(Velocity.KiloMeterPerHour);

            AmountAssert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public void AreEqual_RhsArgumentHasValue_ReturnsFalse()
        {
            StandardMeasure<AmountConcentration>? lhs = null;
            StandardMeasure<AmountConcentration>? rhs = new StandardMeasure<AmountConcentration>(5.0);
            StandardMeasure<AmountConcentration> tol = StandardMeasure<AmountConcentration>.Zero;

            var expected = false;
            var actual = StandardMeasure.AreEqual(lhs, rhs, tol);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void AreEqual_BothArgumentsHaveValuesValuesWithinTolerance_ReturnsTrue()
        {
            StandardMeasure<AmountConcentration>? lhs = new StandardMeasure<AmountConcentration>(5.0);
            StandardMeasure<AmountConcentration>? rhs = new StandardMeasure<AmountConcentration>(5.0001);
            StandardMeasure<AmountConcentration> tol = new StandardMeasure<AmountConcentration>(0.001);

            var expected = true;
            var actual = StandardMeasure.AreEqual(lhs, rhs, tol);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
 public static double ConvertSurfaceMassFrom(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
     {
         return(value);
     }
     else
     {
         StandardMeasure <SurfaceDensity> measure = new StandardMeasure <SurfaceDensity>(value, SurfaceMassUnitFromUnitSystem(unitSystem));
         return(measure.GetAmount(SurfaceMassUnitFromUnitSystem(CurrentUnitSystem)));
     }
 }
Exemplo n.º 13
0
 public void TimeMeasureAdditionsStandardUnitWithStandardMeasure()
 {
     PerformTiming(() =>
                       {
                           var val = new Measure<Mass>(0.0);
                           for (double i = 0.0; i < no; ++i)
                           {
                               val += new StandardMeasure<Mass>(i);
                           }
                           return val;
                       });
 }
Exemplo n.º 14
0
 public void TimeMeasureAdditionsNonStandardUnitWithStandardMeasure()
 {
     PerformTiming(() =>
     {
         var val = new Measure<Length>(0.0, Length.CentiMeter);
         for (double i = 0.0; i < no; ++i)
         {
             val += new StandardMeasure<Length>(i);
         }
         return val;
     });
 }
Exemplo n.º 15
0
 public static double ConvertMassTo(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
     {
         return(value);
     }
     else
     {
         StandardMeasure <Mass> measure = new StandardMeasure <Mass>(value, MassUnitFromUnitSystem(CurrentUnitSystem));
         return(measure.GetAmount(MassUnitFromUnitSystem(unitSystem)));
     }
 }
Exemplo n.º 16
0
 public static double ConvertLengthFrom(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
     {
         return(value);
     }
     else
     {
         StandardMeasure <Length> measure = new StandardMeasure <Length>(value, LengthUnitFromUnitSystem(unitSystem));
         return(measure.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem)));
     }
 }
Exemplo n.º 17
0
 public static double ConvertLinearMassFrom(double value, UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
     {
         return(value);
     }
     else
     {
         StandardMeasure <Mass>   measure       = new StandardMeasure <Mass>(value, MassUnitFromUnitSystem(CurrentUnitSystem));
         StandardMeasure <Length> measureLength = new StandardMeasure <Length>(value, LengthUnitFromUnitSystem(CurrentUnitSystem));
         return(measure.GetAmount(MassUnitFromUnitSystem(unitSystem)));
     }
 }
Exemplo n.º 18
0
 public static Vector2D ConvertLengthFrom(Vector2D value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
     {
         return(value);
     }
     else
     {
         StandardMeasure <Length> measureX = new StandardMeasure <Length>(value.X, LengthUnitFromUnitSystem(unitSystem));
         StandardMeasure <Length> measureY = new StandardMeasure <Length>(value.Y, LengthUnitFromUnitSystem(unitSystem));
         return(new Vector2D(
                    measureX.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem))
                    , measureY.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem))
                    ));
     }
 }
 public void TimesOperator_MultiplyNumberRhs_AllMeasuresEquallyScaled()
 {
     var expected = new StandardMeasureTriplet<Time, Power, ElectricPotential>(15.0, 0.36, 1.8); ;
     var actual = new StandardMeasure<Number>(3.0) * _instance;
     IMeasureTripletAssert.AreEqual(expected, actual);
 }
Exemplo n.º 20
0
 public void GetAmount_UsingIUnit_ValidConversion()
 {
     var expected = AmountConverter.ToAmountType(500.0);
     var instance = new StandardMeasure<Length>(5.0);
     var actual = instance.GetAmount(Length.CentiMeter);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 21
0
 public static double ConvertMassTo(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
         return value;
     else
     {
         StandardMeasure<Mass> measure = new StandardMeasure<Mass>(value, MassUnitFromUnitSystem(CurrentUnitSystem));
         return measure.GetAmount(MassUnitFromUnitSystem(unitSystem));
     }
 }
Exemplo n.º 22
0
 public static double ConvertLengthFrom(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
         return value;
     else
     {
         StandardMeasure<Length> measure = new StandardMeasure<Length>(value, LengthUnitFromUnitSystem(unitSystem));
         return measure.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem));
     }
 }
Exemplo n.º 23
0
 public void Constructor_WithNonReferenceUnit_InitializesMeasureInReferenceUnit()
 {
     var expected = new Measure<Time>(180.0, Time.Second);
     var actual = new StandardMeasure<Time>(3.0, Time.Minute);
     MeasureAssert.MeasuresAreEqual(expected, actual);
 }
Exemplo n.º 24
0
 public void DivisionOperator_DivideGenericSameQuantity_ReturnsScalar()
 {
     var expected = 1.0;
     var numerator = new StandardMeasure<Area>(500.0, Area.SquareCentiMeter);
     var denominator = new StandardMeasure<Area>(5.0, Area.SquareDeciMeter);
     var actual = (double)(numerator / denominator);
     Assert.AreEqual(expected, actual, 1.0e-6);
 }
Exemplo n.º 25
0
 public static Vector3D ConvertLengthFrom(Vector3D value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
         return value;
     else
     {
         StandardMeasure<Length> measureX = new StandardMeasure<Length>(value.X, LengthUnitFromUnitSystem(unitSystem));
         StandardMeasure<Length> measureY = new StandardMeasure<Length>(value.Y, LengthUnitFromUnitSystem(unitSystem));
         StandardMeasure<Length> measureZ = new StandardMeasure<Length>(value.Z, LengthUnitFromUnitSystem(unitSystem));
         return new Vector3D(
             measureX.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem))
             , measureY.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem))
             , measureZ.GetAmount(LengthUnitFromUnitSystem(CurrentUnitSystem))
             );
     }
 }
Exemplo n.º 26
0
 public void Indexer_DifferentQuantitiesNonGenericInterface_Throws()
 {
     IMeasure meas = new StandardMeasure<SpecificVolume>(1.0);
     var throws = meas[Volume.CubicMeter];
 }
Exemplo n.º 27
0
 public static double ConvertSurfaceMassFrom(double value, UnitsManager.UnitSystem unitSystem)
 {
     if (unitSystem == CurrentUnitSystem)
         return value;
     else
     {
         StandardMeasure<SurfaceDensity> measure = new StandardMeasure<SurfaceDensity>(value, SurfaceMassUnitFromUnitSystem(unitSystem));
         return measure.GetAmount(SurfaceMassUnitFromUnitSystem(CurrentUnitSystem));
     }
 }
Exemplo n.º 28
0
 public void TimeStandardMeasureAdditions()
 {
     PerformTiming(() =>
                       {
                           var val = new StandardMeasure<Length>(0.0);
                           for (double i = 0.0; i < no; ++i)
                           {
                               val += new StandardMeasure<Length>(i);
                           }
                           return val;
                       });
 }