-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
23b88f6
commit 859b0ed
Showing
9 changed files
with
587 additions
and
412 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace PanoramicData.NCalcExtensions.Test; | ||
|
||
public class MaxValueTests | ||
{ | ||
[Theory] | ||
[InlineData("sbyte", sbyte.MaxValue)] | ||
[InlineData("byte", byte.MaxValue)] | ||
[InlineData("short", short.MaxValue)] | ||
[InlineData("ushort", ushort.MaxValue)] | ||
[InlineData("int", int.MaxValue)] | ||
[InlineData("uint", uint.MaxValue)] | ||
[InlineData("long", long.MaxValue)] | ||
[InlineData("ulong", ulong.MaxValue)] | ||
[InlineData("float", float.MaxValue)] | ||
[InlineData("double", double.MaxValue)] | ||
public void MaxValue_ReturnsExpectedValue(string type, object expectedOutput) | ||
{ | ||
var expression = new ExtendedExpression($"maxValue('{type}')"); | ||
expression.Evaluate().Should().BeEquivalentTo(expectedOutput); | ||
} | ||
|
||
[Fact] | ||
public void MaxValue_ForDecimal_ReturnsExpectedValue() | ||
{ | ||
var expression = new ExtendedExpression($"maxValue('decimal')"); | ||
expression.Evaluate().Should().BeEquivalentTo(decimal.MaxValue); | ||
} | ||
|
||
[Fact] | ||
public void MaxValue_ForUnsupportedType_ThrowsFormatException() | ||
{ | ||
var expression = new ExtendedExpression($"maxValue('unsupportedType')"); | ||
expression.Invoking(x => x.Evaluate()).Should().Throw<FormatException>(); | ||
} | ||
} |
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,35 @@ | ||
namespace PanoramicData.NCalcExtensions.Test; | ||
|
||
public class MinValueTests | ||
{ | ||
[Theory] | ||
[InlineData("sbyte", sbyte.MinValue)] | ||
[InlineData("byte", byte.MinValue)] | ||
[InlineData("short", short.MinValue)] | ||
[InlineData("ushort", ushort.MinValue)] | ||
[InlineData("int", int.MinValue)] | ||
[InlineData("uint", uint.MinValue)] | ||
[InlineData("long", long.MinValue)] | ||
[InlineData("ulong", ulong.MinValue)] | ||
[InlineData("float", float.MinValue)] | ||
[InlineData("double", double.MinValue)] | ||
public void MinValue_ReturnsExpectedValue(string type, object expectedOutput) | ||
{ | ||
var expression = new ExtendedExpression($"minValue('{type}')"); | ||
expression.Evaluate().Should().BeEquivalentTo(expectedOutput); | ||
} | ||
|
||
[Fact] | ||
public void MinValue_ForDecimal_ReturnsExpectedValue() | ||
{ | ||
var expression = new ExtendedExpression($"minValue('decimal')"); | ||
expression.Evaluate().Should().BeEquivalentTo(decimal.MinValue); | ||
} | ||
|
||
[Fact] | ||
public void MinValue_ForUnsupportedType_ThrowsFormatException() | ||
{ | ||
var expression = new ExtendedExpression($"minValue('unsupportedType')"); | ||
expression.Invoking(x => x.Evaluate()).Should().Throw<FormatException>(); | ||
} | ||
} |
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
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,34 @@ | ||
namespace PanoramicData.NCalcExtensions.Extensions; | ||
|
||
internal static class MaxValue | ||
{ | ||
private const string ErrorMessage = $"{ExtensionFunction.MaxValue} takes exactly one string parameter, which must be one of 'sbyte', 'byte', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'float', 'double' or 'decimal'."; | ||
|
||
internal static void Evaluate(FunctionArgs functionArgs) | ||
{ | ||
var originalList = functionArgs.Parameters[0].Evaluate(); | ||
|
||
if (functionArgs.Parameters.Length != 1) | ||
{ | ||
throw new FormatException(ErrorMessage); | ||
} | ||
|
||
functionArgs.Result = originalList switch | ||
{ | ||
"sbyte" => sbyte.MaxValue, | ||
"byte" => byte.MaxValue, | ||
"short" => short.MaxValue, | ||
"ushort" => ushort.MaxValue, | ||
"int" => int.MaxValue, | ||
"uint" => uint.MaxValue, | ||
"long" => long.MaxValue, | ||
"ulong" => ulong.MaxValue, | ||
"float" => float.MaxValue, | ||
"double" => double.MaxValue, | ||
"decimal" => decimal.MaxValue, | ||
_ => throw new FormatException(ErrorMessage) | ||
}; | ||
|
||
return; | ||
} | ||
} |
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,34 @@ | ||
namespace PanoramicData.NCalcExtensions.Extensions; | ||
|
||
internal static class MinValue | ||
{ | ||
private const string ErrorMessage = $"{ExtensionFunction.MinValue} takes exactly one string parameter, which must be one of 'sbyte', 'byte', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'float', 'double' or 'decimal'."; | ||
|
||
internal static void Evaluate(FunctionArgs functionArgs) | ||
{ | ||
var originalList = functionArgs.Parameters[0].Evaluate(); | ||
|
||
if (functionArgs.Parameters.Length != 1) | ||
{ | ||
throw new FormatException(ErrorMessage); | ||
} | ||
|
||
functionArgs.Result = originalList switch | ||
{ | ||
"sbyte" => sbyte.MinValue, | ||
"byte" => byte.MinValue, | ||
"short" => short.MinValue, | ||
"ushort" => ushort.MinValue, | ||
"int" => int.MinValue, | ||
"uint" => uint.MinValue, | ||
"long" => long.MinValue, | ||
"ulong" => ulong.MinValue, | ||
"float" => float.MinValue, | ||
"double" => double.MinValue, | ||
"decimal" => decimal.MinValue, | ||
_ => throw new FormatException(ErrorMessage) | ||
}; | ||
|
||
return; | ||
} | ||
} |
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.