Skip to content

Commit

Permalink
fix: updated failing numeric tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dtanglr committed Mar 31, 2024
1 parent c7819ee commit e6e87ae
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Primitively.Abstractions" Version="1.5.0-alpha.14" />
<PackageReference Include="Primitively.Abstractions" Version="1.5.0-alpha.18" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Primitively" Version="1.5.0-alpha.14" PrivateAssets="all" />
<PackageReference Include="Primitively" Version="1.5.0-alpha.18" PrivateAssets="all" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<PackageOutputPath>$(MSBuildThisFileDirectory)..\artifacts</PackageOutputPath>
<version>1.5.0-alpha.15</version>
<version>1.5.0-alpha.18</version>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 11 additions & 14 deletions src/Primitively/EmbeddedResources/Numeric/FloatingPoint/Base.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
readonly partial record struct PRIMITIVE_TYPE : global::PRIMITIVE_INTERFACE, global::System.IEquatable<PRIMITIVE_TYPE>, global::System.IComparable<PRIMITIVE_TYPE>PRIMITIVE_IVALIDATABLEOBJECT
{
private readonly global::PRIMITIVE_VALUE_TYPE _value = global::PRIMITIVE_VALUE_TYPE.NaN;
private readonly global::PRIMITIVE_VALUE_TYPE _value = default;

public const string Example = "PRIMITIVE_EXAMPLE";
public const global::PRIMITIVE_VALUE_TYPE Minimum = PRIMITIVE_MINIMUM;
public const global::PRIMITIVE_VALUE_TYPE Maximum = PRIMITIVE_MAXIMUM;
public const int Digits = PRIMITIVE_ROUNDINGDIGITS;
public const global::System.MidpointRounding Mode = global::System.MidpointRounding.PRIMITIVE_MIDPOINTROUNDINGMODE;

public PRIMITIVE_TYPE()
{
HasValue = IsMatch(_value);
}

public PRIMITIVE_TYPE(global::PRIMITIVE_VALUE_TYPE value)
{
PreMatchCheck(ref value);

if (IsMatch(value))
{
_value = value;
HasValue = true;
}
HasValue = IsMatch(value);
_value = HasValue ? value : default;
}

private PRIMITIVE_TYPE(string value)
{
if (global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result))
{
PreMatchCheck(ref result);

if (IsMatch(result))
{
_value = result;
HasValue = true;
}
HasValue = IsMatch(result);
_value = HasValue ? result : default;
}
}

Expand All @@ -38,7 +35,7 @@ private PRIMITIVE_TYPE(string value)
global::PRIMITIVE_VALUE_TYPE global::Primitively.IPrimitive<global::PRIMITIVE_VALUE_TYPE>.Value => _value;

[global::System.Text.Json.Serialization.JsonIgnore]
public bool HasValue { get; }
public bool HasValue { get; } = false;

