Skip to content

Commit

Permalink
chore(v0.0.4/CLI): Add option to specify floating point precision
Browse files Browse the repository at this point in the history
With option "-f" or "--fpp" a floating point precision may be specified.
NOTE: 	These is valid for REAL and LREAL values, since we cannot
	distinguish between them anymore (JSON string).
  • Loading branch information
densogiaichned committed Feb 11, 2024
1 parent 9b987f5 commit dbf0eae
Show file tree
Hide file tree
Showing 31 changed files with 194 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .Zeugwerk/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "snappy",
"plcs": [
{
"version": "0.0.3.0",
"version": "0.0.4.0",
"name": "snappy",
"type": "Library",
"packages": [
Expand Down
21 changes: 19 additions & 2 deletions TcHaxx.Snappy.CLI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "env", "env", "{9A6AE3E0-A67
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcHaxx.Snappy.CLI.Installer", "src\TcHaxx.Snappy.CLI.Installer\TcHaxx.Snappy.CLI.Installer.csproj", "{5E60BFD2-A67C-482B-8446-950D3C9BA36A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcHaxx.Snappy.Common", "src\TcHaxx.Snappy.Common\TcHaxx.Snappy.Common.csproj", "{E544FDBB-BA02-4661-9BCB-C5791613964D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcHaxx.Snappy.Common", "src\TcHaxx.Snappy.Common\TcHaxx.Snappy.Common.csproj", "{E544FDBB-BA02-4661-9BCB-C5791613964D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcHaxx.Snappy.Verifier", "src\TcHaxx.Snappy.Verifier\TcHaxx.Snappy.Verifier.csproj", "{A364EF16-430E-4DC5-80D7-31B7C57AE641}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TcHaxx.Snappy.Verifier", "src\TcHaxx.Snappy.Verifier\TcHaxx.Snappy.Verifier.csproj", "{A364EF16-430E-4DC5-80D7-31B7C57AE641}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcHaxx.Snappy.Verifier.Tests", "src\TcHaxx.Snappy.Verifier.Tests\TcHaxx.Snappy.Verifier.Tests.csproj", "{923C90E9-E97F-4BB5-B971-401089649370}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{C51D268A-94C5-4264-9D30-9A2753B9C872}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{8F2C7052-0F34-4F1F-B9A5-50D5DC2AD989}"
ProjectSection(SolutionItems) = preProject
.github\workflows\cicd.yml = .github\workflows\cicd.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -51,10 +60,18 @@ Global
{A364EF16-430E-4DC5-80D7-31B7C57AE641}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A364EF16-430E-4DC5-80D7-31B7C57AE641}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A364EF16-430E-4DC5-80D7-31B7C57AE641}.Release|Any CPU.Build.0 = Release|Any CPU
{923C90E9-E97F-4BB5-B971-401089649370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{923C90E9-E97F-4BB5-B971-401089649370}.Debug|Any CPU.Build.0 = Debug|Any CPU
{923C90E9-E97F-4BB5-B971-401089649370}.Release|Any CPU.ActiveCfg = Release|Any CPU
{923C90E9-E97F-4BB5-B971-401089649370}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C51D268A-94C5-4264-9D30-9A2753B9C872} = {9A6AE3E0-A679-453E-A11A-9DEC17B6B948}
{8F2C7052-0F34-4F1F-B9A5-50D5DC2AD989} = {C51D268A-94C5-4264-9D30-9A2753B9C872}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5ABE814F-A307-4743-959F-809CDC419600}
EndGlobalSection
Expand Down
30 changes: 15 additions & 15 deletions TcHaxx.Snappy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ Global
{33EAC63E-19FA-4E75-A4EB-E8C86BCF4658}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{33EAC63E-19FA-4E75-A4EB-E8C86BCF4658}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{33EAC63E-19FA-4E75-A4EB-E8C86BCF4658}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7)
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2)
Expand All @@ -64,6 +49,21 @@ Global
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{A888BB16-E4EA-40CD-ABDE-EC95D73B8395}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{AC2D361F-220F-4749-A24C-F7B161E323DC}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
sString: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy,
nNumber: 3735928559,
fFloat: -1.2345678,
fFloat: -1.23457,
aBuffer: [
1,
2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
sString: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy,
nNumber: 3735928559,
fFloat: -1.2345678,
fFloat: -1.23457,
aBuffer: [
1,
2,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion examples/examples/POUs/FB_TcUnitExample.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hr := fbTcUnitAdapter.Verify(anyArg:= stActual);
IF NOT PENDING(hr) THEN
TEST_FINISHED_NAMED('Test some stuff with TcHaxx.Snappy');
END_IF;]]></ST>
END_IF]]></ST>
</Implementation>
</POU>
</TcPlcObject>
6 changes: 6 additions & 0 deletions examples/examples/examples.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
<PlaceholderReference Include="snappy">
<DefaultResolution>snappy, * (TcHaxx)</DefaultResolution>
<Namespace>TcHaxx_Snappy</Namespace>
<Parameters>
<Parameter ListName="PARAM_TCHAXX_SNAPPY">
<Key>CSNAPPYVERIFYAMSNETID</Key>
<Value>'10.1.44.157.1.1'</Value>
</Parameter>
</Parameters>
</PlaceholderReference>
<PlaceholderReference Include="Tc2_Standard">
<DefaultResolution>Tc2_Standard, * (Beckhoff Automation GmbH)</DefaultResolution>
Expand Down
8 changes: 8 additions & 0 deletions src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ namespace TcHaxx.Snappy.CLI;
[Verb("verify", false, HelpText = "Verify.")]
public class VerifyOptions : BaseOptions, ITcAdsOptions, IVerifierOptions
{
/// <inheritdoc/>
[Option('d', "dir", Default = Verifier.Constants.DEFAULT_OPTION_VERIFIED_DIRECTORY, Required = false, HelpText = "Directory of verified snapshot files.")]
public string VerifyDirectory { get; init; } = string.Empty;

/// <inheritdoc/>
[Option('c', "compact-diff", Default = Verifier.Constants.DEFAULT_OPTION_COMPACT_DIFF, Required = false, HelpText = "Diff output as compact as possible.")]
public bool CompactDiff { get; init; }

/// <inheritdoc/>
[Option('p', "port", Default = TcADS.Constants.DEFAULT_AMS_PORT, Required = false, HelpText = "AmsPort of the Server.")]
public ushort AdsPort { get; init; }

/// <inheritdoc/>
[Option('f', "fpp", Default = Verifier.Constants.DEFAULT_OPTION_FP_PRECISION, Required = false, HelpText = "Floating point precision for REAL/LREAL value.")]
public ushort FloatingPointPrecision { get; init; }
}
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"TcHaxx.Snappy.CLI": {
"commandName": "Project",
"commandLineArgs": "verify -l Debug"
"commandLineArgs": "verify -l Debug -d D:\\densogiaichned\\snappy\\examples\\examples\\.snappy-verified"
}
}
}
4 changes: 2 additions & 2 deletions src/TcHaxx.Snappy.CLI/TcHaxx.Snappy.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<LangVersion>Latest</LangVersion>
<RepositoryUrl>https://github.com/TcHaxx/snappy</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>snapshot-testing; unit-test; twincat</PackageTags>
<PackageTags>snapshot-testing; test-framework; unit-test; twincat; beckhoff;</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/TcHaxx/snappy</PackageProjectUrl>
<Description>A Snapshot Testing framework for TwinCAT 3</Description>
<Copyright>Copyright (c) 2024 densogiaichned</Copyright>
<Title>TwinCAT Snapshot Testing framework</Title>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<PackAsTool>True</PackAsTool>
Expand Down
1 change: 1 addition & 0 deletions src/TcHaxx.Snappy.Verifier.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0,
-1,
3,
1234568
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0.0,
-1.0,
3.0,
1234568.0
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0.00,
-1.00,
3.00,
1234567.99
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0.000,
-1.000,
3.000,
1234567.988
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0.0000,
-1.0000,
3.0000,
1234567.9877
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
0.00000,
-1.00001,
3.00000,
1234567.98765
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
0.000000,
-1.000010,
3.000000,
1234567.987654,
-98765433209999996300983879418780084752989155443507930248275595876839919513686268729884672.000000
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using TcHaxx.Snappy.Verifier.JsonConverter;

