Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Adding tests for Increment and Decrement nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Oct 10, 2015
1 parent 7f5d923 commit 41c4542
Show file tree
Hide file tree
Showing 5 changed files with 729 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<OutputType>Library</OutputType>
<AssemblyName>System.Linq.Expressions.Tests</AssemblyName>
<RootNamespace>System.Linq.Expressions.Tests</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> </PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
Expand Down Expand Up @@ -137,6 +136,10 @@
<Compile Include="Unary\UnaryArithmeticNegateCheckedTests.cs" />
<Compile Include="Unary\UnaryArithmeticNegateTests.cs" />
<Compile Include="Unary\UnaryBitwiseNotNullableTests.cs" />
<Compile Include="Unary\UnaryDecrementTests.cs" />
<Compile Include="Unary\UnaryDecrementNullableTests.cs" />
<Compile Include="Unary\UnaryIncrementNullableTests.cs" />
<Compile Include="Unary\UnaryIncrementTests.cs" />
<Compile Include="Unary\UnaryBitwiseNotTests.cs" />
<Compile Include="Unary\UnaryIsFalseNullableTests.cs" />
<Compile Include="Unary\UnaryIsFalseTests.cs" />
Expand Down
181 changes: 181 additions & 0 deletions src/System.Linq.Expressions/tests/Unary/UnaryDecrementNullableTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Linq.Expressions;
using Xunit;

