Skip to content

Commit

Permalink
Merge pull request #420 from DomCR/improve-coverage
Browse files Browse the repository at this point in the history
Coverage test
  • Loading branch information
DomCR authored Aug 15, 2024
2 parents 62f2865 + 30c24f0 commit 512392c
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 98 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=lcov --no-build --verbosity normal ACadSharp.Tests/
- name: Build and Test ACadSharp
run: |
dotnet restore
dotnet build --no-restore
dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=lcov --no-build --verbosity normal ACadSharp.Tests/
- name: Build and Test Submodules
working-directory: CSUtilities
run: |
dotnet restore
dotnet build --no-restore
dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=lcov --no-build --verbosity normal CSUtilities.Tests/
dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=lcov --no-build --verbosity normal CSMath.Tests/
- name: Coveralls action
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ github.token }}
path-to-lcov: ACadSharp.Tests/TestResults/coverage.info
files: ACadSharp.Tests/TestResults/coverage.info CSUtilities/CSUtilities.Tests/TestResults/coverage.info CSUtilities/CSMath.Tests/TestResults/coverage.info
64 changes: 34 additions & 30 deletions ACadSharp.Tests/ACadSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<!-- Enable the MSTest runner, this is an opt-in feature -->
<EnableMSTestRunner>true</EnableMSTestRunner>
<!-- We need to produce an executable and not a DLL -->
<OutputType>Exe</OutputType>
<!-- Enable the MSTest runner, this is an opt-in feature -->
<EnableMSTestRunner>true</EnableMSTestRunner>
<!-- We need to produce an executable and not a DLL -->
<OutputType>Exe</OutputType>

<IsPackable>false</IsPackable>
</PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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.0.2">
<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>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="MSTest.TestAdapter" Version="3.*" />
<PackageReference Include="MSTest.TestFramework" Version="3.*" />
<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>

<ItemGroup>
<ProjectReference Include="..\ACadSharp\ACadSharp.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ACadSharp\ACadSharp.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="TestResults\" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions ACadSharp.Tests/DxfPropertyTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
using ACadSharp.Entities;
using CSMath;
using System;
using System.Reflection;
using Xunit;

namespace ACadSharp.Tests
{
public class DxfPropertyTests
{
[Fact]
public void Constructor()
{
DxfClassMap map = DxfClassMap.Create<Line>();
PropertyInfo dxfProp = typeof(Line).GetProperty(nameof(Line.StartPoint));
PropertyInfo info = typeof(Line).GetProperty(nameof(Line.SubclassMarker));

Assert.Throws<ArgumentException>(() => new DxfProperty(-7, dxfProp));
Assert.Throws<ArgumentException>(() => new DxfProperty(-7, info));
Assert.Throws<ArgumentNullException>(() => new DxfProperty(-7, null));
}

[Fact]
public void SetXYValueTest()
{
Expand Down
17 changes: 17 additions & 0 deletions ACadSharp.Tests/Entities/ArcTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ACadSharp.Entities;
using ACadSharp.Tests.Common;
using CSMath;
using System;
using Xunit;
Expand Down Expand Up @@ -27,5 +28,21 @@ public void CreateFromBulgeTest()
Assert.Equal(0, arc.StartAngle);
Assert.Equal(Math.PI / 2, arc.EndAngle);
}

[Fact]
public void GetEndVerticesTest()
{
XY start = new XY(1, 0);
XY end = new XY(0, 1);
// 90 degree bulge
double bulge = Math.Tan(Math.PI / (2 * 4));

Arc arc = Arc.CreateFromBulge(start, end, bulge);

arc.GetEndVertices(out XY s1, out XY e2);

AssertUtils.AreEqual<XY>(start, s1, "start point");
AssertUtils.AreEqual<XY>(end, e2, "end point");
}
}
}
2 changes: 1 addition & 1 deletion ACadSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
ProjectSection(SolutionItems) = preProject
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\build_n_test.yml = .github\workflows\build_n_test.yml
publish.yml = publish.yml
.github\workflows\coveralls.yml = .github\workflows\coveralls.yml
publish.yml = publish.yml
.github\workflows\wiki-gen.yml = .github\workflows\wiki-gen.yml
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public CadDocument Document
private CadDictionary _xdictionary = null;

/// <summary>
/// Default constructor
/// Default constructor.
/// </summary>
public CadObject() { }

Expand Down
56 changes: 33 additions & 23 deletions ACadSharp/Entities/Arc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using CSMath;
using System;
using System.Collections.Generic;

