Skip to content

Commit 66e886a

Browse files
committed
update: wrap up coverage effort
1 parent 3e10ce5 commit 66e886a

9 files changed

Lines changed: 344 additions & 2 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: coverage-pages
19+
cancel-in-progress: true
20+
21+
jobs:
22+
coverage:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v4
31+
with:
32+
dotnet-version: 8.0.x
33+
34+
- name: Cache NuGet packages
35+
uses: actions/cache@v4
36+
with:
37+
path: ~/.nuget/packages
38+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.sln') }}
39+
restore-keys: |
40+
${{ runner.os }}-nuget-
41+
42+
- name: Restore dependencies
43+
run: dotnet restore
44+
45+
- name: Build tests
46+
run: dotnet build tests/FixedMathSharp.Tests/FixedMathSharp.Tests.csproj --configuration Debug --no-restore
47+
48+
- name: Run tests with coverage
49+
run: dotnet test tests/FixedMathSharp.Tests/FixedMathSharp.Tests.csproj --configuration Debug --no-build --collect:"XPlat Code Coverage" --results-directory artifacts/coverage
50+
51+
- name: Install ReportGenerator
52+
run: dotnet tool install --global dotnet-reportgenerator-globaltool
53+
54+
- name: Add ReportGenerator to PATH
55+
run: echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
56+
57+
- name: Generate coverage report
58+
run: |
59+
reportgenerator \
60+
"-reports:artifacts/coverage/**/coverage.cobertura.xml" \
61+
"-targetdir:artifacts/coverage-report" \
62+
"-reporttypes:Html;MarkdownSummaryGithub;Badges;JsonSummary"
63+
64+
- name: Add coverage summary to job
65+
run: cat artifacts/coverage-report/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY"
66+
67+
- name: Upload coverage artifact
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: coverage-report
71+
path: artifacts/coverage-report
72+
73+
deploy:
74+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
75+
needs: coverage
76+
runs-on: ubuntu-latest
77+
environment:
78+
name: github-pages
79+
url: ${{ steps.deployment.outputs.page_url }}
80+
81+
steps:
82+
- name: Configure Pages
83+
uses: actions/configure-pages@v5
84+
85+
- name: Download coverage artifact
86+
uses: actions/download-artifact@v4
87+
with:
88+
name: coverage-report
89+
path: artifacts/coverage-report
90+
91+
- name: Upload Pages artifact
92+
uses: actions/upload-pages-artifact@v3
93+
with:
94+
path: artifacts/coverage-report
95+
96+
- name: Deploy to GitHub Pages
97+
id: deployment
98+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
.vs/
2-
src/FixedMathSharp/FixedMathSharp.csproj.user

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
![FixedMathSharp Icon](https://raw.githubusercontent.com/mrdav30/fixedmathsharp/main/icon.png)
44

55
[![.NET CI](https://github.com/mrdav30/FixedMathSharp/actions/workflows/dotnet.yml/badge.svg)](https://github.com/mrdav30/FixedMathSharp/actions/workflows/dotnet.yml)
6+
[![Coverage](https://mrdav30.github.io/FixedMathSharp/badge_linecoverage.svg)](https://mrdav30.github.io/FixedMathSharp/)
67
[![NuGet](https://img.shields.io/nuget/v/FixedMathSharp.svg)](https://www.nuget.org/packages/FixedMathSharp)
78
[![NuGet Downloads](https://img.shields.io/nuget/dt/FixedMathSharp.svg)](https://www.nuget.org/packages/FixedMathSharp)
89
[![License](https://img.shields.io/github/license/mrdav30/FixedMathSharp.svg)](https://github.com/mrdav30/FixedMathSharp/blob/main/LICENSE)

src/FixedMathSharp/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
bin/
22
obj/
3+
4+
FixedMathSharp.csproj.user
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/
22
obj/
3+
TestResults/

tests/FixedMathSharp.Tests/Fixed4x4.Tests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ public void FixedMatrix4x4_TRS_CreatesCorrectTransformationMatrix()
265265
$"Expected {rotation} but got {decomposedRotation}");
266266
}
267267

268+
[Fact]
269+
public void FixedMatrix4x4_TranslateRotateScale_MatchesExplicitMultiplicationOrder()
270+
{
271+
var translation = new Vector3d(3, -2, 5);
272+
var rotation = FixedQuaternion.FromEulerAnglesInDegrees((Fixed64)30, (Fixed64)45, (Fixed64)60);
273+
var scale = new Vector3d(2, 3, 4);
274+
275+
var expected = Fixed4x4.CreateTranslation(translation) * Fixed4x4.CreateRotation(rotation) * Fixed4x4.CreateScale(scale);
276+
var result = Fixed4x4.TranslateRotateScale(translation, rotation, scale);
277+
278+
Assert.Equal(expected, result);
279+
}
280+
268281
[Fact]
269282
public void FixedMatrix4x4_Equality_WorksCorrectly()
270283
{
@@ -310,6 +323,19 @@ public void FixedMatrix4x4_SetGlobalScale_WorksWithRotation()
310323
Assert.Equal(globalScale, extractedScale);
311324
}
312325

326+
[Fact]
327+
public void FixedMatrix4x4_SetScale_UpdatesDiagonalComponents()
328+
{
329+
var matrix = Fixed4x4.CreateTranslation(new Vector3d(5, 6, 7));
330+
331+
var updated = Fixed4x4.SetScale(matrix, new Vector3d(2, 3, 4));
332+
333+
Assert.Equal(new Fixed64(2), updated.m00);
334+
Assert.Equal(new Fixed64(3), updated.m11);
335+
Assert.Equal(new Fixed64(4), updated.m22);
336+
Assert.Equal(new Vector3d(5, 6, 7), updated.Translation);
337+
}
338+
313339
[Fact]
314340
public void FixedMatrix4x4_SetRotation_PreservesTranslationAndScale()
315341
{
@@ -340,6 +366,28 @@ public void FixedMatrix4x4_SetTranslationAndRotationExtensions_UpdateMatrixInPla
340366
Assert.True(matrix.Rotation.FuzzyEqual(rotation, new Fixed64(0.0001)));
341367
}
342368

369+
[Fact]
370+
public void FixedMatrix4x4_ExtractRotation_HandlesZeroScaleWithoutThrowing()
371+
{
372+
var matrix = Fixed4x4.CreateScale(Vector3d.Zero);
373+
374+
var exception = Record.Exception(() => Fixed4x4.ExtractRotation(matrix));
375+
376+
Assert.Null(exception);
377+
}
378+
379+
[Fact]
380+
public void FixedMatrix4x4_Decompose_ZeroScaleMatrix_ReplacesZeroScaleToAvoidDivisionByZero()
381+
{
382+
var matrix = Fixed4x4.CreateScale(Vector3d.Zero);
383+
384+
Assert.True(Fixed4x4.Decompose(matrix, out var scale, out var rotation, out var translation));
385+
386+
Assert.Equal(Vector3d.One, scale);
387+
Assert.Equal(Vector3d.Zero, translation);
388+
Assert.Equal(rotation, rotation);
389+
}
390+
343391
[Fact]
344392
public void FixedMatrix4x4_NormalizeRotationMatrixExtension_NormalizesAxesInPlace()
345393
{
@@ -398,6 +446,15 @@ public void FixedMatrix4x4_Invert_SingularNonAffineMatrix_ReturnsFalse()
398446
Assert.Equal(Fixed4x4.Identity, inverted);
399447
}
400448

449+
[Fact]
450+
public void FixedMatrix4x4_Invert_SingularAffineMatrix_ReturnsFalse()
451+
{
452+
var matrix = Fixed4x4.CreateScale(new Vector3d(0, 1, 1));
453+
454+
Assert.False(Fixed4x4.Invert(matrix, out var inverted));
455+
Assert.Equal(Fixed4x4.Identity, inverted);
456+
}
457+
401458
[Fact]
402459
public void FixedMatrix4x4_TransformPoint_NonAffineMatrix_UsesPerspectiveDivision()
403460
{
@@ -540,6 +597,12 @@ public void FixedMatrix4x4_OperatorsAndHashCode_WorkCorrectly()
540597
Assert.NotEqual(hash, changedM13.GetHashCode());
541598
}
542599

600+
[Fact]
601+
public void FixedMatrix4x4_EqualsObject_ReturnsFalseForDifferentType()
602+
{
603+
Assert.False(Fixed4x4.Identity.Equals("not-a-matrix"));
604+
}
605+
543606
[Fact]
544607
public void TransformPoint_WorldToLocal_ReturnsCorrectResult()
545608
{

tests/FixedMathSharp.Tests/FixedMath.Tests.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public void Clamp01_ValueInRange_ReturnsValue()
4646
Assert.Equal(new Fixed64(0.5f), result);
4747
}
4848

49+
[Fact]
50+
public void ClampOne_ClampsToNegativeOneOneRange()
51+
{
52+
Assert.Equal(-Fixed64.One, FixedMath.ClampOne(new Fixed64(-2)));
53+
Assert.Equal(new Fixed64(0.5), FixedMath.ClampOne(new Fixed64(0.5)));
54+
Assert.Equal(Fixed64.One, FixedMath.ClampOne(new Fixed64(2)));
55+
}
56+
4957
#endregion
5058

5159
#region Test: FastAbs Method
@@ -64,6 +72,12 @@ public void FastAbs_NegativeValue_ReturnsPositiveValue()
6472
Assert.Equal(new Fixed64(10), result);
6573
}
6674

75+
[Fact]
76+
public void FastAbs_MinValue_ReturnsMaxValue()
77+
{
78+
Assert.Equal(Fixed64.MAX_VALUE, FixedMath.Abs(Fixed64.MIN_VALUE));
79+
}
80+
6781
#endregion
6882

6983
#region Test: Ceiling Method
@@ -158,6 +172,13 @@ public void Round_ToEven_NegativeNumber_RoundsToNearestEven()
158172
Assert.Equal(new Fixed64(-2), result);
159173
}
160174

175+
[Fact]
176+
public void Round_AwayFromZero_NegativeHalf_RoundsDown()
177+
{
178+
var result = FixedMath.Round(new Fixed64(-2.5), MidpointRounding.AwayFromZero);
179+
Assert.Equal(new Fixed64(-3), result);
180+
}
181+
161182
#endregion
162183

163184
#region Test: Round Method (With Decimal Places)
@@ -183,6 +204,13 @@ public void Round_WithDecimalPlaces_RoundsToZeroDecimalPlaces_AwayFromZero()
183204
Assert.Equal(new Fixed64(3), result);
184205
}
185206

207+
[Fact]
208+
public void Round_WithDecimalPlaces_ThrowsWhenPrecisionIsOutOfRange()
209+
{
210+
Assert.Throws<ArgumentOutOfRangeException>(() => FixedMath.RoundToPrecision(new Fixed64(1.23), -1));
211+
Assert.Throws<ArgumentOutOfRangeException>(() => FixedMath.RoundToPrecision(new Fixed64(1.23), FixedMath.Pow10Lookup.Length));
212+
}
213+
186214
#endregion
187215

188216
#region Test: FastAdd Method
@@ -377,6 +405,14 @@ public void Clamp_ValueAboveMax_ReturnsMax()
377405
Assert.Equal(new Fixed64(5), result);
378406
}
379407

408+
[Fact]
409+
public void Clamp_GenericComparable_ClampsAtBothEndsAndPassesThrough()
410+
{
411+
Assert.Equal(5, FixedMath.Clamp(9, 1, 5));
412+
Assert.Equal(1, FixedMath.Clamp(-3, 1, 5));
413+
Assert.Equal(3, FixedMath.Clamp(3, 1, 5));
414+
}
415+
380416
#endregion
381417

382418
#region Test: MoveTowards Method
@@ -402,6 +438,13 @@ public void MoveTowards_ValueOvershoot_ReturnsTarget()
402438
Assert.Equal(new Fixed64(5), result); // It overshoots, so it should return 5
403439
}
404440

441+
[Fact]
442+
public void MoveTowards_ValueMovesDownWithOvershoot_ReturnsTarget()
443+
{
444+
var result = FixedMath.MoveTowards(new Fixed64(5), new Fixed64(3), new Fixed64(3));
445+
Assert.Equal(new Fixed64(3), result);
446+
}
447+
405448
#endregion
406449

407450
#region Test: FastMod Method (Edge Case)
@@ -462,4 +505,4 @@ public void AddOverflowHelper_NegativeOverflow_SetsOverflowFlag()
462505
}
463506

464507
#endregion
465-
}
508+
}

0 commit comments

Comments
 (0)