Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow input params as output params #44

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Nethermind.Int256.Benchmark/Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Numbers
public static readonly BigInteger TwoTo256 = TwoTo128 * TwoTo128;
public static readonly BigInteger UInt256Max = TwoTo256 - 1;

public static readonly BigInteger Int256Max = ( BigInteger.One << 255 ) - 1;
public static readonly BigInteger Int256Max = (BigInteger.One << 255) - 1;
public static readonly BigInteger Int256Min = -Int256Max;
}
}
4 changes: 2 additions & 2 deletions src/Nethermind.Int256.Test/Convertibles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@
(typeof(decimal), (BigInteger?)decimal.MinValue, (BigInteger?)decimal.MaxValue),
(typeof(BigInteger), null, null)
};

public static IEnumerable<TestCaseData> TestCases => GenerateTestCases(Numbers, BigInteger.Zero);
public static IEnumerable<TestCaseData> SignedTestCases => GenerateTestCases(SignedNumbers);

private static IEnumerable<TestCaseData> GenerateTestCases(IEnumerable<(object, string)> numbers, BigInteger? minValue = null)
{
Type ExpectedException(BigInteger value, BigInteger? min, BigInteger? max) =>
(!min.HasValue || !max.HasValue || (value >= min && value <= max)) && (!minValue.HasValue || value >= minValue)

Check warning on line 86 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 0)

Possible null reference return.

Check warning on line 86 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 1)

Possible null reference return.

Check warning on line 86 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 0)

Possible null reference return.

Check warning on line 86 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 1)

Possible null reference return.
? null
: typeof(OverflowException);

string ExpectedString(Type type, BigInteger value, BigInteger? min, ref Type expectedException)
{
string expectedString = null;

Check warning on line 92 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 0)

Converting null literal or possible null value to non-nullable type.

Check warning on line 92 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 1)

Converting null literal or possible null value to non-nullable type.

Check warning on line 92 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 0)

Converting null literal or possible null value to non-nullable type.

Check warning on line 92 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 1)

Converting null literal or possible null value to non-nullable type.
if (expectedException is not null && type == typeof(float))
{
expectedString = value < min ? "-∞" : "∞";
expectedException = null;

Check warning on line 96 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 0)

Cannot convert null literal to non-nullable reference type.

Check warning on line 96 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 1)

Cannot convert null literal to non-nullable reference type.

Check warning on line 96 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 0)

Cannot convert null literal to non-nullable reference type.

Check warning on line 96 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 1)

Cannot convert null literal to non-nullable reference type.
}

return expectedString;

Check warning on line 99 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 0)

Possible null reference return.

Check warning on line 99 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (debug, 1)

Possible null reference return.

Check warning on line 99 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 0)

Possible null reference return.

Check warning on line 99 in src/Nethermind.Int256.Test/Convertibles.cs

View workflow job for this annotation

GitHub Actions / Test (release, 1)

Possible null reference return.
}

foreach ((object number, string name) in numbers)
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind.Int256.Test/Int256Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ string Expected(string valueString)
{
if (valueString.Contains("Infinity"))
{
return valueString.StartsWith('-') ? "-∞" : "∞" ;
return valueString.StartsWith('-') ? "-∞" : "∞";
}
string expected = valueString.Replace(",", "");
return type == typeof(float) ? expected[..Math.Min(6, expected.Length)] : type == typeof(double) ? expected[..Math.Min(14, expected.Length)] : expected;
Expand All @@ -77,7 +77,7 @@ string Expected(string valueString)
string convertedValue = Expected(((IFormattable)System.Convert.ChangeType(item, type)).ToString("0.#", null));
convertedValue.Should().BeEquivalentTo(expected);
}
catch (Exception e) when(e.GetType() == expectedException) { }
catch (Exception e) when (e.GetType() == expectedException) { }
}
}
}
2 changes: 1 addition & 1 deletion src/Nethermind.Int256.Test/TestNumbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class TestNumbers
public static readonly BigInteger TwoTo256 = TwoTo128 * TwoTo128;
public static readonly BigInteger UInt256Max = TwoTo256 - 1;

public static readonly BigInteger Int256Max = (BigInteger.One << 255)-1;
public static readonly BigInteger Int256Max = (BigInteger.One << 255) - 1;
public static readonly BigInteger Int256Min = -Int256Max;
}
}
Loading
Loading