-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/increase test coverage v3 (#463)
- Loading branch information
Showing
5 changed files
with
155 additions
and
75 deletions.
There are no files selected for viewing
Binary file not shown.
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,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using GsaGH.Components; | ||
using GsaGH.Helpers.GH; | ||
using GsaGH.Helpers.Import; | ||
using GsaGHTests.Helpers; | ||
using OasysGH.Components; | ||
using Rhino.Geometry; | ||
using Xunit; | ||
|
||
namespace GsaGHTests.Helpers.Export.GH { | ||
[Collection("GrasshopperFixture collection")] | ||
public class RhinoConversionsTests { | ||
[Fact] | ||
public void BuildArcLineCurveFromPtsAndTopoTypeTestArc1d() { | ||
var topolist = new List<Point3d>() { | ||
new Point3d(0, 0, 0), | ||
new Point3d(2, 2, 0), | ||
new Point3d(4, 0, 0) | ||
}; | ||
var topotype = new List<string>() { | ||
string.Empty, | ||
"A", | ||
string.Empty, | ||
}; | ||
|
||
PolyCurve crv = RhinoConversions.BuildArcLineCurveFromPtsAndTopoType(topolist, topotype); | ||
Assert.True(crv != null); | ||
Assert.True(crv.IsArc()); | ||
} | ||
|
||
[Fact] | ||
public void ConvertMem1dCrvTest() { | ||
var topolist = new List<Point3d>() { | ||
new Point3d(0, 0, 0), | ||
new Point3d(2, 2, 0), | ||
new Point3d(4, 0, 0) | ||
}; | ||
var crvs = new PolyCurve(); | ||
crvs.Append(new Arc(topolist[0], topolist[1], topolist[2])); | ||
|
||
Tuple<PolyCurve, List<Point3d>, List<string>> mem1d = RhinoConversions.ConvertMem1dCrv( | ||
crvs); | ||
|
||
Assert.True(mem1d.Item1.IsArc()); | ||
Assert.Equal(3, mem1d.Item2.Count); | ||
TestPoint(topolist[0], mem1d.Item2[0]); | ||
TestPoint(topolist[1], mem1d.Item2[1]); | ||
TestPoint(topolist[2], mem1d.Item2[2]); | ||
Assert.Equal(string.Empty, mem1d.Item3[0]); | ||
Assert.Equal("A", mem1d.Item3[1]); | ||
Assert.Equal(string.Empty, mem1d.Item3[2]); | ||
} | ||
|
||
private void TestPoint(Point3d expected, Point3d actual) { | ||
Assert.Equal(expected.X, actual.X, 10); | ||
Assert.Equal(expected.Y, actual.Y, 10); | ||
Assert.Equal(expected.Z, actual.Z, 10); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using GsaGH.Helpers.GsaApi; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace GsaGHTests.Helpers.GsaApi { | ||
public class ValueHelpersTests { | ||
[Theory] | ||
[InlineData(1.23456789, 4, "1.235")] | ||
[InlineData(123456, 4, "123500")] | ||
[InlineData(0.000123456, 4, "0.0001235")] | ||
[InlineData(-1.23456789, 4, "-1.235")] | ||
[InlineData(-123456, 4, "-123500")] | ||
[InlineData(-0.000123456, 4, "-0.0001235")] | ||
public void RoundToSignificantDigitsTest(double value, int digits, string expected) { | ||
double d = ResultHelper.RoundToSignificantDigits(value, digits); | ||
Assert.Equal(expected, d.ToString()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, 0, 0, 0)] | ||
[InlineData(74, 26, 75, 25)] | ||
[InlineData(7499, 26, 8000, 0)] | ||
[InlineData(24, 15, 25, 15)] | ||
[InlineData(0, -24, 0, -25)] | ||
public void SmartRounderTests(double max, double min, double expectedMax, double expectedMin) { | ||
List<double> vals = ResultHelper.SmartRounder(max, min); | ||
Assert.Equal(expectedMax, vals[0]); | ||
Assert.Equal(expectedMin, vals[1]); | ||
} | ||
} | ||
} |
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,62 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using Grasshopper.Kernel; | ||
using Xunit; | ||
|
||
namespace IntegrationTests.Components { | ||
[Collection("GrasshopperFixture collection")] | ||
public class Elem2dFromBrepTests { | ||
public static GH_Document Document { | ||
get { | ||
if (document == null) { | ||
document = OpenDocument(); | ||
} | ||
|
||
return document; | ||
} | ||
} | ||
private static GH_Document document = null; | ||
|
||
[Fact] | ||
public void NoRuntimeErrorTest() { | ||
Helper.TestNoRuntimeMessagesInDocument(Document, GH_RuntimeMessageLevel.Error); | ||
Helper.TestNoRuntimeMessagesInDocument(Document, GH_RuntimeMessageLevel.Warning); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Types", new string[] { | ||
"QUAD8", | ||
"TRI6" | ||
})] | ||
[InlineData("TriQuadCounts", new int[] { | ||
0, | ||
100, | ||
540, | ||
})] | ||
[InlineData("Inclusions", new int[] { | ||
1, | ||
14, | ||
})] | ||
public void Test(string groupIdentifier, object expected) { | ||
IGH_Param param = Helper.FindParameter(Document, groupIdentifier); | ||
Helper.TestGhPrimitives(param, expected); | ||
} | ||
|
||
private static GH_Document OpenDocument() { | ||
Type thisClass = MethodBase.GetCurrentMethod().DeclaringType; | ||
string fileName = thisClass.Name + ".gh"; | ||
fileName = fileName.Replace(thisClass.Namespace, string.Empty).Replace("Tests", string.Empty); | ||
|
||
string solutiondir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent | ||
.Parent.FullName; | ||
string path = Path.Combine(new string[] { | ||
solutiondir, | ||
"ExampleFiles", | ||
"Components", | ||
}); | ||
|
||
return Helper.CreateDocument(Path.Combine(path, fileName)); | ||
} | ||
} | ||
} |