-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding SC.Tests project with simple golden file testing
- Loading branch information
1 parent
7dd8121
commit 8afbbbb
Showing
7 changed files
with
992 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,49 @@ | ||
using JsonDiffPatchDotNet; | ||
using Newtonsoft.Json.Linq; | ||
using FluentAssertions; | ||
using FluentAssertions.Json; | ||
using Newtonsoft.Json.Linq; | ||
using Newtonsoft.Json; | ||
using SC.CLI; | ||
using SC.ObjectModel; | ||
using SC.ObjectModel.Configuration; | ||
using SC.ObjectModel.Additionals; | ||
using SC.ObjectModel.IO; | ||
|
||
|
||
namespace SC.Tests; | ||
|
||
public class Golden | ||
{ | ||
private static JToken LoadJson(string path) => JToken.Parse(File.ReadAllText(path)); | ||
|
||
private static void WriteJson(JToken json, string path) => | ||
File.WriteAllText(path, json.ToString(formatting: Formatting.Indented)); | ||
|
||
|
||
[Theory()] | ||
[InlineData("data/sample_contained.json")] | ||
[InlineData("data/sample_offload.json")] | ||
public void GoldenInputs(string inputFile) | ||
{ | ||
// Load the input file | ||
var instance = Instance.ReadJson(File.ReadAllText(inputFile)); | ||
|
||
// Run calculation | ||
var result = Executor.Execute(instance, new Configuration() { TimeLimitInSeconds = 1 }, Console.WriteLine); | ||
|
||
var update = Environment.GetEnvironmentVariable("UPDATE") == "1"; | ||
if (update) | ||
{ | ||
// Just update the golden file | ||
WriteJson(JToken.Parse(JsonIO.To(result.Solution.ToJsonSolution())), inputFile + ".golden"); | ||
} | ||
else | ||
{ | ||
// Compare the actual result with the golden file | ||
var expectation = LoadJson(inputFile + ".golden"); | ||
var actual = JToken.Parse(JsonIO.To(result.Solution.ToJsonSolution())); | ||
actual.Should().BeEquivalentTo(expectation); | ||
} | ||
} | ||
} |
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,48 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" /> | ||
<PackageReference Include="JsonDiffPatch.Net" Version="2.3.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SC.CLI\SC.CLI.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="data\sample_offload.json" /> | ||
<Content Include="data\sample_offload.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<None Remove="data\sample_contained.json" /> | ||
<Content Include="data\sample_contained.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<None Remove="data\sample_contained.json.golden" /> | ||
<Content Include="data\sample_contained.json.golden"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
<None Remove="data\sample_offload.json.golden" /> | ||
<Content Include="data\sample_offload.json.golden"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
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,230 @@ | ||
{ | ||
"name": "jsonTest", | ||
"containers": [ | ||
{ | ||
"id": 0, | ||
"length": 600, | ||
"width": 400, | ||
"height": 300 | ||
}, | ||
{ | ||
"id": 1, | ||
"length": 600, | ||
"width": 400, | ||
"height": 300 | ||
}, | ||
{ | ||
"id": 2, | ||
"length": 500, | ||
"width": 400, | ||
"height": 300 | ||
}, | ||
{ | ||
"id": 3, | ||
"length": 300, | ||
"width": 400, | ||
"height": 250 | ||
} | ||
], | ||
"pieces": [ | ||
{ | ||
"id": 0, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 1 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 304, | ||
"width": 336, | ||
"height": 140 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 1, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 122, | ||
"width": 245, | ||
"height": 367 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 2, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 392, | ||
"width": 145, | ||
"height": 152 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 3, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 271, | ||
"width": 214, | ||
"height": 393 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 4, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 351, | ||
"width": 398, | ||
"height": 287 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 5, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 351, | ||
"width": 245, | ||
"height": 287 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 6, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 1 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 294, | ||
"width": 234, | ||
"height": 376 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 7, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 0 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 241, | ||
"width": 78, | ||
"height": 115 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 8, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 1 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 154, | ||
"width": 395, | ||
"height": 274 | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 9, | ||
"flags": [ | ||
{ | ||
"flagId": 0, | ||
"flagValue": 1 | ||
} | ||
], | ||
"cubes": [ | ||
{ | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"length": 60, | ||
"width": 183, | ||
"height": 170 | ||
} | ||
] | ||
} | ||
], | ||
"rules": { | ||
"flagRules": [ | ||
{ | ||
"flagId": 0, | ||
"ruleType": 0, | ||
"parameter": 0 | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.