namespace TcHaxx.Snappy.Verifier.Tests.JsonConverter;

public class DoubleConverterTests : VerifyBase
{
public DoubleConverterTests()
: base()
{

}
[Theory]
[InlineData(0, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(1, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(2, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(3, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(4, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(5, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321)]
[InlineData(6, 0.0, -1.00001, 3.00000000000000007, 1234567.987654321, -9.876543321e88)]
public async Task ShouldUseDoublePrecision(ushort precision, params double[] values)
{
var settings = new VerifySettings();
settings.AddExtraSettings(_ =>
{
_.Converters.Add(new DoubleConverter(precision));
});

await Verify(values, settings).UseParameters(precision);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Verify.xunit" Version="23.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TcHaxx.Snappy.Verifier\TcHaxx.Snappy.Verifier.csproj" />
</ItemGroup>

</Project>
13 changes: 6 additions & 7 deletions src/TcHaxx.Snappy.Verifier/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TcHaxx.Snappy.Verifier;
namespace TcHaxx.Snappy.Verifier;

public static class Constants
{
Expand All @@ -17,4 +11,9 @@ public static class Constants
/// Diff output as compact as possible.
/// </summary>
public const bool DEFAULT_OPTION_COMPACT_DIFF = true;

/// <summary>
/// Default floating point precision for REAL/LREAL.
/// </summary>
public const ushort DEFAULT_OPTION_FP_PRECISION = 5;
}
3 changes: 3 additions & 0 deletions src/TcHaxx.Snappy.Verifier/Friends.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("TcHaxx.Snappy.Verifier.Tests")]
10 changes: 10 additions & 0 deletions src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Globalization;

namespace TcHaxx.Snappy.Verifier.JsonConverter;

internal class DoubleConverter(ushort precision) : WriteOnlyJsonConverter<double>
{

public override void Write(VerifyJsonWriter writer, double theDouble) =>
writer.WriteValue(theDouble.ToString($"F{precision}", CultureInfo.InvariantCulture));
}
2 changes: 2 additions & 0 deletions src/TcHaxx.Snappy.Verifier/Options/DefaultOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ internal class DefaultOptions : IVerifierOptions
public string VerifyDirectory { get; init; } = Constants.DEFAULT_OPTION_VERIFIED_DIRECTORY;
///<inheritdoc/>
public bool CompactDiff { get; init; } = Constants.DEFAULT_OPTION_COMPACT_DIFF;
///<inheritdoc/>
public ushort FloatingPointPrecision { get; init; } = Constants.DEFAULT_OPTION_FP_PRECISION;
}
5 changes: 5 additions & 0 deletions src/TcHaxx.Snappy.Verifier/Options/IVerifierOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public interface IVerifierOptions
/// Compact diff output, e.g. for TcUnit where max. ADS log string = 255.
/// </summary>
public bool CompactDiff { get; init; }

/// <summary>
/// Floating point precision for REAL/LREAL.
/// </summary>
public ushort FloatingPointPrecision { get; init; }
}
1 change: 1 addition & 0 deletions src/TcHaxx.Snappy.Verifier/TcHaxx.Snappy.Verifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit dbf0eae

Please sign in to comment.