Example #1
0
 public static void SubtractFromSource(this NumericValue numericValue, NumericValue secondNumber)
 {
    if (secondNumber != null)
    {
       numericValue.Value -= secondNumber.ConvertToUnit(numericValue.UnitOfMeasure.ToInternalUom());
    }
 }
      public void GivenBaseNumberWhenConvertUomThenValueIsSet()
      {
         var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
         var targetUom = InternalUnitSystemManager.Instance.UnitOfMeasures["in"];
         var baseNumber = new NumericValue(sourceUom.ToModelUom(), 12.0);

         baseNumber.ConvertToUnit(targetUom);
         Assert.AreEqual(144.0, baseNumber.Value, Epsilon);
      }
      public void GivenBaseNumberWhenSetTargetThenTargetUnitOfMeasureIsSet()
      {
         var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
         var targetUom = InternalUnitSystemManager.Instance.UnitOfMeasures["in"];
         var baseNumber = new NumericValue(sourceUom.ToModelUom(), (double)12.0);

         baseNumber.ConvertToUnit(targetUom);
         Assert.AreEqual(targetUom.DomainID, baseNumber.UnitOfMeasure.Code);
      }
Example #4
0
      public static VariableValue ConvertCdf(VariableValue variableValue, string targetUnit)
      {
         if (variableValue.UnitOfMeasure == targetUnit)
         {
            return variableValue;
         }

         var sourceUnitOfMeasure = GetUomCdf(variableValue.UnitOfMeasure);
         var targetUnitOfMeasure = GetUomCdf(targetUnit);
         var bn = new NumericValue(sourceUnitOfMeasure.ToModelUom(), variableValue.Value);
         bn.ConvertToUnit(targetUnitOfMeasure);
         var convertedValue = bn.Value;
         return new VariableValue(variableValue.Representation, targetUnit, convertedValue);
      }
      public void GivenTwoScalarValuesWhenConvertedThenResultIsConvertedCorrectly()
      {
         var number = new NumericValue(InternalUnitSystemManager.Instance.UnitOfMeasures["seeds1ac-1"].ToModelUom(), 30213.0);
         number.ConvertToUnit(InternalUnitSystemManager.Instance.UnitOfMeasures["seeds1ha-1"]);

         Assert.AreEqual(74657.948902674674, number.Value, Epsilon);
      }
Example #6
0
 public static NumericValue Add(this NumericValue numericValue, NumericValue secondNumber)
 {
    var unitOfMeasure = numericValue.UnitOfMeasure.ToInternalUom();
    return new NumericValue(numericValue.UnitOfMeasure, numericValue.Value + secondNumber.ConvertToUnit(unitOfMeasure));
 }