Skip to content

Commit 0553e9f

Browse files
authored
Merge pull request #8 from VladM7/tests
Tests
2 parents 57f96a3 + 0c53ff6 commit 0553e9f

10 files changed

Lines changed: 540 additions & 26 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,44 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828

29-
- name: Setup .NET 9 SDK
29+
- name: Setup .NET 10 SDK
3030
uses: actions/setup-dotnet@v4
3131
with:
32-
dotnet-version: 9.0.x
32+
dotnet-version: 10.0.x
3333
cache: true
3434
cache-dependency-path: |
3535
**/*.sln
36+
**/*.slnx
3637
**/*.csproj
3738
38-
- name: Restore
39-
run: dotnet restore
39+
- name: Restore (each csproj)
40+
shell: pwsh
41+
run: |
42+
$projects = Get-ChildItem -Recurse -Filter *.csproj -File
43+
if (-not $projects) { Write-Host "No csproj files found"; exit 1 }
44+
foreach ($p in $projects) {
45+
echo "Restoring $($p.FullName)"
46+
dotnet restore --nologo "$($p.FullName)"
47+
}
4048
41-
- name: Build
42-
run: dotnet build --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
49+
- name: Build (Release)
50+
shell: pwsh
51+
run: |
52+
$projects = Get-ChildItem -Recurse -Filter *.csproj -File | ForEach-Object { $_.FullName }
53+
foreach ($p in $projects) {
54+
echo "Building $p"
55+
dotnet build "$p" --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
56+
}
4357
4458
- name: Test
4559
if: ${{ hashFiles('**/*Tests.csproj') != '' || hashFiles('**/*Test.csproj') != '' }}
46-
run: >-
47-
dotnet test --configuration Release --no-build --verbosity normal
48-
--collect:"XPlat Code Coverage" --logger "trx;LogFileName=test_results.trx"
60+
shell: pwsh
61+
run: |
62+
$testProjects = Get-ChildItem -Recurse -Include *Tests.csproj,*Test.csproj -File | ForEach-Object { $_.FullName }
63+
foreach ($tp in $testProjects) {
64+
echo "Testing $tp"
65+
dotnet test "$tp" --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger "trx;LogFileName=test_results.trx"
66+
}
4967
5068
- name: Upload test results
5169
if: ${{ always() && (hashFiles('**/*Tests.csproj') != '' || hashFiles('**/*Test.csproj') != '' ) }}

.github/workflows/codeql.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ jobs:
2929
- name: Checkout
3030
uses: actions/checkout@v4
3131

32-
- name: Setup .NET 9 SDK
32+
- name: Setup .NET 10 SDK
3333
uses: actions/setup-dotnet@v4
3434
with:
35-
dotnet-version: 9.0.x
35+
dotnet-version: 10.0.x
36+
cache: true
37+
cache-dependency-path: |
38+
**/*.sln
39+
**/*.slnx
40+
**/*.csproj
3641
3742
- name: Initialize CodeQL
3843
uses: github/codeql-action/init@v3
@@ -44,9 +49,18 @@ jobs:
4449

4550
- name: Manual build fallback
4651
if: failure()
52+
shell: pwsh
4753
run: |
48-
dotnet restore
49-
dotnet build --configuration Release --no-restore
54+
$projects = Get-ChildItem -Recurse -Filter *.csproj -File
55+
if (-not $projects) { Write-Host "No csproj files found"; exit 1 }
56+
foreach ($p in $projects) {
57+
echo "Restoring $($p.FullName)"
58+
dotnet restore --nologo "$($p.FullName)"
59+
}
60+
foreach ($p in $projects) {
61+
echo "Building $($p.FullName)"
62+
dotnet build "$($p.FullName)" --configuration Release --no-restore /p:ContinuousIntegrationBuild=true
63+
}
5064
5165
- name: Perform CodeQL Analysis
5266
uses: github/codeql-action/analyze@v3

