Skip to content

Commit

Permalink
Adding generic math tests for integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jul 9, 2021
1 parent 9d8b4e2 commit 0420af8
Show file tree
Hide file tree
Showing 15 changed files with 14,169 additions and 111 deletions.
22 changes: 19 additions & 3 deletions src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<FeatureGenericMath>true</FeatureGenericMath>
<NoWarn>$(NoWarn),1718,SYSLIB0013</NoWarn>
<TestRuntime>true</TestRuntime>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(FeatureGenericMath)' == 'true'">$(DefineConstants);FEATURE_GENERIC_MATH</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)System\EnumTypes.cs"
Link="Common\System\EnumTypes.cs" />
Expand Down Expand Up @@ -81,15 +85,13 @@
<Compile Include="System\FormattableStringTests.cs" />
<Compile Include="System\FormatExceptionTests.cs" />
<Compile Include="System\GCTests.cs" />
<Compile Include="System\GenericMathTests.cs" />
<Compile Include="System\GuidTests.cs" />
<Compile Include="System\HalfTests.cs" />
<Compile Include="System\HandleTests.cs" />
<Compile Include="System\HashCodeTests.cs" />
<Compile Include="System\IndexOutOfRangeExceptionTests.cs" />
<Compile Include="System\IndexTests.cs" />
<Compile Include="System\Int16Tests.cs" />
<Compile Include="System\Int32GenericMathTests.cs" />
<Compile Include="System\Int32Tests.cs" />
<Compile Include="System\Int64Tests.cs" />
<Compile Include="System\IntPtrTests.cs" />
Expand Down Expand Up @@ -247,6 +249,20 @@
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
<Compile Include="System\ExitCodeTests.Unix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureGenericMath)' == 'true'">
<Compile Include="System\ByteTests.GenericMath.cs" />
<Compile Include="System\CharTests.GenericMath.cs" />
<Compile Include="System\GenericMathHelpers.cs" />
<Compile Include="System\Int16Tests.GenericMath.cs" />
<Compile Include="System\Int32Tests.GenericMath.cs" />
<Compile Include="System\Int64Tests.GenericMath.cs" />
<Compile Include="System\IntPtrTests.GenericMath.cs" />
<Compile Include="System\SByteTests.GenericMath.cs" />
<Compile Include="System\UInt16Tests.GenericMath.cs" />
<Compile Include="System\UInt32Tests.GenericMath.cs" />
<Compile Include="System\UInt64Tests.GenericMath.cs" />
<Compile Include="System\UIntPtrTests.GenericMath.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="System\Reflection\SignatureTypes.cs" />
<Compile Include="System\Runtime\CompilerServices\CallerArgumentExpressionAttributeTests.cs" />
Expand Down
1,175 changes: 1,175 additions & 0 deletions src/libraries/System.Runtime/tests/System/ByteTests.GenericMath.cs

Large diffs are not rendered by default.

1,057 changes: 1,057 additions & 0 deletions src/libraries/System.Runtime/tests/System/CharTests.GenericMath.cs

Large diffs are not rendered by default.

228 changes: 228 additions & 0 deletions src/libraries/System.Runtime/tests/System/GenericMathHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Runtime.Versioning;

