Skip to content

Commit

Permalink
Merge pull request #22 from CBenghi/fix/remove-range-tolerances
Browse files Browse the repository at this point in the history
Fix/remove range tolerances
  • Loading branch information
andyward authored Aug 30, 2024
2 parents c9693a8 + a1ff82b commit 8bb7250
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<nullable>Enable</nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="TextCopy" Version="6.2.1" />
<PackageReference Include="Xbim.Essentials" Version="6.0.445" />
<PackageReference Include="Xbim.Properties" Version="6.0.11" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ public void RangeConstraintSupportsNegativeFloats()
public void ExclusiveRangeConstraintShrinkTolerance()
{
var vc = new ValueConstraint(NetTypeName.Floating);

// 0 < x < 100
var t = new RangeConstraint()
{
MinValue = (0).ToString(),
Expand All @@ -286,7 +288,9 @@ public void ExclusiveRangeConstraintShrinkTolerance()

vc.IsSatisfiedBy(99.999999d).Should().BeFalse();
vc.IsSatisfiedBy(-1e-6d).Should().BeFalse();
vc.IsSatisfiedBy(1e-6d).Should().BeFalse();


vc.IsSatisfiedBy(1e-6d).Should().BeTrue(); // Was False in Initial IDS1.0 now True
// True
vc.IsSatisfiedBy(2e-6d).Should().BeTrue();
vc.IsSatisfiedBy(99.999d).Should().BeTrue();
Expand Down Expand Up @@ -343,7 +347,7 @@ public void CanCompareCaseInsensitivelyIgnoringAccents(string input, string cons

[InlineData(true)]
[InlineData(false)]
[Theory]
[Theory(Skip = "Not supported after IDS 1.0 Spec Change (IDS#318)")]
public void DoubleValueSupports1e6Tolerances(bool setBaseType)
{
// from IDS test property/pass-floating_point_numbers_are_compared_with_a_1e_6_tolerance_1_*.ifc && attribute equivalents
Expand All @@ -359,8 +363,8 @@ public void DoubleValueSupports1e6Tolerances(bool setBaseType)
}

[InlineData(true)]
[InlineData(false)]
[Theory]
[InlineData(false)]
[Theory(Skip = "Not supported after IDS 1.0 Spec Change (IDS#318)")]
public void NegativeDoubleValueSupports1e6Tolerances(bool setBaseType)
{
// from IDS test property/pass-floating_point_numbers_are_compared_with_a_1e_6_tolerance_1_*.ifc && attribute equivalents
Expand All @@ -382,9 +386,10 @@ public void NegativeDoubleValueSupports1e6Tolerances(bool setBaseType)
}


// Previously considered in range (true)
[InlineData(41.999958d, false, "originally within 1e-6 min tolerances - inclusive")]
[InlineData(50.000042d, false, "originally within 1e-6 max tolerances - inclusive")]

[InlineData(41.999958d, true, "within 1e-6 min tolerances - inclusive")]
[InlineData(50.000042d, true, "within 1e-6 max tolerances - inclusive")]
[InlineData(41.999916d, false, "outside 1e-6 min tolerances - inclusive")]
[InlineData(50.000084d, false, "outside 1e-6 max tolerances - inclusive")]
[Theory]
Expand All @@ -405,10 +410,12 @@ public void DoubleValueInclusiveRangesSupportTolerance(double input, bool expect

vc.IsSatisfiedBy(input).Should().Be(expectedToSatisfy, $"{input} is {reason}");
}

// Previously considered in range
[InlineData(-41.999958d, false, "within 1e-6 min tolerances - inclusive")]
[InlineData(-50.000042d, false, "within 1e-6 max tolerances - inclusive")]

[InlineData(-41.999958d, true, "within 1e-6 min tolerances - inclusive")]
[InlineData(-45d, true, "well within")]
[InlineData(-50.000042d, true, "within 1e-6 max tolerances - inclusive")]
[InlineData(-41.999916d, false, "outside 1e-6 min tolerances - inclusive")]
[InlineData(-50.000084d, false, "outside 1e-6 max tolerances - inclusive")]
[Theory]
Expand Down Expand Up @@ -438,15 +445,18 @@ public void DoubleNegativeValueInclusiveRangesSupportTolerance(double input, boo
[InlineData(42.000044d, true, "inside min tolerances for exclusive ranges")]
[InlineData(49.999948, true, "inside max tolerances for exclusive ranges")]

[InlineData(42.000001d, false, "Inside but outside min tolerances for exclusive ranges")]
[InlineData(49.999999d, false, "Inside but outside max tolerances for exclusive ranges")]
// Following were false in IDS1.0 but now inside
[InlineData(42.000001d, true, "Inside but outside min tolerances for exclusive ranges")]
[InlineData(49.999999d, true, "Inside but outside max tolerances for exclusive ranges")]
[Theory]
public void DoubleValueExclusiveRangesDoNotSupportTolerance(double input, bool expectedToSatisfy, string reason)
{
// Tolerences on Exclusive ranges make no sense
// E.g. Height must be < 50m. Assuming 50 fails, so must 50.0000000000001
// This does mean 49.9999999999998 < 50 succeeds - despite this potentially being an artefact of FP imprecision
var vc = new ValueConstraint(NetTypeName.Double);

// 42 < x < 50
var t = new RangeConstraint()
{
MinValue = 42.ToString(),
Expand All @@ -463,9 +473,11 @@ public void DoubleValueExclusiveRangesDoNotSupportTolerance(double input, bool e
}

[Fact]
public void ExclusiveRangeSupportToleranceMax()
public void ExclusiveRangeDoNotSupportToleranceMax()
{
var vc = new ValueConstraint(NetTypeName.Double);

// x < 0
var exclusive = new RangeConstraint()
{
MaxValue = 0.ToString(),
Expand All @@ -474,15 +486,17 @@ public void ExclusiveRangeSupportToleranceMax()
};
vc.AddAccepted(exclusive);

vc.IsSatisfiedBy(-0.0000009d).Should().BeFalse();
vc.IsSatisfiedBy(-0.0000009d).Should().BeTrue();


}

[Fact]
public void ExclusiveRangeSupportToleranceMin()
public void ExclusiveRangeDoNotSupportToleranceMin()
{
var vc = new ValueConstraint(NetTypeName.Double);

// x > 0
var exclusive = new RangeConstraint()
{
MinValue = 0.ToString(),
Expand All @@ -491,12 +505,12 @@ public void ExclusiveRangeSupportToleranceMin()
};
vc.AddAccepted(exclusive);

vc.IsSatisfiedBy(0.0000009d).Should().BeFalse();
vc.IsSatisfiedBy(0.0000009d).Should().BeTrue();

}

[Fact]
public void InclusiveRangeSupportToleranceMax()
public void InclusiveRangeDoNotSupportToleranceMax()
{
var vc = new ValueConstraint(NetTypeName.Double);
var exclusive = new RangeConstraint()
Expand All @@ -507,7 +521,7 @@ public void InclusiveRangeSupportToleranceMax()
};
vc.AddAccepted(exclusive);

vc.IsSatisfiedBy(1e-6).Should().BeTrue();
vc.IsSatisfiedBy(1e-6).Should().BeFalse(); // Was True in initial 1.0 IDS but late change removed support

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -26,16 +26,16 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="ids-lib" Version="1.0.77" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
10 changes: 6 additions & 4 deletions Xbim.InformationSpecifications/Values/RangeConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ public bool IsSatisfiedBy(object candidateValue, ValueConstraint context, bool i
if (MinValue is not null && !string.IsNullOrEmpty(MinValue))
{
var minimum = ValueConstraint.ParseValue(MinValue, context.BaseType);
var rangeType = MinInclusive ? RangeType.Inclusive : RangeType.Exclusive;
minimum = ApplyRealTolerances(minimum, rangeType, false);
// Range tolerances removed as part of https://github.com/buildingSMART/IDS/pull/318

//var rangeType = MinInclusive ? RangeType.Inclusive : RangeType.Exclusive;
//minimum = ApplyRealTolerances(minimum, rangeType, false);
minOk = MinInclusive
? valueToCompare.CompareTo(minimum) >= 0
: valueToCompare.CompareTo(minimum) > 0;
}
if (MaxValue is not null && !string.IsNullOrEmpty(MaxValue))
{
var maximum = ValueConstraint.ParseValue(MaxValue, context.BaseType);
var rangeType = MaxInclusive ? RangeType.Inclusive : RangeType.Exclusive;
maximum = ApplyRealTolerances(maximum, rangeType, true);
//var rangeType = MaxInclusive ? RangeType.Inclusive : RangeType.Exclusive;
//maximum = ApplyRealTolerances(maximum, rangeType, true);
maxOk = MaxInclusive
? valueToCompare.CompareTo(maximum) <= 0
: valueToCompare.CompareTo(maximum) < 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<AssemblyName>Xbim.InformationSpecifications</AssemblyName>
<RootNamespace>Xbim.InformationSpecifications</RootNamespace>
<!-- Remember to update the hardcoded AssemblyVersion property in XIDS-->
<AssemblyVersion>1.0.1</AssemblyVersion>
<AssemblyVersion>1.0.2</AssemblyVersion>
<!-- Remember to update the hardcoded AssemblyVersion property in XIDS-->
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
Expand Down Expand Up @@ -57,7 +57,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
<!--
the following two targets tag the "product version" with version and commit hash
Expand Down
2 changes: 1 addition & 1 deletion Xbim.InformationSpecifications/Xids.AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public partial class Xids
/// This is useful for environments that do not allow to load information from the DLL dynamically
/// (e.g. Blazor).
/// </summary>
public static string AssemblyVersion => "1.0.1";
public static string AssemblyVersion => "1.0.2";
}
}

0 comments on commit 8bb7250

Please sign in to comment.