Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/guma/refactor sets #318

Merged
merged 3 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/GShark.Test.XUnit/Core/CollectionHelpersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using FluentAssertions;
using GShark.Core;
using GShark.Geometry;
using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;

namespace GShark.Test.XUnit.Core
{
public class CollectionHelpersTests
{
private readonly ITestOutputHelper _testOutput;

public CollectionHelpersTests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
}

public static IEnumerable<object[]> DataToRepeat =>
new List<object[]>
{
new object[] { 10, 7},
new object[] { new Vector(){ 14, -12, 7}, 5},
new object[] { 2.7, 8 },
new object[] { 1.0, 0 }
};

[Theory]
[MemberData(nameof(DataToRepeat))]
public void It_Returns_A_Set_Of_Repeated_Data_Of_A_Specific_Length(object data, int length)
{
// Act
List<object> repeatedData = CollectionHelpers.RepeatData(data, length);

// Assert
repeatedData.Should().HaveCount(length);
repeatedData.Should().BeEquivalentTo(new List<object>(repeatedData));
}

[Fact]
public void RepeatData_Throws_An_Exception_If_The_Value_Is_Negative_Or_Zero()
{
// Act
Func<object> resultFunction = () => CollectionHelpers.RepeatData(5, -1);

// Assert
resultFunction.Should().Throw<Exception>().WithMessage("Length can not be negative.");
}


[Fact]
public void It_Transposes_A_2D_List_Of_Points()
{
// Arrange
List<List<Point3>> pts = new List<List<Point3>>
{
new()
{
new Point3( 0d, -10d, 0),
new Point3( 10d, -10d, 10)
},
new()
{
new Point3( 0d, -30d, 0),
new Point3( 10d, -30d, 0)

},
new()
{
new Point3( 0d, 0d, 50),
new Point3( 10d, 0d, 0)
}
};

// Act
List<List<Point3>> transposedPointData = CollectionHelpers.Transpose2DArray(pts);

// Assert
transposedPointData.Count.Should().Be(2);
transposedPointData[0].Count.Should().Be(3);
transposedPointData[0][2].Should().BeEquivalentTo(pts[2][0]);
transposedPointData[1][2].Should().BeEquivalentTo(pts[2][1]);
}
}
}
27 changes: 26 additions & 1 deletion src/GShark.Test.XUnit/Core/IntervalTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using FluentAssertions;
using System.Collections.Generic;
using FluentAssertions;
using GShark.Core;
using Xunit;

namespace GShark.Test.XUnit.Core
{
public class IntervalTests
{
public static IEnumerable<object[]> RangesToBeDefined =>
new List<object[]>
{
new object[] { new Interval(0, 1), 4},
new object[] { new Interval(2, 30), 3},
new object[] { new Interval(-10, 30), 6},
new object[] { new Interval(1, 10), 0}
};

[Fact]
public void It_Returns_An_Interval()
{
Expand Down Expand Up @@ -118,5 +128,20 @@ public void It_Returns_The_Minimum_Value_In_The_Interval()
//Assert
interval.Min.Should().Be(-0.5);
}

[Theory]
[MemberData(nameof(RangesToBeDefined))]
public void It_Divides_An_Interval_In_Equal_Parts(Interval interval, int step)
{
// Arrange
IList<double> linearSpace = Interval.Divide(interval, step);

// Act
_ = string.Join(',', linearSpace);

// Assert
linearSpace.Should().NotBeNull();
linearSpace.Should().BeEquivalentTo(new List<double>(linearSpace));
}
}
}
234 changes: 0 additions & 234 deletions src/GShark.Test.XUnit/Core/SetsTests.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/GShark.Test.XUnit/Geometry/NurbsCurveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void It_Returns_A_NurbsCurve()
// Assert
nurbsCurve.Should().NotBeNull();
nurbsCurve.Degree.Should().Be(3);
nurbsCurve.Weights.Should().BeEquivalentTo(Sets.RepeatData(1.0, 6));
nurbsCurve.Weights.Should().BeEquivalentTo(CollectionHelpers.RepeatData(1.0, 6));
}

[Fact]
Expand Down Expand Up @@ -108,7 +108,7 @@ public void It_Creates_A_NurbsCurve_From_ControlPoints_And_Degree()
// Assert
nurbsCurve.Should().NotBeNull();
nurbsCurve.Degree.Should().Be(2);
nurbsCurve.Weights.Should().BeEquivalentTo(Sets.RepeatData(1.0, CurveData.pts.Count));
nurbsCurve.Weights.Should().BeEquivalentTo(CollectionHelpers.RepeatData(1.0, CurveData.pts.Count));
nurbsCurve.Knots.Should().BeEquivalentTo(new KnotVector(CurveData.degree, CurveData.pts.Count));
}

Expand Down
Loading