[global::System.Text.Json.Serialization.JsonIgnore]
public global::System.Type ValueType => typeof(global::PRIMITIVE_VALUE_TYPE);
Expand Down
25 changes: 13 additions & 12 deletions src/Primitively/EmbeddedResources/Numeric/Integer/Base.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
readonly partial record struct PRIMITIVE_TYPE : global::PRIMITIVE_INTERFACE, global::System.IEquatable<PRIMITIVE_TYPE>, global::System.IComparable<PRIMITIVE_TYPE>PRIMITIVE_IVALIDATABLEOBJECT
{
private readonly global::PRIMITIVE_VALUE_TYPE _value;
private readonly global::PRIMITIVE_VALUE_TYPE _value = default;

public const string Example = "PRIMITIVE_EXAMPLE";
public const global::PRIMITIVE_VALUE_TYPE Minimum = PRIMITIVE_MINIMUM;
public const global::PRIMITIVE_VALUE_TYPE Maximum = PRIMITIVE_MAXIMUM;

public PRIMITIVE_TYPE()
{
HasValue = IsMatch(_value);
}

public PRIMITIVE_TYPE(global::PRIMITIVE_VALUE_TYPE value)
{
if (value >= Minimum && value <= Maximum)
{
_value = value;
HasValue = true;
}
HasValue = IsMatch(value);
_value = HasValue ? value : default;
}

private PRIMITIVE_TYPE(string value)
{
if (global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && result >= Minimum && result <= Maximum)
{
_value = result;
HasValue = true;
}
HasValue = global::PRIMITIVE_VALUE_TYPE.TryParse(value, out var result) && IsMatch(result);
_value = HasValue ? result : default;
}

object global::Primitively.IPrimitive.Value => _value;

global::PRIMITIVE_VALUE_TYPE global::Primitively.IPrimitive<global::PRIMITIVE_VALUE_TYPE>.Value => _value;

[global::System.Text.Json.Serialization.JsonIgnore]
public bool HasValue { get; }
public bool HasValue { get; } = false;

[global::System.Text.Json.Serialization.JsonIgnore]
public global::System.Type ValueType => typeof(global::PRIMITIVE_VALUE_TYPE);
Expand All @@ -49,3 +48,5 @@ private PRIMITIVE_TYPE(string value)

public static PRIMITIVE_TYPE Parse(string value) => new(value);
public static bool TryParse(string value, out PRIMITIVE_TYPE result) => (result = new(value)).HasValue;

private static bool IsMatch(global::PRIMITIVE_VALUE_TYPE value) => value >= Minimum && value <= Maximum;
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public FluentValidationTests()
[InlineData("")]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("0")]
[InlineData("00")]
[InlineData("-1", true, true)]
[InlineData("0", true, true)]
[InlineData("00", true, true)]
[InlineData("001", true, true)]
[InlineData(DoubleId.Example, true, true)]
public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,15 @@ public class InstantiationTests
[InlineData("")]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("0")]
[InlineData("00")]
[InlineData("-1", true)]
[InlineData("0", true)]
[InlineData("00", true)]
[InlineData("001", true)]
[InlineData(DoubleId.Example, true)]
public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default)
public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false)
{
var expectedInteger = hasValue ? DoubleId.Parse(from) : default;
var expectedString = expectedInteger.ToString();

var @this = (DoubleId)from;
string to = @this;
var that = DoubleId.Parse(to);
var and = new DoubleId(that);
string back = and;
var @this = DoubleId.Parse(from);

@this.HasValue.Should().Be(hasValue);
@this.Should().Be(expectedInteger);
@this.ToString().Should().Be(expectedString);
to.Should().Be(expectedString);
that.HasValue.Should().Be(hasValue);
that.Should().Be(expectedInteger);
that.ToString().Should().Be(expectedString);
and.HasValue.Should().Be(hasValue);
and.Should().Be(expectedInteger);
and.ToString().Should().Be(expectedString);
back.Should().Be(expectedString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public FluentValidationTests()
[InlineData("")]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("0")]
[InlineData("00")]
[InlineData("-1", true, true)]
[InlineData("0", true, true)]
[InlineData("00", true, true)]
[InlineData("001", true, true)]
[InlineData(SingleId.Example, true, true)]
public void ConvertFromThisToThatWithExpectedResults(string? value, bool nonNullableIsValid = false, bool nullableIsValid = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,15 @@ public class InstantiationTests
[InlineData("")]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("0")]
[InlineData("00")]
[InlineData("-1", true)]
[InlineData("0", true)]
[InlineData("00", true)]
[InlineData("001", true)]
[InlineData(SingleId.Example, true)]
public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = default)
public void ConvertFromThisToThatWithExpectedResults(string? from, bool hasValue = false)
{
var expectedInteger = hasValue ? SingleId.Parse(from) : default;
var expectedString = expectedInteger.ToString();

var @this = (SingleId)from;
string to = @this;
var that = SingleId.Parse(to);
var and = new SingleId(that);
string back = and;
var @this = SingleId.Parse(from);

@this.HasValue.Should().Be(hasValue);
@this.Should().Be(expectedInteger);
@this.ToString().Should().Be(expectedString);
to.Should().Be(expectedString);
that.HasValue.Should().Be(hasValue);
that.Should().Be(expectedInteger);
that.ToString().Should().Be(expectedString);
and.HasValue.Should().Be(hasValue);
and.Should().Be(expectedInteger);
and.ToString().Should().Be(expectedString);
back.Should().Be(expectedString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PrimitiveRepositoryTests : PrimitiveTests
_ when type.IsAssignableTo(typeof(IDateOnly)) => typeof(DateOnlyInfo),
_ when type.IsAssignableTo(typeof(IGuid)) => typeof(GuidInfo),
_ when type.IsAssignableTo(typeof(IByte)) => typeof(NumericInfo<byte>),
_ when type.IsAssignableTo(typeof(IDouble)) => typeof(NumericInfo<double>),
_ when type.IsAssignableTo(typeof(IDouble)) => typeof(DoubleInfo),
_ when type.IsAssignableTo(typeof(IInt)) => typeof(NumericInfo<int>),
_ when type.IsAssignableTo(typeof(ILong)) => typeof(NumericInfo<long>),
_ when type.IsAssignableTo(typeof(ISByte)) => typeof(NumericInfo<sbyte>),
Expand Down

0 comments on commit e6e87ae

Please sign in to comment.