ThisToThat/ThisToThatTests/ToSingleTests.cs
/// <summary>
/// Makes multiple Double to Single or default conversions and asserts that the results are correct.
/// </summary>
Makes multiple Double to Single or default conversions and asserts that the results are correct.
Makes multiple Double to Single or default conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToSingle tests")]
        public void TestDoubleToSingleOrDefault()
        {
            Double source = Double.MinValue;
            Assert.IsInstanceOfType(source, typeof(Double));
            Single? result = source.ToSingleOrDefault(86f);
            Assert.AreEqual(86f, result);
            Assert.IsInstanceOfType(result, typeof(Single));
            source = 42d;
            Assert.IsInstanceOfType(source, typeof(Double));
            result = source.ToSingleOrDefault(86f);
            Assert.AreEqual(42f, result);
            Assert.IsInstanceOfType(result, typeof(Single));
            source = Double.MaxValue;
            Assert.IsInstanceOfType(source, typeof(Double));
            result = source.ToSingleOrDefault(86f);
            Assert.AreEqual(86f, result);
            Assert.IsInstanceOfType(result, typeof(Single));
        }
[ TestMethod , TestCategory ( " " ) ] public void TestDoubleToSingleOrDefault ( ) { Double source = Double . MinValue ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; Single ? result = source . ToSingleOrDefault ( 86f ) ; Assert . AreEqual ( 86f , result ) ; Assert . IsInstanceOfType ( result , typeof ( Single ) ) ; source = 42d ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; result = source . ToSingleOrDefault ( 86f ) ; Assert . AreEqual ( 42f , result ) ; Assert . IsInstanceOfType ( result , typeof ( Single ) ) ; source = Double . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; result = source . ToSingleOrDefault ( 86f ) ; Assert . AreEqual ( 86f , result ) ; Assert . IsInstanceOfType ( result , typeof ( Single ) ) ; }
Makes multiple Double to Single or default conversions and asserts that the results are correct.
Makes multiple Double to Single or default conversions and asserts that the results are correct .
// Test conversion of source type minimum value // Here we would expect this conversion to fail (and return the default value of 86f),  // since the source type's minimum value (-1.7976931348623157E+308) is less than the target type's minimum value (-3.40282347E+38). // Test conversion of source type value 42 to target type // Test conversion of source type maximum value // Here we would expect this conversion to fail (and return the default value of 86f),  // since the source type's maximum value (1.7976931348623157E+308) is greater than the target type's maximum value (3.40282347E+38).