-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
24 changed files
with
631 additions
and
199 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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
/.vs | ||
/.venv | ||
packages | ||
bin/ | ||
obj/ | ||
AdSecGH/bin | ||
AdSecGH/obj | ||
AdSecGHConverters/bin | ||
|
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
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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCore", "AdSecCore\AdSecCore.csproj", "{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdSecCoreTests", "AdSecCoreTests\AdSecCoreTests.csproj", "{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2A3194AF-5B84-47DF-8E36-6819C2CF6E97}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2407A2E8-B608-454F-A6A9-EABDFFFF48FD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
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,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=a0644a1b_002D75bf_002D4493_002Db209_002D201de422018a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<Solution />
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
<TargetFrameworks>net48;net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
</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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AdSecGHCore.Helpers { | ||
public class DoubleComparer : IEqualityComparer<double> { | ||
private readonly double _epsilon = 0.01; //default accuracy in % | ||
private readonly bool _margin; | ||
|
||
public DoubleComparer(double epsilon = 0.01, bool useEpsilonAsMargin = false) { | ||
_epsilon = epsilon; | ||
_margin = useEpsilonAsMargin; | ||
} | ||
|
||
public bool Equals(double x, double y) { | ||
x = Math.Round(x, 6); | ||
y = Math.Round(y, 6); | ||
|
||
if (x == y) { | ||
return true; | ||
} | ||
|
||
if (_margin) { | ||
if (Math.Abs(x - y) < _epsilon) { | ||
return true; | ||
} | ||
} else { | ||
double error = Math.Abs(x - y) / (x + y) * 0.5; | ||
return error < _epsilon; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public int GetHashCode(double obj) { | ||
return obj.GetHashCode(); | ||
} | ||
} | ||
} |
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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AdSecGHCore.Helpers { | ||
|
||
internal class Result { | ||
|
||
internal static double RoundToSignificantDigits(double d, int digits) { | ||
if (d == 0.0) { | ||
return 0.0; | ||
} | ||
|
||
double leftSideNumbers = Math.Floor(Math.Log10(Math.Abs(d))) + 1; | ||
double scale = Math.Pow(10, leftSideNumbers); | ||
double result = scale * Math.Round(d / scale, digits, MidpointRounding.AwayFromZero); | ||
|
||
// Clean possible precision error. | ||
if ((int)leftSideNumbers >= digits) { | ||
return Math.Round(result, 0, MidpointRounding.AwayFromZero); | ||
} | ||
|
||
if (Math.Abs(digits - (int)leftSideNumbers) > 15) { | ||
return 0.0; | ||
} | ||
|
||
return Math.Round(result, digits - (int)leftSideNumbers, MidpointRounding.AwayFromZero); | ||
} | ||
|
||
internal static List<double> SmartRounder(double max, double min) { | ||
// find the biggest abs value of max and min | ||
double val = Math.Max(Math.Abs(max), Math.Abs(min)); | ||
|
||
// round that with 4 significant digits | ||
double scale = RoundToSignificantDigits(val, 4); | ||
|
||
// list to hold output values | ||
var roundedvals = new List<double>(); | ||
|
||
// do max | ||
if (max == 0) { | ||
roundedvals.Add(0); | ||
} else { | ||
double tempmax = scale * Math.Round(max / scale, 4); | ||
tempmax = Math.Ceiling(tempmax * 1000) / 1000; | ||
roundedvals.Add(tempmax); | ||
} | ||
|
||
// do min | ||
if (min == 0) { | ||
roundedvals.Add(0); | ||
} else { | ||
double tempmin = scale * Math.Round(min / scale, 4); | ||
tempmin = Math.Floor(tempmin * 1000) / 1000; | ||
roundedvals.Add(tempmin); | ||
} | ||
|
||
return roundedvals; | ||
} | ||
} | ||
} |
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> | ||
<TargetFramework>net7.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="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.extensibility.core" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AdSecCore\AdSecCore.csproj"/> | ||
</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,16 @@ | ||
using AdSecGHCore.Helpers; | ||
|
||
namespace AdSecCoreTests { | ||
public class DoubleComparerTests { | ||
[Fact] | ||
public void ValuesDifferLessThanEpsilonShouldBeConsideredEqual() { | ||
Assert.Equal(10.0, 10.01, new DoubleComparer()); | ||
} | ||
|
||
[Fact] | ||
public void ValuesLargerThanEpsilonShouldBeConsideredEqual() { | ||
int epsilon = 1; | ||
Assert.NotEqual(10.0, 10.0 + (epsilon * 2), new DoubleComparer(epsilon, true)); | ||
} | ||
} | ||
} |
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
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,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dcccd273_002Dab94_002D4b0c_002D8563_002D940157ce25e3/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<Solution />
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
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
Oops, something went wrong.