Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into StreamIO-async
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Feb 13, 2024
2 parents c2c1b3a + 9ba1dc2 commit 3cf1b56
Show file tree
Hide file tree
Showing 46 changed files with 1,035 additions and 1,462 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: windows-latest

steps:
- name: Checkout
run: git config --global core.autocrlf true
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
25 changes: 25 additions & 0 deletions .github/workflows/build_n_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build&Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: windows-latest

steps:
- name: Checkout
run: git config --global core.autocrlf true
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/local
2 changes: 1 addition & 1 deletion CSMath.Lib/CSMath.Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
39 changes: 21 additions & 18 deletions CSMath.Tests/CSMath.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net48</TargetFrameworks>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="MSTest.TestAdapter" Version="3.*" />
<PackageReference Include="MSTest.TestFramework" Version="3.*" />
<PackageReference Include="coverlet.collector" Version="6.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.extensibility.core" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<Import Project="..\CSMath\CSMath.projitems" Label="Shared" />
<Import Project="..\CSMath\CSMath.projitems" Label="Shared" />

</Project>
2 changes: 1 addition & 1 deletion CSMath.Tests/Geometry/Line2DTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Line2DTests
[Fact]
public void CreateLineTest()
{
Line2D line = LineExtensions.CreateFromPoints<Line2D, XY>(new XY(), new XY());
//Line2D line = LineExtensions.CreateFromPoints<Line2D, XY>(new XY(), new XY(1, 1));
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions CSMath.Tests/QuaternionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class QuaternionTests
[Fact]
public void CreateFromYawPitchRollTest()
{
XYZ xyz = new XYZ(90, 0, 0);
var q = Quaternion.CreateFromYawPitchRoll(MathUtils.ToRadian(xyz));
XYZ xyz = new XYZ(MathUtils.DegToRad(90), 0, 0);
Quaternion q = Quaternion.CreateFromYawPitchRoll(xyz);
}
}
}
38 changes: 10 additions & 28 deletions CSMath.Tests/VectorTestCaseFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSMath.Tests
{
Expand All @@ -21,56 +17,42 @@ public VectorTestCaseFactory(int seed)
}

public T CreatePoint<T>(double? def = null)
where T : IVector<T>, new()
where T : IVector, new()
{
T pt = new T();

int n = pt.GetComponents().Length;

List<double> c1 = new List<double>();

for (int i = 0; i < n; i++)
for (int i = 0; i < pt.Dimension; i++)
{
if (def.HasValue)
{
c1.Add(def.Value);
pt[i] = def.Value;
}
else
{
c1.Add(_random.Next(-100, 100));
pt[i] = _random.Next(-100, 100);
}
}

return pt.SetComponents(c1.ToArray());
return pt;
}

public (T, T, T) CreateOperationCase<T>(Func<double, double, double> op)
where T : IVector<T>, new()
where T : IVector, new()
{
T v1 = new T();
T v2 = new T();
T result = new T();

int n = v1.GetComponents().Length;

List<double> components1 = new List<double>();
List<double> components2 = new List<double>();
List<double> components3 = new List<double>();

for (int i = 0; i < n; i++)
for (int i = 0; i < v1.Dimension; i++)
{
var a = _random.Next(-100, 100);
var b = _random.Next(-100, 100);

components1.Add(a);
components2.Add(b);
components3.Add(op(a, b));
v1[i] = (a);
v2[i] = (b);
result[i] = (op(a, b));
}

v1 = v1.SetComponents(components1.ToArray());
v2 = v2.SetComponents(components2.ToArray());
result = result.SetComponents(components3.ToArray());

return (v1, v2, result);
}
}
Expand Down
71 changes: 68 additions & 3 deletions CSMath.Tests/VectorTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

