Skip to content

Commit

Permalink
Adding tests covering the vector Sin, Cos, and SinCos APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jul 13, 2024
1 parent 5e7012b commit 19183c5
Show file tree
Hide file tree
Showing 11 changed files with 576 additions and 203 deletions.
246 changes: 245 additions & 1 deletion src/libraries/Common/tests/System/GenericMathTestMemberData.cs

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4536,6 +4536,22 @@ private static void TestCreateSequence<T>(T start, T step)
}
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void CosDoubleTest(double value, double expectedResult, double variance)
{
Vector<double> actualResult = Vector.Cos(Vector.Create(value));
AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosCosgleTest(float value, float expectedResult, float variance)
{
Vector<float> actualResult = Vector.Cos(Vector.Create(value));
AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))]
public void ExpDoubleTest(double value, double expectedResult, double variance)
Expand Down Expand Up @@ -4959,6 +4975,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector.Create(expectedResult), actualResult, Vector<float>.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinDoubleTest(double value, double expectedResult, double variance)
{
Vector<double> actualResult = Vector.Sin(Vector.Create(value));
AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector<float> actualResult = Vector.Sin(Vector.Create(value));
AssertEqual(Vector.Create(expectedResult), actualResult, Vector.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos)
{
(Vector<double> resultSin, Vector<double> resultCos) = Vector.SinCos(Vector.Create(value));
AssertEqual(Vector.Create(expectedResultSin), resultSin, Vector.Create(allowedVarianceSin));
AssertEqual(Vector.Create(expectedResultCos), resultCos, Vector.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector<float> resultSin, Vector<float> resultCos) = Vector.SinCos(Vector.Create(value));
AssertEqual(Vector.Create(expectedResultSin), resultSin, Vector.Create(allowedVarianceSin));
AssertEqual(Vector.Create(expectedResultCos), resultCos, Vector.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateDoubleTest(double value, double expectedResult)
Expand Down
25 changes: 25 additions & 0 deletions src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,14 @@ private class EmbeddedVectorObject
public Vector2 FieldVector;
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosSingleTest(float value, float expectedResult, float variance)
{
Vector2 actualResult = Vector2.Cos(Vector2.Create(value));
AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))]
public void ExpSingleTest(float value, float expectedResult, float variance)
Expand Down Expand Up @@ -1474,6 +1482,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector2 actualResult = Vector2.Sin(Vector2.Create(value));
AssertEqual(Vector2.Create(expectedResult), actualResult, Vector2.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector2 resultSin, Vector2 resultCos) = Vector2.SinCos(Vector2.Create(value));
AssertEqual(Vector2.Create(expectedResultSin), resultSin, Vector2.Create(allowedVarianceSin));
AssertEqual(Vector2.Create(expectedResultCos), resultCos, Vector2.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateSingleTest(float value, float expectedResult)
Expand Down
25 changes: 25 additions & 0 deletions src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,14 @@ private class EmbeddedVectorObject
public Vector3 FieldVector;
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosSingleTest(float value, float expectedResult, float variance)
{
Vector3 actualResult = Vector3.Cos(Vector3.Create(value));
AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))]
public void ExpSingleTest(float value, float expectedResult, float variance)
Expand Down Expand Up @@ -1524,6 +1532,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector3 actualResult = Vector3.Sin(Vector3.Create(value));
AssertEqual(Vector3.Create(expectedResult), actualResult, Vector3.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector3 resultSin, Vector3 resultCos) = Vector3.SinCos(Vector3.Create(value));
AssertEqual(Vector3.Create(expectedResultSin), resultSin, Vector3.Create(allowedVarianceSin));
AssertEqual(Vector3.Create(expectedResultCos), resultCos, Vector3.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateSingleTest(float value, float expectedResult)
Expand Down
25 changes: 25 additions & 0 deletions src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,14 @@ public struct Level7
}
#pragma warning restore 0169

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosSingleTest(float value, float expectedResult, float variance)
{
Vector4 actualResult = Vector4.Cos(Vector4.Create(value));
AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpSingle), MemberType = typeof(GenericMathTestMemberData))]
public void ExpSingleTest(float value, float expectedResult, float variance)
Expand Down Expand Up @@ -1899,6 +1907,23 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector4 actualResult = Vector4.Sin(Vector4.Create(value));
AssertEqual(Vector4.Create(expectedResult), actualResult, Vector4.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector4 resultSin, Vector4 resultCos) = Vector4.SinCos(Vector4.Create(value));
AssertEqual(Vector4.Create(expectedResultSin), resultSin, Vector4.Create(allowedVarianceSin));
AssertEqual(Vector4.Create(expectedResultCos), resultCos, Vector4.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateSingle), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateSingleTest(float value, float expectedResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4824,6 +4824,22 @@ private static void TestCreateSequence<T>(T start, T step)
}
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void CosDoubleTest(double value, double expectedResult, double variance)
{
Vector128<double> actualResult = Vector128.Cos(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosSingleTest(float value, float expectedResult, float variance)
{
Vector128<float> actualResult = Vector128.Cos(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))]
public void ExpDoubleTest(double value, double expectedResult, double variance)
Expand Down Expand Up @@ -5329,6 +5345,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128<float>.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinDoubleTest(double value, double expectedResult, double variance)
{
Vector128<double> actualResult = Vector128.Sin(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector128<float> actualResult = Vector128.Sin(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos)
{
(Vector128<double> resultSin, Vector128<double> resultCos) = Vector128.SinCos(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResultSin), resultSin, Vector128.Create(allowedVarianceSin));
AssertEqual(Vector128.Create(expectedResultCos), resultCos, Vector128.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector128<float> resultSin, Vector128<float> resultCos) = Vector128.SinCos(Vector128.Create(value));
AssertEqual(Vector128.Create(expectedResultSin), resultSin, Vector128.Create(allowedVarianceSin));
AssertEqual(Vector128.Create(expectedResultCos), resultCos, Vector128.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateDoubleTest(double value, double expectedResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5840,6 +5840,22 @@ private static void TestCreateSequence<T>(T start, T step)
}
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void CosDoubleTest(double value, double expectedResult, double variance)
{
Vector256<double> actualResult = Vector256.Cos(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.CosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void CosSingleTest(float value, float expectedResult, float variance)
{
Vector256<float> actualResult = Vector256.Cos(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.ExpDouble), MemberType = typeof(GenericMathTestMemberData))]
public void ExpDoubleTest(double value, double expectedResult, double variance)
Expand Down Expand Up @@ -6345,6 +6361,40 @@ public void RoundToEvenSingleTest(float value, float expectedResult)
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256<float>.Zero);
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinDoubleTest(double value, double expectedResult, double variance)
{
Vector256<double> actualResult = Vector256.Sin(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinSingleTest(float value, float expectedResult, float variance)
{
Vector256<float> actualResult = Vector256.Sin(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosDouble), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosDoubleTest(double value, double expectedResultSin, double expectedResultCos, double allowedVarianceSin, double allowedVarianceCos)
{
(Vector256<double> resultSin, Vector256<double> resultCos) = Vector256.SinCos(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResultSin), resultSin, Vector256.Create(allowedVarianceSin));
AssertEqual(Vector256.Create(expectedResultCos), resultCos, Vector256.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.SinCosSingle), MemberType = typeof(GenericMathTestMemberData))]
public void SinCosSingleTest(float value, float expectedResultSin, float expectedResultCos, float allowedVarianceSin, float allowedVarianceCos)
{
(Vector256<float> resultSin, Vector256<float> resultCos) = Vector256.SinCos(Vector256.Create(value));
AssertEqual(Vector256.Create(expectedResultSin), resultSin, Vector256.Create(allowedVarianceSin));
AssertEqual(Vector256.Create(expectedResultCos), resultCos, Vector256.Create(allowedVarianceCos));
}

[Theory]
[MemberData(nameof(GenericMathTestMemberData.TruncateDouble), MemberType = typeof(GenericMathTestMemberData))]
public void TruncateDoubleTest(double value, double expectedResult)
Expand Down
Loading

0 comments on commit 19183c5

Please sign in to comment.