private static void VerifyNullableSBytePower(sbyte?a, sbyte?b)
{
Expression <Func <sbyte?> > e =
Expression.Lambda <Func <sbyte?> >(
Expression.Power(
Expression.Constant(a, typeof(sbyte?)),
Expression.Constant(b, typeof(sbyte?)),
typeof(BinaryNullablePowerTests).GetTypeInfo().GetDeclaredMethod("PowerSByte")
));
Func <sbyte?> f = e.Compile();
// compute with expression tree
sbyte? etResult = default(sbyte);
Exception etException = null;
try
{
etResult = f();
}
catch (Exception ex)
{
etException = ex;
}
// compute with real IL
sbyte? csResult = default(sbyte);
Exception csException = null;
if (a == null || b == null)
{
csResult = null;
}
else
{
try
{
csResult = (sbyte?)Math.Pow((double)a, (double)b);
}
catch (Exception ex)
{
csException = ex;
}
}
// either both should have failed the same way or they should both produce the same result
if (etException != null || csException != null)
{
Assert.NotNull(etException);
Assert.NotNull(csException);
Assert.Equal(csException.GetType(), etException.GetType());
}
else
{
Assert.Equal(csResult, etResult);
}
}