-
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.
- Loading branch information
Jakub Chocholowicz
committed
Mar 25, 2024
1 parent
93ff6f3
commit 508cc4d
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
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,40 @@ | ||
# This workflow will build a .NET project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | ||
|
||
name: "Algorithms Scenario 06" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
paths: [ 'samples/Algorithms/src/**', '.github/workflows/Algorithms_Scenario06.yml' ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./samples/Algorithms/tests/Algorithms.Core.NativeAot.Tests | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Publish | ||
run: dotnet publish -r linux-x64 -c Release /p:AotMsCodeCoverageInstrumentation="true" | ||
- name: Run | ||
run: ./bin/Release/net8.0/linux-x64/publish/Algorithms.Core.NativeAot.Tests --coverage --coverage-output $GITHUB_WORKSPACE/report.cobertura.xml --coverage-output-format cobertura | ||
- name: ReportGenerator | ||
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.0 | ||
with: | ||
reports: '${{ github.workspace }}/report.cobertura.xml' | ||
targetdir: '${{ github.workspace }}/coveragereport' | ||
reporttypes: 'MarkdownSummaryGithub' | ||
- name: Upload coverage into summary | ||
run: cat $GITHUB_WORKSPACE/coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: code-coverage-report | ||
path: ${{ github.workspace }}/report.cobertura.xml |
31 changes: 31 additions & 0 deletions
31
...s/Algorithms/tests/Algorithms.Core.NativeAot.Tests/Algorithms.Core.NativeAot.Tests.csproj
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MSTest.Engine" Version="1.0.0-alpha.24163.4" /> | ||
<PackageReference Include="MSTest.SourceGeneration" Version="1.0.0-alpha.24163.4" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" /> | ||
<PackageReference Include="MSTest.Analyzers" Version="3.2.2" /> | ||
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.4" /> | ||
<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="17.10.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../src/Algorithms.Core/Algorithms.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
35 changes: 35 additions & 0 deletions
35
samples/Algorithms/tests/Algorithms.Core.NativeAot.Tests/MergerTests.cs
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,35 @@ | ||
[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)] | ||
|
||
namespace Algorithms.Core.NativeAot.Tests; | ||
|
||
[TestClass] | ||
public class MergerTests | ||
{ | ||
[TestMethod] | ||
public void Test1() | ||
{ | ||
var result = Merger.Merge([1, 3, 5], [2, 4, 5, 6]); | ||
AssertArrays([1, 2, 3, 4, 5, 5, 6], result); | ||
} | ||
|
||
[TestMethod] | ||
public void Test2() | ||
{ | ||
var result = Merger.Merge([], [2, 4, 5, 6]); | ||
AssertArrays([2, 4, 5, 6], result); | ||
} | ||
|
||
[TestMethod] | ||
public void Test3() | ||
{ | ||
var result = Merger.Merge([2, 4, 5, 6], []); | ||
AssertArrays([2, 4, 5, 6], result); | ||
} | ||
|
||
private void AssertArrays(int[] expected, int[] actual) | ||
{ | ||
Assert.AreEqual(expected.Length, actual.Length, $"Sizes of arrays are different. expected.Length={expected.Length} actual.Length={actual.Length}"); | ||
for (int index = 0; index < expected.Length; index++) | ||
Assert.AreEqual(expected[index], actual[index], $"Arrays different on index={index}. expected[{index}]={expected[index]} actual[{index}]={actual[index]}"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
samples/Algorithms/tests/Algorithms.Core.NativeAot.Tests/Program.cs
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,18 @@ | ||
using Microsoft.Testing.Extensions; | ||
using Microsoft.Testing.Framework; | ||
using Microsoft.Testing.Platform.Builder; | ||
|
||
namespace Algorithms.Core.NativeAot.Tests; | ||
|
||
internal static class Program | ||
{ | ||
public static async Task<int> Main(string[] args) | ||
{ | ||
var builder = await TestApplication.CreateBuilderAsync(args); | ||
builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); | ||
builder.AddTrxReportProvider(); | ||
builder.AddCodeCoverageProvider(); | ||
var app = await builder.BuildAsync(); | ||
return await app.RunAsync(); | ||
} | ||
} |