namespace System.Tests
{
[RequiresPreviewFeatures]
public static class AdditionOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IAdditionOperators<TSelf, TOther, TResult>
{
public static TResult op_Addition(TSelf left, TOther right) => left + right;
}

[RequiresPreviewFeatures]
public static class AdditiveIdentityHelper<TSelf, TResult>
where TSelf : IAdditiveIdentity<TSelf, TResult>
{
public static TResult AdditiveIdentity => TSelf.AdditiveIdentity;
}

[RequiresPreviewFeatures]
public static class BinaryIntegerHelper<TSelf>
where TSelf : IBinaryInteger<TSelf>
{
public static TSelf LeadingZeroCount(TSelf value) => TSelf.LeadingZeroCount(value);

public static TSelf PopCount(TSelf value) => TSelf.PopCount(value);

public static TSelf RotateLeft(TSelf value, int rotateAmount) => TSelf.RotateLeft(value, rotateAmount);

public static TSelf RotateRight(TSelf value, int rotateAmount) => TSelf.RotateRight(value, rotateAmount);

public static TSelf TrailingZeroCount(TSelf value) => TSelf.TrailingZeroCount(value);
}

[RequiresPreviewFeatures]
public static class BinaryNumberHelper<TSelf>
where TSelf : IBinaryNumber<TSelf>
{
public static bool IsPow2(TSelf value) => TSelf.IsPow2(value);

public static TSelf Log2(TSelf value) => TSelf.Log2(value);
}

[RequiresPreviewFeatures]
public static class BitwiseOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IBitwiseOperators<TSelf, TOther, TResult>
{
public static TResult op_BitwiseAnd(TSelf left, TOther right) => left & right;

public static TResult op_BitwiseOr(TSelf left, TOther right) => left | right;

public static TResult op_ExclusiveOr(TSelf left, TOther right) => left ^ right;

public static TResult op_OnesComplement(TSelf value) => ~value;
}

[RequiresPreviewFeatures]
public static class ComparisonOperatorsHelper<TSelf, TOther>
where TSelf : IComparisonOperators<TSelf, TOther>
{
public static bool op_GreaterThan(TSelf left, TOther right) => left > right;

public static bool op_GreaterThanOrEqual(TSelf left, TOther right) => left >= right;

public static bool op_LessThan(TSelf left, TOther right) => left < right;

public static bool op_LessThanOrEqual(TSelf left, TOther right) => left <= right;
}

[RequiresPreviewFeatures]
public static class DecrementOperatorsHelper<TSelf>
where TSelf : IDecrementOperators<TSelf>
{
public static TSelf op_Decrement(TSelf value) => --value;
}

[RequiresPreviewFeatures]
public static class DivisionOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IDivisionOperators<TSelf, TOther, TResult>
{
public static TResult op_Division(TSelf left, TOther right) => left / right;
}

[RequiresPreviewFeatures]
public static class EqualityOperatorsHelper<TSelf, TOther>
where TSelf : IEqualityOperators<TSelf, TOther>
{
public static bool op_Equality(TSelf left, TOther right) => left == right;

public static bool op_Inequality(TSelf left, TOther right) => left != right;
}

[RequiresPreviewFeatures]
public static class IncrementOperatorsHelper<TSelf>
where TSelf : IIncrementOperators<TSelf>
{
public static TSelf op_Increment(TSelf value) => ++value;
}

[RequiresPreviewFeatures]
public static class ModulusOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IModulusOperators<TSelf, TOther, TResult>
{
public static TResult op_Modulus(TSelf left, TOther right) => left % right;
}

[RequiresPreviewFeatures]
public static class MultiplyOperatorsHelper<TSelf, TOther, TResult>
where TSelf : IMultiplyOperators<TSelf, TOther, TResult>
{
public static TResult op_Multiply(TSelf left, TOther right) => left * right;
}

[RequiresPreviewFeatures]
public static class MinMaxValueHelper<TSelf>
where TSelf : IMinMaxValue<TSelf>
{
public static TSelf MaxValue => TSelf.MaxValue;

public static TSelf MinValue => TSelf.MinValue;
}

[RequiresPreviewFeatures]
public static class MultiplicativeIdentityHelper<TSelf, TResult>
where TSelf : IMultiplicativeIdentity<TSelf, TResult>
{
public static TResult MultiplicativeIdentity => TSelf.MultiplicativeIdentity;
}

[RequiresPreviewFeatures]
public static class NumberHelper<TSelf>
where TSelf : INumber<TSelf>
{
public static TSelf One => TSelf.One;

public static TSelf Zero => TSelf.Zero;

public static TSelf Abs(TSelf value) => TSelf.Abs(value);

public static TSelf Clamp(TSelf value, TSelf min, TSelf max) => TSelf.Clamp(value, min, max);

public static TSelf Create<TOther>(TOther value)
where TOther : INumber<TOther> => TSelf.Create<TOther>(value);

public static TSelf CreateSaturating<TOther>(TOther value)
where TOther : INumber<TOther> => TSelf.CreateSaturating<TOther>(value);

public static TSelf CreateTruncating<TOther>(TOther value)
where TOther : INumber<TOther> => TSelf.CreateTruncating<TOther>(value);

public static (TSelf Quotient, TSelf Remainder) DivRem(TSelf left, TSelf right) => TSelf.DivRem(left, right);

public static TSelf Max(TSelf x, TSelf y) => TSelf.Max(x, y);

public static TSelf Min(TSelf x, TSelf y) => TSelf.Min(x, y);

public static TSelf Parse(string s, NumberStyles style, IFormatProvider provider) => TSelf.Parse(s, style, provider);

public static TSelf Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider) => TSelf.Parse(s, style, provider);

public static TSelf Sign(TSelf value) => TSelf.Sign(value);

public static bool TryCreate<TOther>(TOther value, out TSelf result)
where TOther : INumber<TOther> => TSelf.TryCreate<TOther>(value, out result);

public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, style, provider, out result);

public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, style, provider, out result);
}

[RequiresPreviewFeatures]
public static class ParseableHelper<TSelf>
where TSelf : IParseable<TSelf>
{
public static TSelf Parse(string s, IFormatProvider provider) => TSelf.Parse(s, provider);

public static bool TryParse(string s, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, provider, out result);
}

[RequiresPreviewFeatures]
public static class ShiftOperatorsHelper<TSelf, TResult>
where TSelf : IShiftOperators<TSelf, TResult>
{
public static TResult op_LeftShift(TSelf value, int shiftAmount) => value << shiftAmount;

public static TResult op_RightShift(TSelf value, int shiftAmount) => value >> shiftAmount;
}

[RequiresPreviewFeatures]
public static class SignedNumberHelper<TSelf>
where TSelf : ISignedNumber<TSelf>
{
public static TSelf NegativeOne => TSelf.NegativeOne;
}

[RequiresPreviewFeatures]
public static class SpanParseableHelper<TSelf>
where TSelf : ISpanParseable<TSelf>
{
public static TSelf Parse(ReadOnlySpan<char> s, IFormatProvider provider) => TSelf.Parse(s, provider);

public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider provider, out TSelf result) => TSelf.TryParse(s, provider, out result);
}

[RequiresPreviewFeatures]
public static class SubtractionOperatorsHelper<TSelf, TOther, TResult>
where TSelf : ISubtractionOperators<TSelf, TOther, TResult>
{
public static TResult op_Subtraction(TSelf left, TOther right) => left - right;
}

[RequiresPreviewFeatures]
public static class UnaryNegationOperatorsHelper<TSelf, TResult>
where TSelf : IUnaryNegationOperators<TSelf, TResult>
{
public static TResult op_UnaryNegation(TSelf value) => -value;
}

[RequiresPreviewFeatures]
public static class UnaryPlusOperatorsHelper<TSelf, TResult>
where TSelf : IUnaryPlusOperators<TSelf, TResult>
{
public static TResult op_UnaryPlus(TSelf value) => +value;
}
}
73 changes: 0 additions & 73 deletions src/libraries/System.Runtime/tests/System/GenericMathTests.cs

This file was deleted.

Loading

0 comments on commit 0420af8

Please sign in to comment.