public void TryParseDouble_FromFloatAndNullableFloat() { #region float - full method var success = ConvertibleFloatValue.TryParseDouble(DefaultValue); Assert.AreEqual(success.ToString("n2"), ConvertibleDoubleValue.ToString("n2"), "Error converting float to double"); #endregion #region float - without DefaultValue param success = ConvertibleFloatValue.TryParseDouble(); Assert.AreEqual(success.ToString("n2"), ConvertibleDoubleValue.ToString("n2"), "Error converting float to double"); #endregion #region float? - full method success = ConvertibleNullableFloatValue.TryParseDouble(DefaultValue); var invalid1 = ((float?)null).TryParseDouble(DefaultValue); Assert.AreEqual(success.ToString("n2"), ConvertibleDoubleValue.ToString("n2"), "Error converting float? to double"); Assert.AreEqual(invalid1, DefaultValue, "Error converting float? to double"); #endregion #region float? - without DefaultValue param success = ConvertibleNullableFloatValue.TryParseDouble(); invalid1 = ((float?)null).TryParseDouble(); Assert.AreEqual(success.ToString("n2"), ConvertibleDoubleValue.ToString("n2"), "Error converting float? to double"); Assert.AreEqual(invalid1, BasePrimitivesExtensions.GetDefaultDoubleConversionValue(), "Error converting float? to double"); #endregion }
public void TryParseShort_FromFloatAndNullableFloat() { const float invalidValue1 = float.MaxValue; float? nullableInvalidValue1 = float.MaxValue; const float invalidValue2 = float.MinValue; float? nullableInvalidValue2 = float.MinValue; #region float - full method var success = ConvertibleFloatValue.TryParseShort(DefaultValue); var invalid1 = invalidValue1.TryParseShort(DefaultValue); var invalid2 = invalidValue2.TryParseShort(DefaultValue); Assert.AreEqual(success, ConvertibleShortValue, "Error converting float to short"); Assert.AreEqual(invalid1, DefaultValue, "Error converting float to short"); Assert.AreEqual(invalid2, DefaultValue, "Error converting float to short"); #endregion #region float - without DefaultValue param success = ConvertibleFloatValue.TryParseShort(); invalid1 = invalidValue1.TryParseShort(); invalid2 = invalidValue2.TryParseShort(); Assert.AreEqual(success, ConvertibleShortValue, "Error converting float to short"); Assert.AreEqual(invalid1, BasePrimitivesExtensions.GetDefaultShortConversionValue(), "Error converting float to short"); Assert.AreEqual(invalid2, BasePrimitivesExtensions.GetDefaultShortConversionValue(), "Error converting float to short"); #endregion #region float? - full method success = ConvertibleNullableFloatValue.TryParseShort(DefaultValue); invalid1 = nullableInvalidValue1.TryParseShort(DefaultValue); invalid2 = nullableInvalidValue2.TryParseShort(DefaultValue); Assert.AreEqual(success, ConvertibleShortValue, "Error converting float? to short"); Assert.AreEqual(invalid1, DefaultValue, "Error converting float? to short"); Assert.AreEqual(invalid2, DefaultValue, "Error converting float? to short"); #endregion #region float? - without DefaultValue param success = ConvertibleNullableFloatValue.TryParseShort(); invalid1 = nullableInvalidValue1.TryParseShort(); invalid2 = nullableInvalidValue2.TryParseShort(); Assert.AreEqual(success, ConvertibleShortValue, "Error converting float? to short"); Assert.AreEqual(invalid1, BasePrimitivesExtensions.GetDefaultShortConversionValue(), "Error converting float? to short"); Assert.AreEqual(invalid2, BasePrimitivesExtensions.GetDefaultShortConversionValue(), "Error converting float? to short"); #endregion }