namespace Tests.ExpressionCompiler.Unary
{
public static unsafe class UnaryDecrementNullableTests
{
#region Test methods

[Fact]
public static void CheckUnaryDecrementNullableShortTest()
{
short?[] values = new short?[] { null, 0, 1, -1, short.MinValue, short.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableShort(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementNullableUShortTest()
{
ushort?[] values = new ushort?[] { null, 0, 1, ushort.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableUShort(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementNullableIntTest()
{
int?[] values = new int?[] { null, 0, 1, -1, int.MinValue, int.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableInt(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementNullableUIntTest()
{
uint?[] values = new uint?[] { null, 0, 1, uint.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableUInt(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementNullableLongTest()
{
long?[] values = new long?[] { null, 0, 1, -1, long.MinValue, long.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableLong(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementNullableULongTest()
{
ulong?[] values = new ulong?[] { null, 0, 1, ulong.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableULong(values[i]);
}
}

[Fact]
public static void CheckDecrementFloatTest()
{
float?[] values = new float?[] { null, 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableFloat(values[i]);
}
}

[Fact]
public static void CheckDecrementDoubleTest()
{
double?[] values = new double?[] { null, 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementNullableDouble(values[i]);
}
}

#endregion

#region Test verifiers

private static void VerifyDecrementNullableShort(short? value)
{
Expression<Func<short?>> e =
Expression.Lambda<Func<short?>>(
Expression.Decrement(Expression.Constant(value, typeof(short?))),
Enumerable.Empty<ParameterExpression>());
Func<short?> f = e.Compile();
Assert.Equal((short?)(--value), f());
}

private static void VerifyDecrementNullableUShort(ushort? value)
{
Expression<Func<ushort?>> e =
Expression.Lambda<Func<ushort?>>(
Expression.Decrement(Expression.Constant(value, typeof(ushort?))),
Enumerable.Empty<ParameterExpression>());
Func<ushort?> f = e.Compile();
Assert.Equal((ushort?)(--value), f());
}

private static void VerifyDecrementNullableInt(int? value)
{
Expression<Func<int?>> e =
Expression.Lambda<Func<int?>>(
Expression.Decrement(Expression.Constant(value, typeof(int?))),
Enumerable.Empty<ParameterExpression>());
Func<int?> f = e.Compile();
Assert.Equal((int?)(--value), f());
}

private static void VerifyDecrementNullableUInt(uint? value)
{
Expression<Func<uint?>> e =
Expression.Lambda<Func<uint?>>(
Expression.Decrement(Expression.Constant(value, typeof(uint?))),
Enumerable.Empty<ParameterExpression>());
Func<uint?> f = e.Compile();
Assert.Equal((uint?)(--value), f());
}

private static void VerifyDecrementNullableLong(long? value)
{
Expression<Func<long?>> e =
Expression.Lambda<Func<long?>>(
Expression.Decrement(Expression.Constant(value, typeof(long?))),
Enumerable.Empty<ParameterExpression>());
Func<long?> f = e.Compile();
Assert.Equal((long?)(--value), f());
}

private static void VerifyDecrementNullableULong(ulong? value)
{
Expression<Func<ulong?>> e =
Expression.Lambda<Func<ulong?>>(
Expression.Decrement(Expression.Constant(value, typeof(ulong?))),
Enumerable.Empty<ParameterExpression>());
Func<ulong?> f = e.Compile();
Assert.Equal((ulong?)(--value), f());
}

private static void VerifyDecrementNullableFloat(float? value)
{
Expression<Func<float?>> e =
Expression.Lambda<Func<float?>>(
Expression.Decrement(Expression.Constant(value, typeof(float?))),
Enumerable.Empty<ParameterExpression>());
Func<float?> f = e.Compile();
Assert.Equal((float?)(--value), f());
}

private static void VerifyDecrementNullableDouble(double? value)
{
Expression<Func<double?>> e =
Expression.Lambda<Func<double?>>(
Expression.Decrement(Expression.Constant(value, typeof(double?))),
Enumerable.Empty<ParameterExpression>());
Func<double?> f = e.Compile();
Assert.Equal((double?)(--value), f());
}

#endregion
}
}
181 changes: 181 additions & 0 deletions src/System.Linq.Expressions/tests/Unary/UnaryDecrementTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Linq.Expressions;
using Xunit;

namespace Tests.ExpressionCompiler.Unary
{
public static unsafe class UnaryDecrementTests
{
#region Test methods

[Fact]
public static void CheckUnaryDecrementShortTest()
{
short[] values = new short[] { 0, 1, -1, short.MinValue, short.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementShort(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementUShortTest()
{
ushort[] values = new ushort[] { 0, 1, ushort.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementUShort(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementIntTest()
{
int[] values = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementInt(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementUIntTest()
{
uint[] values = new uint[] { 0, 1, uint.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementUInt(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementLongTest()
{
long[] values = new long[] { 0, 1, -1, long.MinValue, long.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementLong(values[i]);
}
}

[Fact]
public static void CheckUnaryDecrementULongTest()
{
ulong[] values = new ulong[] { 0, 1, ulong.MaxValue };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementULong(values[i]);
}
}

[Fact]
public static void CheckDecrementFloatTest()
{
float[] values = new float[] { 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementFloat(values[i]);
}
}

[Fact]
public static void CheckDecrementDoubleTest()
{
double[] values = new double[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
for (int i = 0; i < values.Length; i++)
{
VerifyDecrementDouble(values[i]);
}
}

#endregion

#region Test verifiers

private static void VerifyDecrementShort(short value)
{
Expression<Func<short>> e =
Expression.Lambda<Func<short>>(
Expression.Decrement(Expression.Constant(value, typeof(short))),
Enumerable.Empty<ParameterExpression>());
Func<short> f = e.Compile();
Assert.Equal((short)(--value), f());
}

private static void VerifyDecrementUShort(ushort value)
{
Expression<Func<ushort>> e =
Expression.Lambda<Func<ushort>>(
Expression.Decrement(Expression.Constant(value, typeof(ushort))),
Enumerable.Empty<ParameterExpression>());
Func<ushort> f = e.Compile();
Assert.Equal((ushort)(--value), f());
}

private static void VerifyDecrementInt(int value)
{
Expression<Func<int>> e =
Expression.Lambda<Func<int>>(
Expression.Decrement(Expression.Constant(value, typeof(int))),
Enumerable.Empty<ParameterExpression>());
Func<int> f = e.Compile();
Assert.Equal((int)(--value), f());
}

private static void VerifyDecrementUInt(uint value)
{
Expression<Func<uint>> e =
Expression.Lambda<Func<uint>>(
Expression.Decrement(Expression.Constant(value, typeof(uint))),
Enumerable.Empty<ParameterExpression>());
Func<uint> f = e.Compile();
Assert.Equal((uint)(--value), f());
}

private static void VerifyDecrementLong(long value)
{
Expression<Func<long>> e =
Expression.Lambda<Func<long>>(
Expression.Decrement(Expression.Constant(value, typeof(long))),
Enumerable.Empty<ParameterExpression>());
Func<long> f = e.Compile();
Assert.Equal((long)(--value), f());
}

private static void VerifyDecrementULong(ulong value)
{
Expression<Func<ulong>> e =
Expression.Lambda<Func<ulong>>(
Expression.Decrement(Expression.Constant(value, typeof(ulong))),
Enumerable.Empty<ParameterExpression>());
Func<ulong> f = e.Compile();
Assert.Equal((ulong)(--value), f());
}

private static void VerifyDecrementFloat(float value)
{
Expression<Func<float>> e =
Expression.Lambda<Func<float>>(
Expression.Decrement(Expression.Constant(value, typeof(float))),
Enumerable.Empty<ParameterExpression>());
Func<float> f = e.Compile();
Assert.Equal((float)(--value), f());
}

private static void VerifyDecrementDouble(double value)
{
Expression<Func<double>> e =
Expression.Lambda<Func<double>>(
Expression.Decrement(Expression.Constant(value, typeof(double))),
Enumerable.Empty<ParameterExpression>());
Func<double> f = e.Compile();
Assert.Equal((double)(--value), f());
}

#endregion
}
}
Loading

0 comments on commit 41c4542

Please sign in to comment.