namespace ACadSharp.Entities
{
Expand Down Expand Up @@ -82,39 +83,48 @@ public static Arc CreateFromBulge(XY p1, XY p2, double bulge)
/// </summary>
/// <param name="start">Start point of the arc segment</param>
/// <param name="end">End point of the arc segment</param>
public void GetEndVertices(out XYZ start, out XYZ end)
public void GetEndVertices(out XY start, out XY end)
{
if (this.Normal != XYZ.AxisZ)
{
throw new NotImplementedException("GetBoundPoints box for not aligned Normal is not implemented");
}
List<XY> pts = this.PolygonalVertexes(2);

double tmpEndAngle = this.EndAngle;
start = pts[0];
end = pts[1];
}

if (this.EndAngle < this.StartAngle)
/// <summary>
/// Converts the arc in a list of vertexes.
/// </summary>
/// <param name="precision">Number of vertexes generated.</param>
/// <returns>A list vertexes that represents the arc expressed in object coordinate system.</returns>
public List<XY> PolygonalVertexes(int precision)
{
if (precision < 2)
{
tmpEndAngle += 2 * Math.PI;
throw new ArgumentOutOfRangeException(nameof(precision), precision, "The arc precision must be equal or greater than two.");
}

double delta = tmpEndAngle - this.StartAngle;

double angle = this.StartAngle + delta;
double startX = this.Radius * Math.Sin(angle);
double startY = this.Radius * Math.Cos(angle);

startX = MathUtils.IsZero(startX) ? 0 : startX;
startY = MathUtils.IsZero(startY) ? 0 : startY;
List<XY> ocsVertexes = new List<XY>();
double start = this.StartAngle;
double end = this.EndAngle;
if (end < start)
{
end += 2 * Math.PI;
}

start = new XYZ(startX, startY, 0);
double delta = (end - start) / (precision - 1);
for (int i = 0; i < precision; i++)
{
double angle = start + delta * i;
double cosine = this.Radius * Math.Cos(angle);
double sine = this.Radius * Math.Sin(angle);

double angle2 = this.StartAngle + delta * 2;
double endX = (this.Radius * Math.Sin(angle2));
double endY = (this.Radius * Math.Cos(angle2));
cosine = MathUtils.IsZero(cosine) ? 0 : cosine;
sine = MathUtils.IsZero(sine) ? 0 : sine;

endX = MathUtils.IsZero(endX) ? 0 : endX;
endY = MathUtils.IsZero(endY) ? 0 : endY;
ocsVertexes.Add(new XY(cosine, sine));
}

end = new XYZ(endX, endY, 0);
return ocsVertexes;
}
}
}
4 changes: 1 addition & 3 deletions ACadSharp/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public LineType LineType

private LineType _lineType = LineType.ByLayer;

/// <summary>
/// Default constructor.
/// </summary>
/// <inheritdoc/>
public Entity() : base() { }

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion ACadSharp/Entities/Seqend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class Seqend : Entity
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntitySeqend;

public Seqend() { }
/// <inheritdoc/>
public Seqend() : base() { }

internal Seqend(CadObject owner)
{
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp/Exceptions/DwgException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ protected DwgException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
}
}
12 changes: 0 additions & 12 deletions ACadSharp/Exceptions/DwgNotSupportedException.cs

This file was deleted.

12 changes: 0 additions & 12 deletions ACadSharp/Exceptions/DxfNotSupportedException.cs

This file was deleted.

5 changes: 3 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgStreamReaderBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CSMath;
using ACadSharp.Exceptions;
using CSMath;
using CSUtilities.Converters;
using CSUtilities.IO;
using CSUtilities.Text;
Expand Down Expand Up @@ -589,7 +590,7 @@ public ulong HandleReference(ulong referenceHandle, out DwgReferenceType referen
}
else
{
throw new Exceptions.DwgException($"DwgStreamReader exception, incorrect reference code with value: {code}");
throw new DwgException($"[HandleReference] invalid reference code with value: {code}");
}

return initialPos;
Expand Down
8 changes: 5 additions & 3 deletions ACadSharp/SeqendCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ACadSharp
{
/// <summary>
/// Represents a collection of <see cref="CadObject"/> ended by a <see cref="Entities.Seqend"/> entity
/// Represents a collection of <see cref="CadObject"/> ended by a <see cref="Entities.Seqend"/> entity.
/// </summary>
/// <typeparam name="T"></typeparam>
public class SeqendCollection<T> : CadObjectCollection<T>, ISeqendCollection
Expand All @@ -15,6 +15,9 @@ public class SeqendCollection<T> : CadObjectCollection<T>, ISeqendCollection

public event EventHandler<CollectionChangedEventArgs> OnSeqendRemoved;

/// <summary>
/// Sequence end entity for dxf.
/// </summary>
public Seqend Seqend
{
get
Expand All @@ -35,8 +38,7 @@ internal set

public SeqendCollection(CadObject owner) : base(owner)
{
this._seqend = new Seqend();
this._seqend.Owner = owner;
this._seqend = new Seqend(owner);
}

/// <inheritdoc/>
Expand Down

0 comments on commit 512392c

Please sign in to comment.