-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddTests | ||
{ | ||
public static TheoryData<int> AddData | ||
=> new() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Short_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (short)(value + 1)).ToArray(); | ||
var result = new short[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (short)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<short>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => value + 1).ToArray(); | ||
var result = new int[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => value + value + 1).ToArray(); | ||
|
||
// act | ||
Tensor.Add<int>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (long)(value + 1)).ToArray(); | ||
var result = new long[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (long)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<long>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (float)(value + 1)).ToArray(); | ||
var result = new float[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (float)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<float>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var y = Enumerable.Range(0, count).Select(value => (double)(value + 1)).ToArray(); | ||
var result = new double[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (double)(value + value + 1)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<double>(x, y, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class AddValueTests | ||
{ | ||
public const int constValue = 42; | ||
|
||
public static TheoryData<int> AddData | ||
=> new() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Value_Short_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var result = new short[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (short)(value + constValue)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<short>(x, constValue, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Value_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).ToArray(); | ||
var result = new int[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => value + constValue).ToArray(); | ||
|
||
// act | ||
Tensor.Add<int>(x, constValue, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Value_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var result = new long[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (long)(value + constValue)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<long>(x, constValue, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Value_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var result = new float[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (float)(value + constValue)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<float>(x, constValue, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(AddData))] | ||
public void Add_Value_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var x = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var result = new double[count]; | ||
var expected = Enumerable.Range(0, count).Select(value => (double)(value + constValue)).ToArray(); | ||
|
||
// act | ||
Tensor.Add<double>(x, constValue, result); | ||
|
||
// assert | ||
result.Should().Equal(expected); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/NetFabric.Numerics.Tensors.UnitTests/NetFabric.Numerics.Tensors.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<RootNamespace>NetFabric.Numerics.Tensors.UnitsTests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="FluentAssertions" /> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.6.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NetFabric.Numerics.Tensors\NetFabric.Numerics.Tensors.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Linq; | ||
|
||
namespace NetFabric.Numerics.Tensors.UnitTests; | ||
|
||
public class SumTests | ||
{ | ||
public static TheoryData<int> SumData | ||
=> new() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 }; | ||
|
||
[Theory] | ||
[MemberData(nameof(SumData))] | ||
public void Sum_Short_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count).Select(value => (short)value).ToArray(); | ||
var expected = Enumerable.Range(0, count).Sum(); | ||
|
||
// act | ||
var result = Tensor.Sum<short>(source); | ||
|
||
// assert | ||
result.Should().Be((short)expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SumData))] | ||
public void Sum_Int_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count).ToArray(); | ||
var expected = source.Sum(); | ||
|
||
// act | ||
var result = Tensor.Sum<int>(source); | ||
|
||
// assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SumData))] | ||
public void Sum_Long_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count).Select(value => (long)value).ToArray(); | ||
var expected = source.Sum(); | ||
|
||
// act | ||
var result = Tensor.Sum<long>(source); | ||
|
||
// assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SumData))] | ||
public void Sum_Float_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count).Select(value => (float)value).ToArray(); | ||
var expected = source.Sum(); | ||
|
||
// act | ||
var result = Tensor.Sum<float>(source); | ||
|
||
// assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SumData))] | ||
public void Sum_Double_Should_Succeed(int count) | ||
{ | ||
// arrange | ||
var source = Enumerable.Range(0, count).Select(value => (double)value).ToArray(); | ||
var expected = source.Sum(); | ||
|
||
// act | ||
var result = Tensor.Sum<double>(source); | ||
|
||
// assert | ||
result.Should().Be(expected); | ||
} | ||
|
||
} |