namespace CSMath.Tests
{
public abstract class VectorTests<T>
where T : IVector<T>, new()
where T : IVector, new()
{
public VectorTestCaseFactory Factory { get; set; }

Expand Down Expand Up @@ -36,7 +37,24 @@ public void DistanceTest()

double dist = pt1.DistanceFrom(pt2);

Assert.Equal(Math.Sqrt(pt1.GetComponents().Length), dist);
Assert.Equal(Math.Sqrt(pt1.Dimension), dist);
}

[Fact]
public void CopyValuesTest()
{
var pt1 = Factory.CreatePoint<T>(0);
var pt2 = Factory.CreatePoint<T>(1);

pt1 = pt1.CopyValues(pt2);

Assert.Equal(pt2, pt1);
}


[Fact]
public virtual void ConvertTest()
{
}

[Fact]
Expand All @@ -45,7 +63,7 @@ public void SubsctractTest()
var test = Factory.CreateOperationCase<T>((o, x) => o - x);
writeTest(test);

Assert.Equal(test.Item3, test.Item1.Substract(test.Item2));
Assert.Equal(test.Item3, test.Item1.Subtract(test.Item2));
}

[Fact]
Expand Down Expand Up @@ -90,6 +108,53 @@ public void IsEqualDigitsTest()
Assert.True(pt1.IsEqual(pt2, 2));
}

[Fact]
public void IsZeroTest()
{
Assert.True(XY.Zero.IsZero());
Assert.True(XYZ.Zero.IsZero());
Assert.True(XYZM.Zero.IsZero());
}

[Fact]
public void IsNormalizedTest()
{
T v = new T();
v[0] = 1;

Assert.True(v.IsNormalized());
}

[Fact]
public virtual void IsParallelTest()
{
}

[Fact]
public void ToEnumerableTest()
{
T pt = Factory.CreatePoint<T>();
var arr = pt.ToEnumerable().ToArray();

for (int i = 0; i < pt.Dimension; i++)
{
Assert.Equal(pt[i], arr[i]);
}
}

[Fact]
public void GetAngleTest()
{
var v = new T();
var u = new T();

v[0] = 1;
u[1] = 1;

Assert.Equal(Math.PI / 2, v.AngleFrom(u));
Assert.True(v.IsPerpendicular(u));
}

protected void writeTest((T, T, T) test)
{
output.WriteLine($"Item 1 : {test.Item1}");
Expand Down
11 changes: 10 additions & 1 deletion CSMath.Tests/XYTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;

namespace CSMath.Tests
{
Expand All @@ -7,5 +8,13 @@ public class XYTest : VectorTests<XY>
public XYTest(ITestOutputHelper output) : base(output)
{
}

public override void ConvertTest()
{
XY xy = new XY(1, 1);
XYZ xyz = xy.Convert<XYZ>();

Assert.Equal(new XYZ(1, 1, 0), xyz);
}
}
}
15 changes: 14 additions & 1 deletion CSMath.Tests/XYZTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;

namespace CSMath.Tests
{
Expand All @@ -7,5 +8,17 @@ public class XYZTest : VectorTests<XYZ>
public XYZTest(ITestOutputHelper output) : base(output)
{
}

[Fact]
public void CrossTest()
{
var v = new XYZ(1, 2, 3);
var u = new XYZ(1, 5, 7);
var result = XYZ.Cross(v, u);

Assert.Equal(-1, result.X);
Assert.Equal(-4, result.Y);
Assert.Equal(3, result.Z);
}
}
}
3 changes: 3 additions & 0 deletions CSMath/CSMath.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
<Compile Include="$(MSBuildThisFileDirectory)MathUtils.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Quaternion.cs" />
<Compile Include="$(MSBuildThisFileDirectory)VectorExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XY.operators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XY.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XYZ.operators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XYZ.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XYZM.operators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)XYZM.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions CSMath/Geometry/LineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public static T CreateFromPoints<T, R>(R pt1, R pt2)
where T : ILine<R>
where R : IVector
{

throw new NotImplementedException();
}

Expand All @@ -21,11 +20,10 @@ public static bool IsPointOnLine<T>(this ILine<T> line, T point)
where T : IVector
{
double lambda = 0;
double[] components = point.GetComponents();

for (int i = 0; i < components.Length; ++i)
for (int i = 0; i < point.Dimension; ++i)
{
var value = (components[i] - line.Origin.GetComponents()[i]) / line.Direction.GetComponents()[i];
var value = (point[i] - line.Origin[i]) / line.Direction[i];
if (i != 0 && (value != lambda))
{
return false;
Expand Down
Loading

0 comments on commit 3cf1b56

Please sign in to comment.