Services/Layering/StripFillGenerationStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public List<Layer> Generate(List<SKU> skus, SupportSurface supportSurface, Gener
103103

104104
double util = usedArea / area;
105105
string desc = $"rows={nrows} seq=" + string.Join(",", seq.Select(v => $"{v.sref.Name}:{v.w}x{v.h}"));
106-
string lid = $"strip_r{nrows}_" + string.Join("_", seq.Select(v => $"{v.sref.Name.Replace(' ', '_')}{v.w}x{v.h}"));
106+
string lid = $"strip_r{nrows}";
107107

108108
int layerHeight = seq.Count != 0 ? seq.Max(v => v.sref.Height) : 0;
109109
var metadata = new LayerMetadata(util, layerHeight, desc);

Stack-Solver.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net9.0-windows10.0.26100.1</TargetFramework>
5+
<TargetFramework>net10.0-windows</TargetFramework>
66
<ApplicationManifest>app.manifest</ApplicationManifest>
77
<ApplicationIcon>Box.ico</ApplicationIcon>
88
<UseWPF>true</UseWPF>
@@ -17,6 +17,10 @@
1717
<EmbeddedResource Remove="Controls\**" />
1818
<None Remove="Controls\**" />
1919
<Page Remove="Controls\**" />
20+
<Compile Remove="Tests\**" />
21+
<EmbeddedResource Remove="Tests\**" />
22+
<None Remove="Tests\**" />
23+
<Page Remove="Tests\**" />
2024
</ItemGroup>
2125

2226
<ItemGroup>
@@ -25,16 +29,16 @@
2529

2630
<ItemGroup>
2731
<PackageReference Include="Google.OrTools" Version="9.14.6206" />
28-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.9" />
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.9" />
30-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="9.0.9" />
31-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9">
32+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
33+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
34+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="10.0.0" />
35+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0">
3236
<PrivateAssets>all</PrivateAssets>
3337
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3438
</PackageReference>
3539
<PackageReference Include="WPF-UI" Version="4.0.3" />
3640
<PackageReference Include="WPF-UI.DependencyInjection" Version="4.0.3" />
37-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
41+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
3842
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0 " />
3943
</ItemGroup>
4044

Stack-Solver.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<Solution>
2-
<Project Path="../Stack-Solver-Tests/Stack-Solver-Tests.csproj" Id="39597fc4-81df-463b-8581-9fa36df424e3" />
32
<Project Path="Stack-Solver.csproj" />
3+
<Project Path="Tests/Stack-Solver.Tests/Stack-Solver.Tests.csproj" Id="f381e69c-0b5f-4653-856f-a6e51e51e45b" />
44
</Solution>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Stack_Solver.Models;
2+
using Stack_Solver.Models.Supports;
3+
using Stack_Solver.Services.Layering;
4+
using Xunit;
5+
6+
7+
namespace Stack_Solver.Tests.Strategies
8+
{
9+
public class BLFGenerationStrategyTests
10+
{
11+
[Fact]
12+
public void Generate_SingleSKU()
13+
{
14+
var skus = new List<SKU>
15+
{
16+
new() {
17+
SkuId = "A",
18+
Name = "Box A",
19+
Length = 50,
20+
Width = 30,
21+
Height = 20,
22+
Quantity = 500,
23+
Rotatable = true
24+
}
25+
};
26+
27+
var pallet = new Pallet("Standard Pallet", 800, 60, 14);
28+
29+
var strategy = new BLFGenerationStrategy();
30+
var options = new GenerationOptions { };
31+
32+
var layers = strategy.Generate(skus, pallet, options);
33+
34+
Assert.NotEmpty(layers);
35+
layers.Sort((l1, l2) => l1.Items.Count.CompareTo(l2.Items.Count));
36+
Assert.Equal(32, layers.Last().Items.Count);
37+
}
38+
39+
[Fact]
40+
public void Generate_MultipleSKUs()
41+
{
42+
var skus = new List<SKU>
43+
{
44+
new() {
45+
SkuId = "A",
46+
Name = "Box A",
47+
Length = 21,
48+
Width = 16,
49+
Height = 20,
50+
Quantity = 500,
51+
Rotatable = true
52+
},
53+
new() {
54+
SkuId = "B",
55+
Name = "Box B",
56+
Length = 52,
57+
Width = 33,
58+
Height = 20,
59+
Quantity = 500,
60+
Rotatable = true
61+
}
62+
};
63+
64+
var pallet = new Pallet("Standard Pallet", 120, 100, 14);
65+
66+
var strategy = new BLFGenerationStrategy();
67+
var options = new GenerationOptions { };
68+
69+
var layers = strategy.Generate(skus, pallet, options);
70+
71+
Assert.NotEmpty(layers);
72+
layers.Sort((l1, l2) => l1.Items.Count.CompareTo(l2.Items.Count));
73+
Assert.Equal(33, layers.Last().Items.Count);
74+
layers.Sort((l1, l2) => l1.Metadata.Utilization.CompareTo(l2.Metadata.Utilization));
75+
Assert.Equal(0.942, layers.Last().Metadata.Utilization, 3);
76+
}
77+
78+
[Fact]
79+
public void Generate_ShouldRespectSKUQuantityLimits()
80+
{
81+
var skus = new List<SKU>
82+
{
83+
new SKU
84+
{
85+
SkuId = "X",
86+
Name = "Tiny Box",
87+
Length = 100,
88+
Width = 100,
89+
Height = 50,
90+
Quantity = 2,
91+
Rotatable = true
92+
}
93+
};
94+
95+
var pallet = new Pallet("Interesting Pallet", 300, 200, 14);
96+
var strategy = new BLFGenerationStrategy();
97+
98+
var layers = strategy.Generate(skus, pallet, new GenerationOptions { });
99+
var totalPlaced = 0;
100+
101+
foreach (var layer in layers)
102+
totalPlaced += layer.Items.Count(i => i.SkuType.SkuId == "X");
103+
104+
Assert.True(totalPlaced <= 2);
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)