From 4fa6d7f93c0afc59253daebada93f37aec96989f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 12 Jan 2026 10:23:31 +0100 Subject: [PATCH 01/24] Added plus and minus functions. --- .../Expressions/ExpressionEvaluator.cs | 37 ++++++++++++++++--- .../Internal/Expressions/ExpressionValue.cs | 18 ++++----- .../Models/Expressions/ExpressionFunction.cs | 10 +++++ .../CommonTests/TestFunctions.cs | 8 ++++ .../minus/subtracting-negative-values.json | 5 +++ .../minus/subtracting-null-values.json | 5 +++ .../minus/subtracting-one-null-value.json | 5 +++ .../functions/minus/sutracting-decimals.json | 5 +++ .../functions/plus/adding-decimals.json | 5 +++ .../plus/adding-negative-values.json | 5 +++ .../functions/plus/adding-null-values.json | 5 +++ .../functions/plus/adding-one-null-value.json | 5 +++ .../ExpressionValueTests.cs | 2 +- 13 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 841f4ddc87..97314b4469 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -127,6 +127,9 @@ internal static async Task EvaluateExpression_internal( ExpressionFunction.argv => Argv(args, positionalArguments), ExpressionFunction.gatewayAction => state.GetGatewayAction(), ExpressionFunction.language => state.GetLanguage(), + // Calculations: + ExpressionFunction.plus => Plus(args), + ExpressionFunction.minus => Minus(args), ExpressionFunction.INVALID => throw new ExpressionEvaluatorTypeErrorException( $"Function {expr.Args.FirstOrDefault()} not implemented in backend {expr}" ), @@ -610,8 +613,8 @@ private static int StringLength(ExpressionValue[] args) throw new ExpressionEvaluatorTypeErrorException($"Expected 2-3 arguments, got {args.Length}"); } string? subject = args[0].ToStringForEquals(); - double? start = PrepareNumericArg(args[1]); - double? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; + decimal? start = PrepareNumericArg(args[1]); + decimal? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; bool hasEnd = args.Length == 3; if (start == null || (hasEnd && end == null)) @@ -805,7 +808,7 @@ ExpressionValue[] args return !PrepareBooleanArg(args[0]); } - private static (double?, double?) PrepareNumericArgs(ExpressionValue[] args) + private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) { if (args.Length != 2) { @@ -819,7 +822,7 @@ private static (double?, double?) PrepareNumericArgs(ExpressionValue[] args) return (a, b); } - private static double? PrepareNumericArg(ExpressionValue arg) + private static decimal? PrepareNumericArg(ExpressionValue arg) { return arg.ValueKind switch { @@ -862,9 +865,9 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) private static readonly Regex _numberRegex = new Regex(@"^-?\d+(\.\d+)?$"); - internal static double? ParseNumber(string s, bool throwException = true) + internal static decimal? ParseNumber(string s, bool throwException = true) { - if (_numberRegex.IsMatch(s) && double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) + if (_numberRegex.IsMatch(s) && decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) { return d; } @@ -887,6 +890,28 @@ private static bool LessThan(ExpressionValue[] args) return a < b; // Actual implementation } + private static string Plus(ExpressionValue[] args) + { + var (a, b) = PrepareNumericArgs(args); + a ??= 0; + b ??= 0; + return (a + b).Value.ToString(CultureInfo.InvariantCulture); + } + + private static string Minus(ExpressionValue[] args) + { + var (a, b) = PrepareNumericArgs(args); + if (a is null || b is null) + { + throw new ExpressionEvaluatorTypeErrorException( + "One or both arguments were null or undefined. Cannot subtract.", + ExpressionFunction.minus, + args + ); + } + return (a - b).Value.ToString(CultureInfo.InvariantCulture); + } + private static bool LessThanEq(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 22614733c6..e0329fb184 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -17,7 +17,7 @@ namespace Altinn.App.Core.Internal.Expressions; private readonly string? _stringValue = null; // double is a value type where nullable takes extra space, and we only read it when it should be set - private readonly double _numberValue = 0; + private readonly decimal _numberValue = 0; // private readonly Dictionary? _objectValue = null; // private readonly ExpressionValue[]? _arrayValue = null; @@ -65,7 +65,7 @@ private ExpressionValue(bool? value) } } - private ExpressionValue(double? value) + private ExpressionValue(decimal? value) { if (value.HasValue) { @@ -104,7 +104,7 @@ private ExpressionValue(string? value) /// /// Convert a nullable double to ExpressionValue /// - public static implicit operator ExpressionValue(double? value) => new(value); + public static implicit operator ExpressionValue(decimal? value) => new(value); /// /// Convert a nullable string to ExpressionValue @@ -132,8 +132,8 @@ public static ExpressionValue FromObject(object? value) null => Null, bool boolValue => boolValue, string stringValue => stringValue, - float numberValue => numberValue, - double numberValue => numberValue, + float numberValue => (decimal)numberValue, // expressions uses double which needs an explicit cast + double numberValue => (decimal)numberValue, // expressions uses double which needs an explicit cast byte numberValue => numberValue, sbyte numberValue => numberValue, short numberValue => numberValue, @@ -142,9 +142,7 @@ public static ExpressionValue FromObject(object? value) uint numberValue => numberValue, long numberValue => numberValue, ulong numberValue => numberValue, - decimal numberValue => - (double?)numberValue // expressions uses double which needs an explicit cast - , + decimal numberValue => numberValue, DateTime dateTimeValue => JsonSerializer .Serialize(dateTimeValue, _unsafeSerializerOptionsForSerializingDates) .Trim( @@ -230,7 +228,7 @@ public static ExpressionValue FromObject(object? value) /// /// Get the value as a number (or throw if it isn't a number ValueKind) /// - public double Number => + public decimal Number => _valueKind switch { JsonValueKind.Number => _numberValue, @@ -457,7 +455,7 @@ public override ExpressionValue Read(ref Utf8JsonReader reader, Type typeToConve JsonTokenType.True => true, JsonTokenType.False => false, JsonTokenType.String => reader.GetString(), - JsonTokenType.Number => reader.GetDouble(), + JsonTokenType.Number => reader.GetDecimal(), JsonTokenType.Null => ExpressionValue.Null, // JsonTokenType.StartObject => ReadObject(ref reader), // JsonTokenType.StartArray => ReadArray(ref reader), diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs index f799c95a9f..2e8f25bc6c 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs @@ -205,4 +205,14 @@ public enum ExpressionFunction /// If no translations exist for the current language, we will use the resources for "nb" /// text, + + /// + /// Adding two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// + plus, + + /// + /// Subtracting a value from another. Use a period (.) as the decimals separator. Must be numeric values. + /// + minus, } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index ec7c206c8e..5ee18a960c 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -203,6 +203,14 @@ public TestFunctions(ITestOutputHelper output) [SharedTest("stringLength")] public async Task StringLength_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] + [SharedTest("plus")] + public async Task Plus_Theory(string testName, string folder) => await RunTestCase(testName, folder); + + [Theory] + [SharedTest("minus")] + public async Task Minus_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] [SharedTest("round")] public async Task Round_Theory(string testName, string folder) => await RunTestCase(testName, folder); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json new file mode 100644 index 0000000000..f566f3cb2c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract the second negative argument from the first", + "expression": ["minus", -0.1, -0.2], + "expects": "0.1" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json new file mode 100644 index 0000000000..e2baa3dca7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when both of the arguments are null", + "expression": ["minus", null, null], + "expectsFailure": "One or both arguments were null or undefined. Cannot subtract." +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json new file mode 100644 index 0000000000..d1b7896e42 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when one of the arguments is null", + "expression": ["minus", null, 2.1], + "expectsFailure": "One or both arguments were null or undefined. Cannot subtract." +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json new file mode 100644 index 0000000000..8f1d9acf64 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract the second argument from the first", + "expression": ["minus", 0.1, 0.2], + "expects": "-0.1" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json new file mode 100644 index 0000000000..be17d8483a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should add the two given numbers together", + "expression": ["plus", 0.1, 0.2], + "expects": "0.3" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json new file mode 100644 index 0000000000..abdf1a9380 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should add two negative numbers together", + "expression": ["plus", -4, -0.2], + "expects": "-4.2" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json new file mode 100644 index 0000000000..3c74b62a03 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 0 when values are null", + "expression": ["plus", null, null], + "expects": "0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json new file mode 100644 index 0000000000..6316b073ba --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json @@ -0,0 +1,5 @@ +{ + "name": "Should return the value that is a valid decimal when one of them is null", + "expression": ["plus", 4.3, null], + "expects": "4.3" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 4eaa01cc73..c6b99a7aa6 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -56,7 +56,7 @@ public void TestString() [Fact] public void TestDouble() { - double doubleValue = 123.456; + decimal doubleValue = 123.456m; ExpressionValue value = doubleValue; Assert.Equal(doubleValue, value.ToObject()); Assert.Equal(doubleValue, value.Number); From bc237c8c174ce1eeaf7cfb1bf713d51323626212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 28 Jan 2026 10:01:17 +0100 Subject: [PATCH 02/24] Added multiply and devide --- .../Expressions/ExpressionEvaluator.cs | 64 ++++++++++++++----- .../Models/Expressions/ExpressionFunction.cs | 10 +++ .../CommonTests/TestFunctions.cs | 10 ++- .../functions/devide/devide-decimals.json | 5 ++ .../devide/devide-negative-values.json | 5 ++ .../functions/devide/devide-null-values.json | 5 ++ .../devide/devide-one-null-value.json | 5 ++ .../minus/subtracting-null-values.json | 2 +- .../minus/subtracting-one-null-value.json | 2 +- .../functions/multiply/multiply-decimals.json | 5 ++ .../multiply/multiply-negative-values.json | 5 ++ .../multiply/multiply-null-values.json | 5 ++ .../multiply/multiply-one-null-value.json | 5 ++ .../functions/plus/adding-null-values.json | 4 +- .../functions/plus/adding-one-null-value.json | 4 +- .../ExpressionEvaluatorTests/EqualsTests.cs | 12 ++-- .../ExpressionValueTests.cs | 2 +- ...ouldNotChange_Unintentionally.verified.txt | 8 ++- 18 files changed, 125 insertions(+), 33 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index c2941b288f..6009f58462 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -130,6 +130,8 @@ internal static async Task EvaluateExpression_internal( // Calculations: ExpressionFunction.plus => Plus(args), ExpressionFunction.minus => Minus(args), + ExpressionFunction.multiply => Multiply(args), + ExpressionFunction.devide => Devide(args), ExpressionFunction.INVALID => throw new ExpressionEvaluatorTypeErrorException( $"Function {expr.Args.FirstOrDefault()} not implemented in backend {expr}" ), @@ -809,7 +811,7 @@ ExpressionValue[] args return !PrepareBooleanArg(args[0]); } - private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) + private static (decimal?, decimal?) PrepareTwoNumericArgs(ExpressionValue[] args) { if (args.Length != 2) { @@ -823,6 +825,16 @@ private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) return (a, b); } + private static IEnumerable PrepareMultipleNumericArgs(ExpressionValue[] args) + { + return args.Select(arg => PrepareNumericArg(arg)) + .Select(x => + !x.HasValue + ? throw new ExpressionEvaluatorTypeErrorException("At least one of the arguments is not a number") + : x.Value + ); + } + private static decimal? PrepareNumericArg(ExpressionValue arg) { return arg.ValueKind switch @@ -882,7 +894,7 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) private static bool LessThan(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareTwoNumericArgs(args); if (a is null || b is null) { @@ -893,29 +905,47 @@ private static bool LessThan(ExpressionValue[] args) private static string Plus(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); - a ??= 0; - b ??= 0; - return (a + b).Value.ToString(CultureInfo.InvariantCulture); + var numericArgs = PrepareMultipleNumericArgs(args); + return numericArgs.Sum(arg => arg).ToString(CultureInfo.InvariantCulture); } private static string Minus(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); - if (a is null || b is null) + var numericArgs = PrepareMultipleNumericArgs(args); + var sum = numericArgs.First(); + foreach (var arg in numericArgs.Skip(1)) { - throw new ExpressionEvaluatorTypeErrorException( - "One or both arguments were null or undefined. Cannot subtract.", - ExpressionFunction.minus, - args - ); + sum -= arg; + } + + return sum.ToString(CultureInfo.InvariantCulture); + } + + private static string Multiply(ExpressionValue[] args) + { + var numericArgs = PrepareMultipleNumericArgs(args); + var sum = numericArgs.First(); + foreach (var arg in numericArgs.Skip(1)) + { + sum *= arg; + } + return sum.ToString(CultureInfo.InvariantCulture); + } + + private static string Devide(ExpressionValue[] args) + { + var numericArgs = PrepareMultipleNumericArgs(args); + var sum = numericArgs.First(); + foreach (var arg in numericArgs.Skip(1)) + { + sum /= arg; } - return (a - b).Value.ToString(CultureInfo.InvariantCulture); + return sum.ToString(CultureInfo.InvariantCulture); } private static bool LessThanEq(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareTwoNumericArgs(args); if (a is null || b is null) { @@ -926,7 +956,7 @@ private static bool LessThanEq(ExpressionValue[] args) private static bool GreaterThan(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareTwoNumericArgs(args); if (a is null || b is null) { @@ -937,7 +967,7 @@ private static bool GreaterThan(ExpressionValue[] args) private static bool GreaterThanEq(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareTwoNumericArgs(args); if (a is null || b is null) { diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs index 2e8f25bc6c..cb150ab42f 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs @@ -215,4 +215,14 @@ public enum ExpressionFunction /// Subtracting a value from another. Use a period (.) as the decimals separator. Must be numeric values. /// minus, + + /// + /// Multiplying two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// + multiply, + + /// + /// Devide two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// + devide, } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 5ee18a960c..0034587f62 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -211,6 +211,14 @@ public TestFunctions(ITestOutputHelper output) [SharedTest("minus")] public async Task Minus_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] + [SharedTest("multiply")] + public async Task Multiply_Theory(string testName, string folder) => await RunTestCase(testName, folder); + + [Theory] + [SharedTest("devide")] + public async Task Devide_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] [SharedTest("round")] public async Task Round_Theory(string testName, string folder) => await RunTestCase(testName, folder); @@ -439,7 +447,7 @@ private async Task RunTestCaseItem( Assert.Null(result); break; case JsonValueKind.Number: - Assert.Equal(test.Expects.GetDouble(), result); + Assert.Equal(test.Expects.GetDecimal(), result); break; case JsonValueKind.Undefined: diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json new file mode 100644 index 0000000000..325d9f68ee --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should devide the first argument with the second", + "expression": ["devide", 0.1, 0.2], + "expects": "0.5" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json new file mode 100644 index 0000000000..7935103498 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should devide the first argument with the second", + "expression": ["devide", -0.1, -0.2], + "expects": "0.5" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json new file mode 100644 index 0000000000..51fbfaad7a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when both of the arguments are null", + "expression": ["devide", null, null], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json new file mode 100644 index 0000000000..2267a11068 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when one of the arguments is null", + "expression": ["devide", null, 2.1], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json index e2baa3dca7..75eb1befb3 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when both of the arguments are null", "expression": ["minus", null, null], - "expectsFailure": "One or both arguments were null or undefined. Cannot subtract." + "expectsFailure": "At least one of the arguments is not a number" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json index d1b7896e42..f8c494afd6 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when one of the arguments is null", "expression": ["minus", null, 2.1], - "expectsFailure": "One or both arguments were null or undefined. Cannot subtract." + "expectsFailure": "At least one of the arguments is not a number" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json new file mode 100644 index 0000000000..d97333ed0c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply the two arguments", + "expression": ["multiply", 0.1, 0.2], + "expects": "0.02" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json new file mode 100644 index 0000000000..8880981f9e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply the two negative arguments", + "expression": ["multiply", -0.1, -0.2], + "expects": "0.02" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json new file mode 100644 index 0000000000..e5621fb813 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when both of the arguments are null", + "expression": ["multiply", null, null], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json new file mode 100644 index 0000000000..dfd04c6b55 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when one of the arguments is null", + "expression": ["multiply", null, 2.1], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json index 3c74b62a03..75fdfebcb6 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json @@ -1,5 +1,5 @@ { - "name": "Should return 0 when values are null", + "name": "Should throw exception when both of the arguments are null", "expression": ["plus", null, null], - "expects": "0" + "expectsFailure": "At least one of the arguments is not a number" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json index 6316b073ba..3a77acc4fa 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json @@ -1,5 +1,5 @@ { - "name": "Should return the value that is a valid decimal when one of them is null", + "name": "Should throw exception when one of the arguments is null", "expression": ["plus", 4.3, null], - "expects": "4.3" + "expectsFailure": "At least one of the arguments is not a number" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs index b34947d406..9122e60f29 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs @@ -50,12 +50,12 @@ public static TheoryData GetNumericTestData(double value) DateTimeOffset.Parse("2025-02-04T13:13:15.84473533+01:00"), DateOnly.FromDateTime(DateTime.Parse("2025-02-04T13:13:15.8447353+01:00")), TimeOnly.FromDateTime(DateTime.Parse("2025-02-04T13:13:15.8447353+01:00")), - ((long)int.MaxValue) + 1, - ((ulong)uint.MaxValue) + 1, - ((decimal)int.MaxValue) + 1, - ((decimal)uint.MaxValue) + 1, - (double)((decimal)long.MaxValue + 1), - (double)((decimal)ulong.MaxValue + 1), + (long)int.MaxValue + 1, + (ulong)uint.MaxValue + 1, + (decimal)int.MaxValue + 1, + (decimal)uint.MaxValue + 1, + (decimal)long.MaxValue + 1, + (decimal)ulong.MaxValue + 1, }; [Theory] diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 3bfec6fd1e..138d623505 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -228,7 +228,7 @@ public void TestObjectsFail() public void TestTryDeserializeVariousTypes() { TestTryDeserialize(2, 2.0, true); - TestTryDeserialize(2.5, 2.5, true); + TestTryDeserialize(2.5m, 2.5, true); TestTryDeserialize("test", "test", true); TestTryDeserialize(true, true, true); TestTryDeserialize(false, false, true); diff --git a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt index 2fa93e000d..e1c13bba1a 100644 --- a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt +++ b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt @@ -3130,7 +3130,7 @@ namespace Altinn.App.Core.Internal.Expressions { public ExpressionValue() { } public bool Bool { get; } - public double Number { get; } + public decimal Number { get; } public string String { get; } public System.Text.Json.JsonValueKind ValueKind { get; } public static Altinn.App.Core.Internal.Expressions.ExpressionValue False { get; } @@ -3149,7 +3149,7 @@ namespace Altinn.App.Core.Internal.Expressions public bool TryDeserialize(out T? result) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue FromObject(object? value) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(bool? value) { } - public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(double? value) { } + public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(decimal? value) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(string? value) { } public static bool operator !=(Altinn.App.Core.Internal.Expressions.ExpressionValue left, Altinn.App.Core.Internal.Expressions.ExpressionValue right) { } public static bool operator ==(Altinn.App.Core.Internal.Expressions.ExpressionValue left, Altinn.App.Core.Internal.Expressions.ExpressionValue right) { } @@ -4585,6 +4585,10 @@ namespace Altinn.App.Core.Models.Expressions gatewayAction = 34, language = 35, text = 36, + plus = 37, + minus = 38, + multiply = 39, + devide = 40, } } namespace Altinn.App.Core.Models.Layout.Components.Base From 65fd9942a5eaf893c36b25de951440a75fa9f529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 28 Jan 2026 12:59:27 +0100 Subject: [PATCH 03/24] Added average and more unit tests for function --- .../Internal/Expressions/ExpressionEvaluator.cs | 12 ++++++++++++ .../Models/Expressions/ExpressionFunction.cs | 13 +++++++++---- .../LayoutExpressions/CommonTests/TestFunctions.cs | 4 ++++ .../functions/average/average-decimals.json | 5 +++++ .../average/average-multiple-decimals.json | 5 +++++ .../functions/average/average-negative-values.json | 5 +++++ .../functions/average/average-null-values.json | 5 +++++ .../functions/average/average-one-null-value.json | 5 +++++ .../functions/devide/devide-multiple-decimals.json | 5 +++++ ...ting-decimals.json => subtracting-decimals.json} | 0 .../minus/subtracting-multiple-decimals.json | 5 +++++ .../multiply/multiply-multiple-decimals.json | 5 +++++ .../functions/plus/adding-multiple-values.json | 5 +++++ 13 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{sutracting-decimals.json => subtracting-decimals.json} (100%) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 6009f58462..8ce82011db 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -132,6 +132,7 @@ internal static async Task EvaluateExpression_internal( ExpressionFunction.minus => Minus(args), ExpressionFunction.multiply => Multiply(args), ExpressionFunction.devide => Devide(args), + ExpressionFunction.average => Average(args), ExpressionFunction.INVALID => throw new ExpressionEvaluatorTypeErrorException( $"Function {expr.Args.FirstOrDefault()} not implemented in backend {expr}" ), @@ -943,6 +944,17 @@ private static string Devide(ExpressionValue[] args) return sum.ToString(CultureInfo.InvariantCulture); } + private static string Average(ExpressionValue[] args) + { + var numericArgs = PrepareMultipleNumericArgs(args); + var sum = 0m; + foreach (var arg in numericArgs) + { + sum += arg; + } + return (sum / numericArgs.Count()).ToString(CultureInfo.InvariantCulture); + } + private static bool LessThanEq(ExpressionValue[] args) { var (a, b) = PrepareTwoNumericArgs(args); diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs index cb150ab42f..f7566b675d 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs @@ -207,22 +207,27 @@ public enum ExpressionFunction text, /// - /// Adding two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// Adding numbers. Use a period (.) as the decimals separator. Must be numeric values. /// plus, /// - /// Subtracting a value from another. Use a period (.) as the decimals separator. Must be numeric values. + /// Subtracting all preceding values from the first. Use a period (.) as the decimals separator. Must be numeric values. /// minus, /// - /// Multiplying two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// Multiplying numbers. Use a period (.) as the decimals separator. Must be numeric values. /// multiply, /// - /// Devide two numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// Devide numbers. Use a period (.) as the decimals separator. Must be numeric values. /// devide, + + /// + /// Calculate the average of all values. Use a period (.) as the decimals separator. Must be numeric values. + /// + average, } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 0034587f62..d271254bfa 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -219,6 +219,10 @@ public TestFunctions(ITestOutputHelper output) [SharedTest("devide")] public async Task Devide_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] + [SharedTest("average")] + public async Task Average_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [Theory] [SharedTest("round")] public async Task Round_Theory(string testName, string folder) => await RunTestCase(testName, folder); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json new file mode 100644 index 0000000000..948be417fd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should average the two arguments", + "expression": ["average", 0.1, 0.2], + "expects": "0.15" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json new file mode 100644 index 0000000000..2b21e1b48c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should average multiple arguments", + "expression": ["average", 0.1, 0.2, 15, 1.50], + "expects": "4.2" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json new file mode 100644 index 0000000000..ed6d5d0a0e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should average the two arguments", + "expression": ["average", -0.1, -0.2], + "expects": "-0.15" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json new file mode 100644 index 0000000000..2239f9229c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when both of the arguments are null", + "expression": ["average", null, null], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json new file mode 100644 index 0000000000..c31931783a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when one of the arguments is null", + "expression": ["average", null, 2.1], + "expectsFailure": "At least one of the arguments is not a number" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json new file mode 100644 index 0000000000..ca9af176cd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should devide the first argument multiple times", + "expression": ["devide", 0.1, 0.2, 15, 1.50], + "expects": "4.2" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/sutracting-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json new file mode 100644 index 0000000000..82b92d0547 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract the proceeding arguments from the first", + "expression": ["minus", 0.1, 0.2, 15, 1.50], + "expects": "-16.6" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json new file mode 100644 index 0000000000..7cd8600e0f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply multiple arguments", + "expression": ["multiply", 0.1, 0.2, 15, 1.50], + "expects": "0.450" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json new file mode 100644 index 0000000000..6689fd2075 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should add multiple arguments", + "expression": ["plus", 0.1, 0.2, 15, 1.50], + "expects": "16.8" +} From 4882838bbfda3d404b4663c6177c15119ad7124d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 28 Jan 2026 13:29:31 +0100 Subject: [PATCH 04/24] Renamed devide to divide --- .../Internal/Expressions/ExpressionEvaluator.cs | 4 ++-- src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs | 4 ++-- src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs | 4 ++-- .../LayoutExpressions/CommonTests/TestFunctions.cs | 4 ++-- .../shared-tests/functions/devide/devide-decimals.json | 5 ----- .../functions/devide/devide-multiple-decimals.json | 5 ----- .../functions/devide/devide-negative-values.json | 5 ----- .../shared-tests/functions/divide/divide-decimals.json | 5 +++++ .../functions/divide/divide-multiple-decimals.json | 5 +++++ .../functions/divide/divide-negative-values.json | 5 +++++ .../divide-null-values.json} | 2 +- .../divide-one-null-value.json} | 2 +- 12 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/{devide/devide-null-values.json => divide/divide-null-values.json} (78%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/{devide/devide-one-null-value.json => divide/divide-one-null-value.json} (78%) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 8ce82011db..f909923b33 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -131,7 +131,7 @@ internal static async Task EvaluateExpression_internal( ExpressionFunction.plus => Plus(args), ExpressionFunction.minus => Minus(args), ExpressionFunction.multiply => Multiply(args), - ExpressionFunction.devide => Devide(args), + ExpressionFunction.divide => Divide(args), ExpressionFunction.average => Average(args), ExpressionFunction.INVALID => throw new ExpressionEvaluatorTypeErrorException( $"Function {expr.Args.FirstOrDefault()} not implemented in backend {expr}" @@ -933,7 +933,7 @@ private static string Multiply(ExpressionValue[] args) return sum.ToString(CultureInfo.InvariantCulture); } - private static string Devide(ExpressionValue[] args) + private static string Divide(ExpressionValue[] args) { var numericArgs = PrepareMultipleNumericArgs(args); var sum = numericArgs.First(); diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index d9273e94c8..5bfece7a45 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -131,8 +131,8 @@ public static ExpressionValue FromObject(object? value) null => Null, bool boolValue => boolValue, string stringValue => stringValue, - float numberValue => (decimal)numberValue, // expressions uses double which needs an explicit cast - double numberValue => (decimal)numberValue, // expressions uses double which needs an explicit cast + float numberValue => (decimal?)numberValue, // expressions uses double which needs an explicit cast + double numberValue => (decimal?)numberValue, // expressions uses double which needs an explicit cast byte numberValue => numberValue, sbyte numberValue => numberValue, short numberValue => numberValue, diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs index f7566b675d..361698b0ef 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs @@ -222,9 +222,9 @@ public enum ExpressionFunction multiply, /// - /// Devide numbers. Use a period (.) as the decimals separator. Must be numeric values. + /// Divide numbers. Use a period (.) as the decimals separator. Must be numeric values. /// - devide, + divide, /// /// Calculate the average of all values. Use a period (.) as the decimals separator. Must be numeric values. diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index d271254bfa..aa2f6f8e5a 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -216,8 +216,8 @@ public TestFunctions(ITestOutputHelper output) public async Task Multiply_Theory(string testName, string folder) => await RunTestCase(testName, folder); [Theory] - [SharedTest("devide")] - public async Task Devide_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [SharedTest("divide")] + public async Task Divide_Theory(string testName, string folder) => await RunTestCase(testName, folder); [Theory] [SharedTest("average")] diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json deleted file mode 100644 index 325d9f68ee..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should devide the first argument with the second", - "expression": ["devide", 0.1, 0.2], - "expects": "0.5" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json deleted file mode 100644 index ca9af176cd..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-multiple-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should devide the first argument multiple times", - "expression": ["devide", 0.1, 0.2, 15, 1.50], - "expects": "4.2" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json deleted file mode 100644 index 7935103498..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-negative-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should devide the first argument with the second", - "expression": ["devide", -0.1, -0.2], - "expects": "0.5" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json new file mode 100644 index 0000000000..1b8fcd5d35 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide the first argument with the second", + "expression": ["divide", 0.1, 0.2], + "expects": "0.5" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json new file mode 100644 index 0000000000..a3c4d16f81 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide the first argument multiple times", + "expression": ["divide", 0.1, 0.2, 15, 1.50], + "expects": "0.0222222222222222222222222222" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json new file mode 100644 index 0000000000..a963c9f0f3 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide the first argument with the second", + "expression": ["divide", -0.1, -0.2], + "expects": "0.5" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json similarity index 78% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json index 51fbfaad7a..979a8fd399 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when both of the arguments are null", - "expression": ["devide", null, null], + "expression": ["divide", null, null], "expectsFailure": "At least one of the arguments is not a number" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json similarity index 78% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json index 2267a11068..f8e6804df9 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/devide/devide-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when one of the arguments is null", - "expression": ["devide", null, 2.1], + "expression": ["divide", null, 2.1], "expectsFailure": "At least one of the arguments is not a number" } From 4f04237c4b7e3cfedaf8cac97cafaaff9428f294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 2 Feb 2026 18:35:56 +0100 Subject: [PATCH 05/24] Double fix --- src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs | 2 +- src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 5bfece7a45..03932599af 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -558,7 +558,7 @@ public bool TryDeserialize(Type type, out object? result) try { var json = ToString(); - result = JsonSerializer.Deserialize(json, type, _unsafeSerializerOptionsForSerializingDates); + result = JsonSerializer.Deserialize(json, type); return true; } catch (JsonException) diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs index 3095ad950b..477b2178d2 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs @@ -27,7 +27,7 @@ public static Expression ReadStatic(JsonElement element) => JsonValueKind.True => new Expression(true), JsonValueKind.False => new Expression(false), JsonValueKind.String => new Expression(element.GetString()), - JsonValueKind.Number => new Expression(element.GetDouble()), + JsonValueKind.Number => new Expression(element.GetDecimal()), JsonValueKind.Null => new Expression(ExpressionValue.Null), JsonValueKind.Array => ReadArray(element), JsonValueKind.Object => throw new JsonException("Invalid type \"object\""), @@ -44,7 +44,7 @@ public static Expression ReadStatic(ref Utf8JsonReader reader, JsonSerializerOpt JsonTokenType.True => new Expression(true), JsonTokenType.False => new Expression(false), JsonTokenType.String => new Expression(reader.GetString()), - JsonTokenType.Number => new Expression(reader.GetDouble()), + JsonTokenType.Number => new Expression(reader.GetDecimal()), JsonTokenType.Null => new Expression(ExpressionValue.Null), JsonTokenType.StartArray => ReadArray(ref reader, options), JsonTokenType.StartObject => throw new JsonException("Invalid type \"object\""), From 45396f25776c265c9503e9507e45508d3bfa8c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 2 Feb 2026 19:01:33 +0100 Subject: [PATCH 06/24] Fixed unit tests --- .../functions/average/average-multiple-decimals.json | 2 +- .../functions/minus/subtracting-multiple-decimals.json | 2 +- .../functions/multiply/multiply-multiple-decimals.json | 2 +- .../shared-tests/functions/plus/adding-multiple-values.json | 2 +- ...ests.PublicApi_ShouldNotChange_Unintentionally.verified.txt | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json index 2b21e1b48c..810dd9c7ca 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should average multiple arguments", "expression": ["average", 0.1, 0.2, 15, 1.50], - "expects": "4.2" + "expects": "4.20" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json index 82b92d0547..c00581eaa2 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should subtract the proceeding arguments from the first", "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expects": "-16.6" + "expects": "-16.60" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json index 7cd8600e0f..9b624dd179 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should multiply multiple arguments", "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expects": "0.450" + "expects": "0.4500" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json index 6689fd2075..6079c44131 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -1,5 +1,5 @@ { "name": "Should add multiple arguments", "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expects": "16.8" + "expects": "16.80" } diff --git a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt index e1c13bba1a..a66863f1bf 100644 --- a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt +++ b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt @@ -4588,7 +4588,8 @@ namespace Altinn.App.Core.Models.Expressions plus = 37, minus = 38, multiply = 39, - devide = 40, + divide = 40, + average = 41, } } namespace Altinn.App.Core.Models.Layout.Components.Base From e2ee639193ce659194ffac139248bccb30a3b885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Tue, 3 Feb 2026 10:48:10 +0100 Subject: [PATCH 07/24] Implemented CodeRabbits suggested changes --- .../Expressions/ExpressionEvaluator.cs | 28 +++++++++++++++---- .../Internal/Expressions/ExpressionValue.cs | 8 +++--- .../average/average-no-arguments.json | 5 ++++ .../functions/divide/divide-by-zero.json | 5 ++++ .../functions/divide/divide-one-argument.json | 5 ++++ .../minus/subtracting-no-arguments.json | 5 ++++ .../functions/plus/adding-no-arguments.json | 5 ++++ .../ExpressionValueTests.cs | 18 ++++++------ 8 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index f909923b33..cb03950f95 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -912,7 +912,11 @@ private static string Plus(ExpressionValue[] args) private static string Minus(ExpressionValue[] args) { - var numericArgs = PrepareMultipleNumericArgs(args); + if (args.Length == 0) + { + return "0"; + } + var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = numericArgs.First(); foreach (var arg in numericArgs.Skip(1)) { @@ -924,7 +928,7 @@ private static string Minus(ExpressionValue[] args) private static string Multiply(ExpressionValue[] args) { - var numericArgs = PrepareMultipleNumericArgs(args); + var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = numericArgs.First(); foreach (var arg in numericArgs.Skip(1)) { @@ -935,7 +939,17 @@ private static string Multiply(ExpressionValue[] args) private static string Divide(ExpressionValue[] args) { - var numericArgs = PrepareMultipleNumericArgs(args); + if (args.Length <= 1) + { + throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); + } + var numericArgs = PrepareMultipleNumericArgs(args).ToList(); + if (numericArgs.Skip(1).Any(arg => arg == 0)) + { + throw new ExpressionEvaluatorTypeErrorException( + "At least one of the arguments after the first is 0, cannot divide by 0" + ); + } var sum = numericArgs.First(); foreach (var arg in numericArgs.Skip(1)) { @@ -946,13 +960,17 @@ private static string Divide(ExpressionValue[] args) private static string Average(ExpressionValue[] args) { - var numericArgs = PrepareMultipleNumericArgs(args); + if (args.Length == 0) + { + throw new ExpressionEvaluatorTypeErrorException("At least one argument must be provided"); + } + var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = 0m; foreach (var arg in numericArgs) { sum += arg; } - return (sum / numericArgs.Count()).ToString(CultureInfo.InvariantCulture); + return (sum / numericArgs.Count).ToString(CultureInfo.InvariantCulture); } private static bool LessThanEq(ExpressionValue[] args) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 03932599af..1077d507a7 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -15,7 +15,7 @@ namespace Altinn.App.Core.Internal.Expressions; { private readonly string? _stringValue = null; - // double is a value type where nullable takes extra space, and we only read it when it should be set + // decimal is a value type where nullable takes extra space, and we only read it when it should be set private readonly decimal _numberValue = 0; // private readonly Dictionary? _objectValue = null; @@ -101,7 +101,7 @@ private ExpressionValue(string? value) public static implicit operator ExpressionValue(bool? value) => new(value); /// - /// Convert a nullable double to ExpressionValue + /// Convert a nullable decimal to ExpressionValue /// public static implicit operator ExpressionValue(decimal? value) => new(value); @@ -131,8 +131,8 @@ public static ExpressionValue FromObject(object? value) null => Null, bool boolValue => boolValue, string stringValue => stringValue, - float numberValue => (decimal?)numberValue, // expressions uses double which needs an explicit cast - double numberValue => (decimal?)numberValue, // expressions uses double which needs an explicit cast + float numberValue => (decimal?)numberValue, // expressions uses decimal which needs an explicit cast + double numberValue => (decimal?)numberValue, // expressions uses decimal which needs an explicit cast byte numberValue => numberValue, sbyte numberValue => numberValue, short numberValue => numberValue, diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json new file mode 100644 index 0000000000..f1af1e673f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when no arguments are provided", + "expression": ["average"], + "expectsFailure": "At least one argument must be provided" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json new file mode 100644 index 0000000000..b2c061d61a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when trying to divide by zero", + "expression": ["divide", 15, 0], + "expectsFailure": "At least one of the arguments after the first is 0, cannot divide by 0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json new file mode 100644 index 0000000000..1976067b21 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when less then two arguments are provided", + "expression": ["divide", 2.1], + "expectsFailure": "At least two arguments must be provided" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json new file mode 100644 index 0000000000..24edebfa1f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 0 when no arguments are provided", + "expression": ["minus"], + "expects": "0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json new file mode 100644 index 0000000000..f487cf239a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 0 when no arguments are provided", + "expression": ["plus"], + "expects": "0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 138d623505..7f80805296 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -55,19 +55,19 @@ public void TestString() } [Fact] - public void TestDouble() + public void TestDecimal() { - decimal doubleValue = 123.456m; - ExpressionValue value = doubleValue; - Assert.Equal(doubleValue, value.ToObject()); - Assert.Equal(doubleValue, value.Number); + decimal decimalValue = 123.456m; + ExpressionValue value = decimalValue; + Assert.Equal(decimalValue, value.ToObject()); + Assert.Equal(decimalValue, value.Number); - value = ExpressionValue.FromObject(doubleValue); - Assert.Equal(doubleValue, value.ToObject()); + value = ExpressionValue.FromObject(decimalValue); + Assert.Equal(decimalValue, value.ToObject()); - Assert.Equal(doubleValue.ToString(CultureInfo.InvariantCulture), value.ToString()); + Assert.Equal(decimalValue.ToString(CultureInfo.InvariantCulture), value.ToString()); Assert.Throws(() => value.GetHashCode()); - // Assert.Equal(doubleValue.GetHashCode(), value.GetHashCode()); + // Assert.Equal(decimalValue.GetHashCode(), value.GetHashCode()); } [Theory] From 3528b6852df1126d470c7f016f68bf172c219641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Tue, 3 Feb 2026 12:37:11 +0100 Subject: [PATCH 08/24] Changed to decimal return type --- .../Expressions/ExpressionEvaluator.cs | 24 +++++++++---------- .../functions/average/average-decimals.json | 2 +- .../average/average-multiple-decimals.json | 2 +- .../average/average-negative-values.json | 2 +- .../functions/divide/divide-decimals.json | 2 +- .../divide/divide-multiple-decimals.json | 2 +- .../divide/divide-negative-values.json | 2 +- .../functions/minus/subtracting-decimals.json | 2 +- .../minus/subtracting-multiple-decimals.json | 2 +- .../minus/subtracting-negative-values.json | 2 +- .../minus/subtracting-no-arguments.json | 2 +- .../functions/multiply/multiply-decimals.json | 2 +- .../multiply/multiply-multiple-decimals.json | 2 +- .../multiply/multiply-negative-values.json | 2 +- .../functions/plus/adding-decimals.json | 2 +- .../plus/adding-multiple-values.json | 2 +- .../plus/adding-negative-values.json | 2 +- .../functions/plus/adding-no-arguments.json | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index cb03950f95..a4fcf3f3cb 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -877,7 +877,7 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) ); } - private static readonly Regex _numberRegex = new Regex(@"^-?\d+(\.\d+)?$"); + private static readonly Regex _numberRegex = new(@"^-?\d+(\.\d+)?$"); internal static decimal? ParseNumber(string s, bool throwException = true) { @@ -904,17 +904,17 @@ private static bool LessThan(ExpressionValue[] args) return a < b; // Actual implementation } - private static string Plus(ExpressionValue[] args) + private static decimal Plus(ExpressionValue[] args) { var numericArgs = PrepareMultipleNumericArgs(args); - return numericArgs.Sum(arg => arg).ToString(CultureInfo.InvariantCulture); + return numericArgs.Sum(arg => arg); } - private static string Minus(ExpressionValue[] args) + private static decimal Minus(ExpressionValue[] args) { if (args.Length == 0) { - return "0"; + return 0; } var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = numericArgs.First(); @@ -923,10 +923,10 @@ private static string Minus(ExpressionValue[] args) sum -= arg; } - return sum.ToString(CultureInfo.InvariantCulture); + return sum; } - private static string Multiply(ExpressionValue[] args) + private static decimal Multiply(ExpressionValue[] args) { var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = numericArgs.First(); @@ -934,10 +934,10 @@ private static string Multiply(ExpressionValue[] args) { sum *= arg; } - return sum.ToString(CultureInfo.InvariantCulture); + return sum; } - private static string Divide(ExpressionValue[] args) + private static decimal Divide(ExpressionValue[] args) { if (args.Length <= 1) { @@ -955,10 +955,10 @@ private static string Divide(ExpressionValue[] args) { sum /= arg; } - return sum.ToString(CultureInfo.InvariantCulture); + return sum; } - private static string Average(ExpressionValue[] args) + private static decimal Average(ExpressionValue[] args) { if (args.Length == 0) { @@ -970,7 +970,7 @@ private static string Average(ExpressionValue[] args) { sum += arg; } - return (sum / numericArgs.Count).ToString(CultureInfo.InvariantCulture); + return sum / numericArgs.Count; } private static bool LessThanEq(ExpressionValue[] args) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json index 948be417fd..4cf8a2c368 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json @@ -1,5 +1,5 @@ { "name": "Should average the two arguments", "expression": ["average", 0.1, 0.2], - "expects": "0.15" + "expects": 0.15 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json index 810dd9c7ca..cd5133f6ff 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should average multiple arguments", "expression": ["average", 0.1, 0.2, 15, 1.50], - "expects": "4.20" + "expects": 4.20 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json index ed6d5d0a0e..a113da636c 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json @@ -1,5 +1,5 @@ { "name": "Should average the two arguments", "expression": ["average", -0.1, -0.2], - "expects": "-0.15" + "expects": -0.15 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json index 1b8fcd5d35..9c4061d3d3 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json @@ -1,5 +1,5 @@ { "name": "Should divide the first argument with the second", "expression": ["divide", 0.1, 0.2], - "expects": "0.5" + "expects": 0.5 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json index a3c4d16f81..d97874a424 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should divide the first argument multiple times", "expression": ["divide", 0.1, 0.2, 15, 1.50], - "expects": "0.0222222222222222222222222222" + "expects": 0.0222222222222222222222222222 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json index a963c9f0f3..7f69aa3791 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json @@ -1,5 +1,5 @@ { "name": "Should divide the first argument with the second", "expression": ["divide", -0.1, -0.2], - "expects": "0.5" + "expects": 0.5 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json index 8f1d9acf64..adc5cc16f7 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json @@ -1,5 +1,5 @@ { "name": "Should subtract the second argument from the first", "expression": ["minus", 0.1, 0.2], - "expects": "-0.1" + "expects": -0.1 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json index c00581eaa2..df75b4c69f 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should subtract the proceeding arguments from the first", "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expects": "-16.60" + "expects": -16.60 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json index f566f3cb2c..7c7eab7535 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json @@ -1,5 +1,5 @@ { "name": "Should subtract the second negative argument from the first", "expression": ["minus", -0.1, -0.2], - "expects": "0.1" + "expects": 0.1 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json index 24edebfa1f..01c9cbafaf 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json @@ -1,5 +1,5 @@ { "name": "Should return 0 when no arguments are provided", "expression": ["minus"], - "expects": "0" + "expects": 0 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json index d97333ed0c..624b14366b 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json @@ -1,5 +1,5 @@ { "name": "Should multiply the two arguments", "expression": ["multiply", 0.1, 0.2], - "expects": "0.02" + "expects": 0.02 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json index 9b624dd179..ca7af6dbbe 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -1,5 +1,5 @@ { "name": "Should multiply multiple arguments", "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expects": "0.4500" + "expects": 0.4500 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json index 8880981f9e..22edf04a9a 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json @@ -1,5 +1,5 @@ { "name": "Should multiply the two negative arguments", "expression": ["multiply", -0.1, -0.2], - "expects": "0.02" + "expects": 0.02 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json index be17d8483a..3588338e12 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json @@ -1,5 +1,5 @@ { "name": "Should add the two given numbers together", "expression": ["plus", 0.1, 0.2], - "expects": "0.3" + "expects": 0.3 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json index 6079c44131..02033154f4 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -1,5 +1,5 @@ { "name": "Should add multiple arguments", "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expects": "16.80" + "expects": 16.80 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json index abdf1a9380..72d79d9af7 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json @@ -1,5 +1,5 @@ { "name": "Should add two negative numbers together", "expression": ["plus", -4, -0.2], - "expects": "-4.2" + "expects": -4.2 } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json index f487cf239a..fc1eac12ad 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json @@ -1,5 +1,5 @@ { "name": "Should return 0 when no arguments are provided", "expression": ["plus"], - "expects": "0" + "expects": 0 } From 1cd82117adacf9a49899d2b225d70568958de8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Tue, 3 Feb 2026 14:54:26 +0100 Subject: [PATCH 09/24] Implementes suggested changes and added unit tests --- .../Expressions/ExpressionEvaluator.cs | 8 +++-- .../Internal/Expressions/ExpressionValue.cs | 21 ++++++++++++-- .../average/average-no-arguments.json | 5 ---- .../average/average-one-argument.json | 5 ++++ .../functions/divide/divide-one-argument.json | 2 +- .../multiply/multiply-one-argument.json | 5 ++++ .../ExpressionValueTests.cs | 29 +++++++++++++++++++ 7 files changed, 65 insertions(+), 10 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index a4fcf3f3cb..1de3c33610 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -928,6 +928,10 @@ private static decimal Minus(ExpressionValue[] args) private static decimal Multiply(ExpressionValue[] args) { + if (args.Length <= 1) + { + throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); + } var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = numericArgs.First(); foreach (var arg in numericArgs.Skip(1)) @@ -960,9 +964,9 @@ private static decimal Divide(ExpressionValue[] args) private static decimal Average(ExpressionValue[] args) { - if (args.Length == 0) + if (args.Length <= 1) { - throw new ExpressionEvaluatorTypeErrorException("At least one argument must be provided"); + throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); } var numericArgs = PrepareMultipleNumericArgs(args).ToList(); var sum = 0m; diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 1077d507a7..374180685a 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -131,8 +131,8 @@ public static ExpressionValue FromObject(object? value) null => Null, bool boolValue => boolValue, string stringValue => stringValue, - float numberValue => (decimal?)numberValue, // expressions uses decimal which needs an explicit cast - double numberValue => (decimal?)numberValue, // expressions uses decimal which needs an explicit cast + float numberValue => ValidateAndCastFloatingPoint(numberValue), // expressions uses decimal which needs an explicit cast + double numberValue => ValidateAndCastFloatingPoint(numberValue), // expressions uses decimal which needs an explicit cast byte numberValue => numberValue, sbyte numberValue => numberValue, short numberValue => numberValue, @@ -587,6 +587,23 @@ private static bool IsSupportedNumericType(Type type) || type == typeof(ushort) || type == typeof(sbyte); } + + private static decimal? ValidateAndCastFloatingPoint(double value) + { + if ( + double.IsNaN(value) + || double.IsInfinity(value) + || value > (double)decimal.MaxValue + || value < (double)decimal.MinValue + ) + { + throw new ExpressionEvaluatorTypeErrorException( + $"Cannot convert non-finite or out-of-range number to decimal: {value}" + ); + } + + return (decimal?)value; + } } /// diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json deleted file mode 100644 index f1af1e673f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-no-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when no arguments are provided", - "expression": ["average"], - "expectsFailure": "At least one argument must be provided" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json new file mode 100644 index 0000000000..2fb356e7d3 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when less than two arguments are provided", + "expression": ["average", 0.1], + "expectsFailure": "At least two arguments must be provided" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json index 1976067b21..8a3b474ae8 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when less then two arguments are provided", + "name": "Should throw exception when less than two arguments are provided", "expression": ["divide", 2.1], "expectsFailure": "At least two arguments must be provided" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json new file mode 100644 index 0000000000..6c6992cfca --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when less than two arguments are provided", + "expression": ["multiply", 0.1], + "expectsFailure": "At least two arguments must be provided" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 7f80805296..cb142bcd88 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -70,6 +70,35 @@ public void TestDecimal() // Assert.Equal(decimalValue.GetHashCode(), value.GetHashCode()); } + [Theory] + [InlineData(double.MaxValue)] + [InlineData(float.MaxValue)] + public void FromObject_MaxValue_ThrowsExpressionEvaluatorTypeErrorException(object obj) + { + var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); + Assert.Contains("Cannot convert non-finite or out-of-range number to decimal: ", exception.Message); + } + + [Theory] + [InlineData(Double.NaN)] + [InlineData(Single.NaN)] + public void FromObject_Nan_ThrowsExpressionEvaluatorTypeErrorException(Object obj) + { + var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); + Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); + } + + [Theory] + [InlineData(Double.NegativeInfinity)] + [InlineData(Double.PositiveInfinity)] + [InlineData(Single.NegativeInfinity)] + [InlineData(Single.PositiveInfinity)] + public void FromObject_Infinite_ThrowsExpressionEvaluatorTypeErrorException(Object obj) + { + var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); + Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); + } + [Theory] [InlineData(true)] [InlineData(false)] From 364e4b8f464a391ed4557f566163fd7328bf2b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Tue, 3 Feb 2026 15:44:01 +0100 Subject: [PATCH 10/24] improved unit test names and added min value tests --- .../ExpressionEvaluatorTests/ExpressionValueTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index cb142bcd88..3b5e98d495 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -73,7 +73,9 @@ public void TestDecimal() [Theory] [InlineData(double.MaxValue)] [InlineData(float.MaxValue)] - public void FromObject_MaxValue_ThrowsExpressionEvaluatorTypeErrorException(object obj) + [InlineData(double.MinValue)] + [InlineData(float.MinValue)] + public void FromObject_FloatingPointMaxAndMinValue_ThrowsExpressionEvaluatorTypeErrorException(object obj) { var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); Assert.Contains("Cannot convert non-finite or out-of-range number to decimal: ", exception.Message); @@ -82,7 +84,7 @@ public void FromObject_MaxValue_ThrowsExpressionEvaluatorTypeErrorException(obje [Theory] [InlineData(Double.NaN)] [InlineData(Single.NaN)] - public void FromObject_Nan_ThrowsExpressionEvaluatorTypeErrorException(Object obj) + public void FromObject_FloatingPointNan_ThrowsExpressionEvaluatorTypeErrorException(object obj) { var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); @@ -93,7 +95,7 @@ public void FromObject_Nan_ThrowsExpressionEvaluatorTypeErrorException(Object ob [InlineData(Double.PositiveInfinity)] [InlineData(Single.NegativeInfinity)] [InlineData(Single.PositiveInfinity)] - public void FromObject_Infinite_ThrowsExpressionEvaluatorTypeErrorException(Object obj) + public void FromObject_FloatingPointInfinite_ThrowsExpressionEvaluatorTypeErrorException(object obj) { var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); From 2a01a104f9beff1c9d263c6a876625f0a28dea0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 9 Feb 2026 15:21:43 +0100 Subject: [PATCH 11/24] Changed from accepting multiple arguments to just accept two. Removed average. --- .../Expressions/ExpressionEvaluator.cs | 74 ++++--------------- .../Models/Expressions/ExpressionFunction.cs | 5 -- .../functions/average/average-decimals.json | 5 -- .../average/average-multiple-decimals.json | 5 -- .../average/average-negative-values.json | 5 -- .../average/average-null-values.json | 5 -- .../average/average-one-argument.json | 5 -- .../average/average-one-null-value.json | 5 -- .../divide/divide-multiple-decimals.json | 4 +- .../minus/subtracting-multiple-decimals.json | 4 +- .../multiply/multiply-multiple-decimals.json | 4 +- .../plus/adding-multiple-values.json | 4 +- 12 files changed, 23 insertions(+), 102 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 1de3c33610..17bb9e3cc1 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -132,7 +132,6 @@ internal static async Task EvaluateExpression_internal( ExpressionFunction.minus => Minus(args), ExpressionFunction.multiply => Multiply(args), ExpressionFunction.divide => Divide(args), - ExpressionFunction.average => Average(args), ExpressionFunction.INVALID => throw new ExpressionEvaluatorTypeErrorException( $"Function {expr.Args.FirstOrDefault()} not implemented in backend {expr}" ), @@ -826,16 +825,6 @@ private static (decimal?, decimal?) PrepareTwoNumericArgs(ExpressionValue[] args return (a, b); } - private static IEnumerable PrepareMultipleNumericArgs(ExpressionValue[] args) - { - return args.Select(arg => PrepareNumericArg(arg)) - .Select(x => - !x.HasValue - ? throw new ExpressionEvaluatorTypeErrorException("At least one of the arguments is not a number") - : x.Value - ); - } - private static decimal? PrepareNumericArg(ExpressionValue arg) { return arg.ValueKind switch @@ -904,77 +893,44 @@ private static bool LessThan(ExpressionValue[] args) return a < b; // Actual implementation } - private static decimal Plus(ExpressionValue[] args) + private static decimal? Plus(ExpressionValue[] args) { - var numericArgs = PrepareMultipleNumericArgs(args); - return numericArgs.Sum(arg => arg); + var (a, b) = PrepareTwoNumericArgs(args); + return a + b; } - private static decimal Minus(ExpressionValue[] args) + private static decimal? Minus(ExpressionValue[] args) { if (args.Length == 0) { return 0; } - var numericArgs = PrepareMultipleNumericArgs(args).ToList(); - var sum = numericArgs.First(); - foreach (var arg in numericArgs.Skip(1)) - { - sum -= arg; - } - - return sum; - } - - private static decimal Multiply(ExpressionValue[] args) - { - if (args.Length <= 1) - { - throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); - } - var numericArgs = PrepareMultipleNumericArgs(args).ToList(); - var sum = numericArgs.First(); - foreach (var arg in numericArgs.Skip(1)) - { - sum *= arg; - } - return sum; + var (a, b) = PrepareTwoNumericArgs(args); + return a - b; } - private static decimal Divide(ExpressionValue[] args) + private static decimal? Multiply(ExpressionValue[] args) { if (args.Length <= 1) { - throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); + throw new ExpressionEvaluatorTypeErrorException("Two arguments must be provided"); } - var numericArgs = PrepareMultipleNumericArgs(args).ToList(); - if (numericArgs.Skip(1).Any(arg => arg == 0)) - { - throw new ExpressionEvaluatorTypeErrorException( - "At least one of the arguments after the first is 0, cannot divide by 0" - ); - } - var sum = numericArgs.First(); - foreach (var arg in numericArgs.Skip(1)) - { - sum /= arg; - } - return sum; + var (a, b) = PrepareTwoNumericArgs(args); + return a * b; } - private static decimal Average(ExpressionValue[] args) + private static decimal? Divide(ExpressionValue[] args) { if (args.Length <= 1) { throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); } - var numericArgs = PrepareMultipleNumericArgs(args).ToList(); - var sum = 0m; - foreach (var arg in numericArgs) + var (a, b) = PrepareTwoNumericArgs(args); + if (b == 0) { - sum += arg; + throw new ExpressionEvaluatorTypeErrorException("Argument two is 0, cannot divide by 0"); } - return sum / numericArgs.Count; + return a / b; } private static bool LessThanEq(ExpressionValue[] args) diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs index 361698b0ef..57ecfe5d26 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunction.cs @@ -225,9 +225,4 @@ public enum ExpressionFunction /// Divide numbers. Use a period (.) as the decimals separator. Must be numeric values. /// divide, - - /// - /// Calculate the average of all values. Use a period (.) as the decimals separator. Must be numeric values. - /// - average, } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json deleted file mode 100644 index 4cf8a2c368..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should average the two arguments", - "expression": ["average", 0.1, 0.2], - "expects": 0.15 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json deleted file mode 100644 index cd5133f6ff..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-multiple-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should average multiple arguments", - "expression": ["average", 0.1, 0.2, 15, 1.50], - "expects": 4.20 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json deleted file mode 100644 index a113da636c..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-negative-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should average the two arguments", - "expression": ["average", -0.1, -0.2], - "expects": -0.15 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json deleted file mode 100644 index 2239f9229c..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-null-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when both of the arguments are null", - "expression": ["average", null, null], - "expectsFailure": "At least one of the arguments is not a number" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json deleted file mode 100644 index 2fb356e7d3..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-argument.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when less than two arguments are provided", - "expression": ["average", 0.1], - "expectsFailure": "At least two arguments must be provided" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json deleted file mode 100644 index c31931783a..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/average/average-one-null-value.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when one of the arguments is null", - "expression": ["average", null, 2.1], - "expectsFailure": "At least one of the arguments is not a number" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json index d97874a424..ebc3e1eb4a 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should divide the first argument multiple times", + "name": "Should throw exception when more then two arguments is present", "expression": ["divide", 0.1, 0.2, 15, 1.50], - "expects": 0.0222222222222222222222222222 + "expectsFailure": "Invalid number of args for compare" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json index df75b4c69f..c085e6ea00 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should subtract the proceeding arguments from the first", + "name": "Should throw exception when more then two arguments is present", "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expects": -16.60 + "expectsFailure": "Invalid number of args for compare" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json index ca7af6dbbe..b51c67f61c 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should multiply multiple arguments", + "name": "Should throw exception when more then two arguments is present", "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expects": 0.4500 + "expectsFailure": "Invalid number of args for compare" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json index 02033154f4..6d88941ed1 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -1,5 +1,5 @@ { - "name": "Should add multiple arguments", + "name": "Should throw exception when more then two arguments is present", "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expects": 16.80 + "expectsFailure": "Invalid number of args for compare" } From 5d427f589a2fe137a802f5fdae73564a1eb0301c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 9 Feb 2026 16:19:52 +0100 Subject: [PATCH 12/24] Fixed unit tests and consistancy in functions --- .../Expressions/ExpressionEvaluator.cs | 32 ++++++------------- .../CommonTests/TestFunctions.cs | 4 --- .../functions/divide/divide-by-zero.json | 2 +- .../functions/divide/divide-null-values.json | 2 +- .../functions/divide/divide-one-argument.json | 2 +- .../divide/divide-one-null-value.json | 4 +-- .../minus/subtracting-no-arguments.json | 5 --- .../minus/subtracting-null-values.json | 4 +-- .../minus/subtracting-one-argument.json | 5 +++ .../minus/subtracting-one-null-value.json | 4 +-- .../multiply/multiply-null-values.json | 4 +-- .../multiply/multiply-one-argument.json | 2 +- .../multiply/multiply-one-null-value.json | 4 +-- .../functions/plus/adding-no-arguments.json | 5 --- .../functions/plus/adding-null-values.json | 4 +-- .../functions/plus/adding-one-argument.json | 5 +++ .../functions/plus/adding-one-null-value.json | 4 +-- ...ouldNotChange_Unintentionally.verified.txt | 1 - 18 files changed, 38 insertions(+), 55 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 17bb9e3cc1..6000c885da 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -811,7 +811,7 @@ ExpressionValue[] args return !PrepareBooleanArg(args[0]); } - private static (decimal?, decimal?) PrepareTwoNumericArgs(ExpressionValue[] args) + private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) { if (args.Length != 2) { @@ -884,7 +884,7 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) private static bool LessThan(ExpressionValue[] args) { - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -895,47 +895,35 @@ private static bool LessThan(ExpressionValue[] args) private static decimal? Plus(ExpressionValue[] args) { - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); return a + b; } private static decimal? Minus(ExpressionValue[] args) { - if (args.Length == 0) - { - return 0; - } - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); return a - b; } private static decimal? Multiply(ExpressionValue[] args) { - if (args.Length <= 1) - { - throw new ExpressionEvaluatorTypeErrorException("Two arguments must be provided"); - } - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); return a * b; } private static decimal? Divide(ExpressionValue[] args) { - if (args.Length <= 1) - { - throw new ExpressionEvaluatorTypeErrorException("At least two arguments must be provided"); - } - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (b == 0) { - throw new ExpressionEvaluatorTypeErrorException("Argument two is 0, cannot divide by 0"); + throw new ExpressionEvaluatorTypeErrorException("The second argument is 0, cannot divide by 0"); } return a / b; } private static bool LessThanEq(ExpressionValue[] args) { - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -946,7 +934,7 @@ private static bool LessThanEq(ExpressionValue[] args) private static bool GreaterThan(ExpressionValue[] args) { - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -957,7 +945,7 @@ private static bool GreaterThan(ExpressionValue[] args) private static bool GreaterThanEq(ExpressionValue[] args) { - var (a, b) = PrepareTwoNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index aa2f6f8e5a..117c15d9a0 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -219,10 +219,6 @@ public TestFunctions(ITestOutputHelper output) [SharedTest("divide")] public async Task Divide_Theory(string testName, string folder) => await RunTestCase(testName, folder); - [Theory] - [SharedTest("average")] - public async Task Average_Theory(string testName, string folder) => await RunTestCase(testName, folder); - [Theory] [SharedTest("round")] public async Task Round_Theory(string testName, string folder) => await RunTestCase(testName, folder); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json index b2c061d61a..abb25771a4 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when trying to divide by zero", "expression": ["divide", 15, 0], - "expectsFailure": "At least one of the arguments after the first is 0, cannot divide by 0" + "expectsFailure": "The second argument is 0, cannot divide by 0" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json index 979a8fd399..71a66c341e 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when both of the arguments are null", "expression": ["divide", null, null], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json index 8a3b474ae8..55ac70f4cb 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["divide", 2.1], - "expectsFailure": "At least two arguments must be provided" + "expectsFailure": "Invalid number of args for compare" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json index f8e6804df9..7e30c95f52 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when one of the arguments is null", + "name": "Should return null when one of the arguments is null", "expression": ["divide", null, 2.1], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json deleted file mode 100644 index 01c9cbafaf..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-no-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return 0 when no arguments are provided", - "expression": ["minus"], - "expects": 0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json index 75eb1befb3..07166edea4 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when both of the arguments are null", + "name": "Should return null when both of the arguments are null", "expression": ["minus", null, null], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json new file mode 100644 index 0000000000..6d916583f4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when less than two arguments are provided", + "expression": ["minus", 0.2], + "expectsFailure": "Invalid number of args for compare" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json index f8c494afd6..9e37685657 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when one of the arguments is null", + "name": "Should return null when one of the arguments is null", "expression": ["minus", null, 2.1], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json index e5621fb813..691f4bdb58 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when both of the arguments are null", + "name": "Should return null when both of the arguments are null", "expression": ["multiply", null, null], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json index 6c6992cfca..7ce568dd68 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["multiply", 0.1], - "expectsFailure": "At least two arguments must be provided" + "expectsFailure": "Invalid number of args for compare" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json index dfd04c6b55..c3e7cc0927 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when one of the arguments is null", + "name": "Should return null when one of the arguments is null", "expression": ["multiply", null, 2.1], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json deleted file mode 100644 index fc1eac12ad..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-no-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return 0 when no arguments are provided", - "expression": ["plus"], - "expects": 0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json index 75fdfebcb6..b49bc24fc9 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when both of the arguments are null", + "name": "Should return null when both of the arguments are null", "expression": ["plus", null, null], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json new file mode 100644 index 0000000000..ba9cdc29d8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json @@ -0,0 +1,5 @@ +{ + "name": "Should throw exception when less than two arguments are provided", + "expression": ["plus", 0.2], + "expectsFailure": "Invalid number of args for compare" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json index 3a77acc4fa..3a04d0c977 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when one of the arguments is null", + "name": "Should return null when one of the arguments is null", "expression": ["plus", 4.3, null], - "expectsFailure": "At least one of the arguments is not a number" + "expects": null } diff --git a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt index 621fdc6408..a0771c2076 100644 --- a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt +++ b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt @@ -4581,7 +4581,6 @@ namespace Altinn.App.Core.Models.Expressions minus = 38, multiply = 39, divide = 40, - average = 41, } } namespace Altinn.App.Core.Models.Layout.Components.Base From efd31680101b34ad7999e1504ffe4e35b1fa462f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 9 Feb 2026 16:27:33 +0100 Subject: [PATCH 13/24] Fixed exception message --- .../Internal/Expressions/ExpressionEvaluator.cs | 2 +- .../functions/divide/divide-multiple-decimals.json | 4 ++-- .../shared-tests/functions/divide/divide-one-argument.json | 2 +- .../functions/minus/subtracting-multiple-decimals.json | 4 ++-- .../functions/minus/subtracting-one-argument.json | 2 +- .../functions/multiply/multiply-multiple-decimals.json | 4 ++-- .../functions/multiply/multiply-one-argument.json | 2 +- .../shared-tests/functions/plus/adding-multiple-values.json | 4 ++-- .../shared-tests/functions/plus/adding-one-argument.json | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 6000c885da..ec77c7150e 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -815,7 +815,7 @@ private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) { if (args.Length != 2) { - throw new ExpressionEvaluatorTypeErrorException("Invalid number of args for compare"); + throw new ExpressionEvaluatorTypeErrorException("Invalid number of args"); } var a = PrepareNumericArg(args[0]); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json index ebc3e1eb4a..7dab3a1c98 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more then two arguments is present", + "name": "Should throw exception when more than two arguments is present", "expression": ["divide", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json index 55ac70f4cb..bea8b216ea 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["divide", 2.1], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json index c085e6ea00..7654e5685d 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more then two arguments is present", + "name": "Should throw exception when more than two arguments is present", "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json index 6d916583f4..fe765bb4e5 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["minus", 0.2], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json index b51c67f61c..94d9c76d8e 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more then two arguments is present", + "name": "Should throw exception when more than two arguments is present", "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json index 7ce568dd68..6475b6b240 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["multiply", 0.1], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json index 6d88941ed1..f7fe00e1fc 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more then two arguments is present", + "name": "Should throw exception when more than two arguments is present", "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json index ba9cdc29d8..cd1bf05f57 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["plus", 0.2], - "expectsFailure": "Invalid number of args for compare" + "expectsFailure": "Invalid number of args" } From a90381c2154be29dc3141c70aa8af7f0c7b32826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Mon, 9 Feb 2026 16:42:57 +0100 Subject: [PATCH 14/24] Fixed test name --- .../shared-tests/functions/divide/divide-null-values.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json index 71a66c341e..a54e895801 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when both of the arguments are null", + "name": "Should return null when both of the arguments are null", "expression": ["divide", null, null], "expects": null } From 46f6067fd6fe51ef427246a566b6b8d4f161664b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 09:44:43 +0100 Subject: [PATCH 15/24] Implemented suggested changes --- .../Internal/Expressions/ExpressionEvaluator.cs | 1 - .../LayoutExpressions/CommonTests/TestFunctions.cs | 6 +++--- .../shared-tests/functions/divide/diff-types-float-int.json | 5 +++++ .../functions/divide/diff-types-string-float-valid.json | 5 +++++ .../functions/divide/diff-types-string-int-valid.json | 5 +++++ .../shared-tests/functions/divide/divide-by-one.json | 5 +++++ .../functions/divide/divide-multiple-decimals.json | 4 ++-- .../functions/divide/divide-negative-by-positive.json | 5 +++++ .../shared-tests/functions/divide/divide-one-argument.json | 2 +- .../shared-tests/functions/divide/divide-two-negatives.json | 5 +++++ .../functions/divide/divide-with-remainder.json | 5 +++++ .../functions/divide/divide-zero-by-number.json | 5 +++++ .../shared-tests/functions/divide/error-bool-int.json | 5 +++++ .../shared-tests/functions/divide/error-invalid-string.json | 5 +++++ .../shared-tests/functions/divide/error-no-decimals.json | 5 +++++ .../shared-tests/functions/divide/same-types-int.json | 5 +++++ .../functions/divide/scientific-notation-mixed.json | 5 +++++ .../divide/scientific-notation-negative-exponent.json | 5 +++++ .../functions/divide/scientific-notation-simple.json | 5 +++++ .../functions/divide/scientific-notation-string.json | 5 +++++ .../shared-tests/functions/divide/very-large-numbers.json | 5 +++++ .../shared-tests/functions/divide/very-small-numbers.json | 5 +++++ .../shared-tests/functions/minus/diff-types-float-int.json | 5 +++++ .../functions/minus/diff-types-string-float-valid.json | 5 +++++ .../functions/minus/diff-types-string-int-valid.json | 5 +++++ .../shared-tests/functions/minus/error-bool-int.json | 5 +++++ .../shared-tests/functions/minus/error-invalid-string.json | 5 +++++ .../shared-tests/functions/minus/error-no-decimals.json | 5 +++++ .../shared-tests/functions/minus/same-types-int.json | 5 +++++ .../functions/minus/scientific-notation-mixed.json | 5 +++++ .../minus/scientific-notation-negative-exponent.json | 5 +++++ .../functions/minus/scientific-notation-simple.json | 5 +++++ .../functions/minus/scientific-notation-string.json | 5 +++++ .../shared-tests/functions/minus/subtracting-from-zero.json | 5 +++++ .../functions/minus/subtracting-multiple-decimals.json | 4 ++-- .../functions/minus/subtracting-negative-from-positive.json | 5 +++++ .../functions/minus/subtracting-one-argument.json | 2 +- .../shared-tests/functions/minus/subtracting-zero.json | 5 +++++ .../shared-tests/functions/minus/very-large-numbers.json | 5 +++++ .../shared-tests/functions/minus/very-small-numbers.json | 5 +++++ .../functions/multiply/diff-types-float-int.json | 5 +++++ .../functions/multiply/diff-types-string-float-valid.json | 5 +++++ .../functions/multiply/diff-types-string-int-valid.json | 5 +++++ .../shared-tests/functions/multiply/error-bool-int.json | 5 +++++ .../functions/multiply/error-invalid-string.json | 5 +++++ .../shared-tests/functions/multiply/error-no-decimals.json | 5 +++++ .../shared-tests/functions/multiply/multiply-by-one.json | 5 +++++ .../shared-tests/functions/multiply/multiply-by-zero.json | 5 +++++ .../functions/multiply/multiply-multiple-decimals.json | 4 ++-- .../functions/multiply/multiply-negative-positive.json | 5 +++++ .../functions/multiply/multiply-one-argument.json | 2 +- .../functions/multiply/multiply-two-negatives.json | 5 +++++ .../shared-tests/functions/multiply/same-types-int.json | 5 +++++ .../functions/multiply/scientific-notation-mixed.json | 5 +++++ .../multiply/scientific-notation-negative-exponent.json | 5 +++++ .../functions/multiply/scientific-notation-simple.json | 5 +++++ .../functions/multiply/scientific-notation-string.json | 5 +++++ .../shared-tests/functions/multiply/very-large-numbers.json | 5 +++++ .../shared-tests/functions/multiply/very-small-numbers.json | 5 +++++ .../shared-tests/functions/plus/adding-multiple-values.json | 4 ++-- .../functions/plus/adding-negative-to-positive.json | 5 +++++ .../shared-tests/functions/plus/adding-one-argument.json | 2 +- .../shared-tests/functions/plus/adding-zero.json | 5 +++++ .../shared-tests/functions/plus/diff-types-float-int.json | 5 +++++ .../functions/plus/diff-types-string-float-valid.json | 5 +++++ .../functions/plus/diff-types-string-int-valid.json | 5 +++++ .../shared-tests/functions/plus/error-bool-int.json | 5 +++++ .../shared-tests/functions/plus/error-invalid-string.json | 5 +++++ .../shared-tests/functions/plus/error-no-decimals.json | 5 +++++ .../shared-tests/functions/plus/same-types-int.json | 5 +++++ .../functions/plus/scientific-notation-mixed.json | 5 +++++ .../plus/scientific-notation-negative-exponent.json | 5 +++++ .../functions/plus/scientific-notation-simple.json | 5 +++++ .../functions/plus/scientific-notation-string.json | 5 +++++ .../shared-tests/functions/plus/very-large-numbers.json | 5 +++++ .../shared-tests/functions/plus/very-small-numbers.json | 5 +++++ 76 files changed, 345 insertions(+), 16 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index ec77c7150e..d23abed75d 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -127,7 +127,6 @@ internal static async Task EvaluateExpression_internal( ExpressionFunction.argv => Argv(args, positionalArguments), ExpressionFunction.gatewayAction => state.GetGatewayAction(), ExpressionFunction.language => state.GetLanguage(), - // Calculations: ExpressionFunction.plus => Plus(args), ExpressionFunction.minus => Minus(args), ExpressionFunction.multiply => Multiply(args), diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 117c15d9a0..6c0f1da5d8 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -332,16 +332,16 @@ private async Task RunTestCase(string testName, string folder) componentModel = new LayoutModel([layout], null); } - var appRewourcesMock = new Mock(MockBehavior.Strict); + var appResourcesMock = new Mock(MockBehavior.Strict); var language = test.ProfileSettings?.Language ?? "nb"; - appRewourcesMock + appResourcesMock .Setup(ar => ar.GetTexts(It.IsAny(), It.IsAny(), language)) .ReturnsAsync(new TextResource() { Resources = test.TextResources ?? [] }); var translationService = new TranslationService( new Core.Models.AppIdentifier("org", "app"), - appRewourcesMock.Object, + appResourcesMock.Object, FakeLoggerXunit.Get(_output) ); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json new file mode 100644 index 0000000000..8978f2bfcf --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide [float, integer]", + "expression": ["divide", 30.0, 6], + "expects": 5.0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json new file mode 100644 index 0000000000..ca98307301 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide [string, float] when string is valid number", + "expression": ["divide", "22.0", 4.0], + "expects": 5.5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json new file mode 100644 index 0000000000..efe744a093 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide [string, integer] when string is valid number", + "expression": ["divide", "30", 6], + "expects": 5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json new file mode 100644 index 0000000000..4cf8fbede0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle dividing by one", + "expression": ["divide", 42, 1], + "expects": 42 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json index 7dab3a1c98..dd5c3ab793 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more than two arguments is present", + "name": "Should throw exception when more than two arguments are present", "expression": ["divide", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json new file mode 100644 index 0000000000..6f4e35a1b7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide negative by positive", + "expression": ["divide", -30, 6], + "expects": -5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json index bea8b216ea..b0f5029b8f 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["divide", 2.1], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json new file mode 100644 index 0000000000..13ab2377de --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide two negative numbers", + "expression": ["divide", -30, -6], + "expects": 5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json new file mode 100644 index 0000000000..81c6f32a4a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle division with remainder", + "expression": ["divide", 10, 3], + "expects": 3.3333333333333333333333333333 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json new file mode 100644 index 0000000000..d77942848b --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle dividing zero by a number", + "expression": ["divide", 0, 42], + "expects": 0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json new file mode 100644 index 0000000000..53c6437054 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with [boolean, integer]", + "expression": ["divide", 100, true], + "expectsFailure": "Expected number, got value true" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json new file mode 100644 index 0000000000..0c2f5d13fd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["divide", 100, "not a number"], + "expectsFailure": "Expected number, got value \"not a number\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json new file mode 100644 index 0000000000..036b0197b2 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with string with no decimals after dot", + "expression": ["divide", "55.", 5], + "expectsFailure": "Expected number, got value \"55.\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json new file mode 100644 index 0000000000..a43facfbd8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide two integers", + "expression": ["divide", 30, 6], + "expects": 5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json new file mode 100644 index 0000000000..ac46999b05 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide scientific notation by regular number", + "expression": ["divide", 5e2, 10], + "expects": 50 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json new file mode 100644 index 0000000000..921c675b8b --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide numbers with negative exponents", + "expression": ["divide", 6e-3, 2e-3], + "expects": 3 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json new file mode 100644 index 0000000000..03cb93e6aa --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide numbers in scientific notation", + "expression": ["divide", 6e3, 2e3], + "expects": 3 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json new file mode 100644 index 0000000000..92bd77b87f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide string scientific notation by number", + "expression": ["divide", "5e2", 10], + "expectsFailure": "Expected number, got value \"5e2\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json new file mode 100644 index 0000000000..9dddd5601a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very large numbers", + "expression": ["divide", 1000000000000, 1000000], + "expects": 1000000 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json new file mode 100644 index 0000000000..dea4395d2c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very small numbers", + "expression": ["divide", 0.00000001, 0.0001], + "expects": 0.0001 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json new file mode 100644 index 0000000000..0ab080ad44 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract [float, integer]", + "expression": ["minus", 50.5, 20], + "expects": 30.5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json new file mode 100644 index 0000000000..b41b7ccbdf --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract [string, float] when string is valid number", + "expression": ["minus", "50.8", 20.3], + "expects": 30.5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json new file mode 100644 index 0000000000..44652a480e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract [string, integer] when string is valid number", + "expression": ["minus", "50", 20], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json new file mode 100644 index 0000000000..ee6de42e44 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with [boolean, integer]", + "expression": ["minus", false, 10], + "expectsFailure": "Expected number, got value false" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json new file mode 100644 index 0000000000..97a579aab5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["minus", 50, "not a number"], + "expectsFailure": "Expected number, got value \"not a number\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json new file mode 100644 index 0000000000..86329aca19 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with string with no decimals after dot", + "expression": ["minus", "55.", 10], + "expectsFailure": "Expected number, got value \"55.\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json new file mode 100644 index 0000000000..7fd077accf --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract two integers", + "expression": ["minus", 50, 20], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json new file mode 100644 index 0000000000..e9b14d9735 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract scientific notation from regular number", + "expression": ["minus", 150, 1e2], + "expects": 50 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json new file mode 100644 index 0000000000..ab71a94afe --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract numbers with negative exponents", + "expression": ["minus", 5e-3, 2e-3], + "expects": 0.003 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json new file mode 100644 index 0000000000..2c319861b6 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract numbers in scientific notation", + "expression": ["minus", 5e3, 2e3], + "expects": 3000 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json new file mode 100644 index 0000000000..5b9e31fb3d --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract string scientific notation from number", + "expression": ["minus", 150, "1e2"], + "expectsFailure": "Expected number, got value \"1e2\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json new file mode 100644 index 0000000000..b8ca6df6e1 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle subtracting from zero", + "expression": ["minus", 0, 42], + "expects": -42 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json index 7654e5685d..17df0e15f2 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more than two arguments is present", + "name": "Should throw exception when more than two arguments are present", "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json new file mode 100644 index 0000000000..143e924fa6 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract negative from positive", + "expression": ["minus", 50, -30], + "expects": 80 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json index fe765bb4e5..80c8034fc8 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["minus", 0.2], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json new file mode 100644 index 0000000000..f17ab56c68 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle subtracting zero", + "expression": ["minus", 42, 0], + "expects": 42 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json new file mode 100644 index 0000000000..9a387dd08e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very large numbers", + "expression": ["minus", 9007199254740992, 1], + "expects": 9007199254740991 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json new file mode 100644 index 0000000000..ee28da24b6 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very small numbers", + "expression": ["minus", 0.0000003, 0.0000001], + "expects": 0.0000002 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json new file mode 100644 index 0000000000..9a5f03cae1 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply [float, integer]", + "expression": ["multiply", 7.5, 4], + "expects": 30.0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json new file mode 100644 index 0000000000..8fd2a39091 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply [string, float] when string is valid number", + "expression": ["multiply", "5.5", 4.0], + "expects": 22.0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json new file mode 100644 index 0000000000..e0bcc31140 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply [string, integer] when string is valid number", + "expression": ["multiply", "5", 6], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json new file mode 100644 index 0000000000..db28d0d6c5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with [boolean, integer]", + "expression": ["multiply", true, 5], + "expectsFailure": "Expected number, got value true" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json new file mode 100644 index 0000000000..958508e642 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["multiply", "not a number", 5], + "expectsFailure": "Expected number, got value \"not a number\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json new file mode 100644 index 0000000000..b4abc63e60 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with string with no decimals after dot", + "expression": ["multiply", "55.", 5], + "expectsFailure": "Expected number, got value \"55.\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json new file mode 100644 index 0000000000..fc5b6db16e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle multiplying by one", + "expression": ["multiply", 42, 1], + "expects": 42 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json new file mode 100644 index 0000000000..48883ca8e1 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle multiplying by zero", + "expression": ["multiply", 42, 0], + "expects": 0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json index 94d9c76d8e..a0d5ab0f86 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more than two arguments is present", + "name": "Should throw exception when more than two arguments are present", "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json new file mode 100644 index 0000000000..72ad362aa5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply negative and positive numbers", + "expression": ["multiply", -5, 6], + "expects": -30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json index 6475b6b240..1984c25515 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["multiply", 0.1], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json new file mode 100644 index 0000000000..2190343ae0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply two negative numbers", + "expression": ["multiply", -5, -6], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json new file mode 100644 index 0000000000..1141fd27d9 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply two integers", + "expression": ["multiply", 5, 6], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json new file mode 100644 index 0000000000..b25cda13d4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply scientific notation with regular number", + "expression": ["multiply", 1e2, 5], + "expects": 500 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json new file mode 100644 index 0000000000..0a1e24417f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply numbers with negative exponents", + "expression": ["multiply", 2e-3, 3e-2], + "expects": 0.00006 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json new file mode 100644 index 0000000000..85f7327624 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply numbers in scientific notation", + "expression": ["multiply", 2e3, 3e2], + "expects": 600000 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json new file mode 100644 index 0000000000..f85745118a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply string scientific notation with number", + "expression": ["multiply", "1e2", 5], + "expectsFailure": "Expected number, got value \"1e2\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json new file mode 100644 index 0000000000..cd943c82c0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very large numbers", + "expression": ["multiply", 1000000, 1000000], + "expects": 1000000000000 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json new file mode 100644 index 0000000000..bcb5a934a2 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very small numbers", + "expression": ["multiply", 0.0001, 0.0001], + "expects": 0.00000001 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json index f7fe00e1fc..45d19d78b0 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json @@ -1,5 +1,5 @@ { - "name": "Should throw exception when more than two arguments is present", + "name": "Should throw exception when more than two arguments are present", "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json new file mode 100644 index 0000000000..55c895a688 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json @@ -0,0 +1,5 @@ +{ + "name": "Should add negative and positive numbers", + "expression": ["plus", 50, -30], + "expects": 20 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json index cd1bf05f57..f06256fd35 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json @@ -1,5 +1,5 @@ { "name": "Should throw exception when less than two arguments are provided", "expression": ["plus", 0.2], - "expectsFailure": "Invalid number of args" + "expectsFailure": "Invalid" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json new file mode 100644 index 0000000000..984ffcaecf --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle adding zero", + "expression": ["plus", 42, 0], + "expects": 42 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json new file mode 100644 index 0000000000..8c6ae279f4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should add [float, integer]", + "expression": ["plus", 10.5, 20], + "expects": 30.5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json new file mode 100644 index 0000000000..8398f8db8c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should add [string, float] when string is valid number", + "expression": ["plus", "10.5", 20.3], + "expects": 30.8 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json new file mode 100644 index 0000000000..062c414d24 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json @@ -0,0 +1,5 @@ +{ + "name": "Should add [string, integer] when string is valid number", + "expression": ["plus", "10", 20], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json new file mode 100644 index 0000000000..20feae704f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with [boolean, integer]", + "expression": ["plus", true, 10], + "expectsFailure": "Expected number, got value true" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json new file mode 100644 index 0000000000..9749de05ec --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["plus", "not a number", 10], + "expectsFailure": "Expected number, got value \"not a number\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json new file mode 100644 index 0000000000..0ea8299c08 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail with string with no decimals after dot", + "expression": ["plus", "55.", 10], + "expectsFailure": "Expected number, got value \"55.\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json new file mode 100644 index 0000000000..f1fef6afe7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json @@ -0,0 +1,5 @@ +{ + "name": "Should add two integers", + "expression": ["plus", 10, 20], + "expects": 30 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json new file mode 100644 index 0000000000..93589c50d7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json @@ -0,0 +1,5 @@ +{ + "name": "Should add scientific notation with regular number", + "expression": ["plus", 1e2, 50], + "expects": 150 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json new file mode 100644 index 0000000000..3ce291514e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json @@ -0,0 +1,5 @@ +{ + "name": "Should add numbers with negative exponents", + "expression": ["plus", 1e-3, 2e-3], + "expects": 0.003 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json new file mode 100644 index 0000000000..c1981169bc --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json @@ -0,0 +1,5 @@ +{ + "name": "Should add numbers in scientific notation", + "expression": ["plus", 1e3, 2e3], + "expects": 3000 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json new file mode 100644 index 0000000000..bcb831157c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should add string scientific notation with number", + "expression": ["plus", "1e2", 50], + "expectsFailure": "Expected number, got value \"1e2\"" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json new file mode 100644 index 0000000000..80a195e06f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very large numbers", + "expression": ["plus", 9007199254740991, 1], + "expects": 9007199254740992 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json new file mode 100644 index 0000000000..7ea180d925 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json @@ -0,0 +1,5 @@ +{ + "name": "Should handle very small numbers", + "expression": ["plus", 0.0000001, 0.0000002], + "expects": 0.0000003 +} From 1c226fb6bcbedb922d77d4d90b92f110a98e418a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 12:18:37 +0100 Subject: [PATCH 16/24] Made shared test json file names more consistant --- ...vide-one-null-value.json => diff-types-null-decimal.json} | 0 .../shared-tests/functions/divide/divide-by-one.json | 5 ----- .../{divide-one-argument.json => error-one-argument.json} | 0 .../divide/{divide-by-zero.json => error-zero-divisor.json} | 0 .../{divide-decimals.json => same-types-decimals.json} | 0 ...tiple-decimals.json => same-types-multiple-decimals.json} | 0 ...egative-values.json => same-types-negative-decimals.json} | 0 ...y-positive.json => same-types-negative-positive-int.json} | 0 ...vide-two-negatives.json => same-types-negatives-int.json} | 0 .../{divide-null-values.json => same-types-null-values.json} | 0 ...de-with-remainder.json => same-types-with-remainder.json} | 0 ...ero-by-number.json => same-types-zero-by-number-int.json} | 0 ...ng-one-null-value.json => diff-types-one-null-value.json} | 0 ...subtracting-one-argument.json => error-one-argument.json} | 0 .../{subtracting-decimals.json => same-types-decimals.json} | 0 ...tracting-from-zero.json => same-types-from-zero-int.json} | 0 ...tiple-decimals.json => same-types-multiple-decimals.json} | 0 ...egative-values.json => same-types-negative-decimals.json} | 0 ...itive.json => same-types-negative-from-positive-int.json} | 0 ...tracting-null-values.json => same-types-null-values.json} | 0 .../{subtracting-zero.json => same-types-zero-int.json} | 0 ...iply-one-null-value.json => diff-types-null-decimal.json} | 0 ...y-multiple-decimals.json => error-multiple-decimals.json} | 0 .../{multiply-one-argument.json => error-one-argument.json} | 0 .../shared-tests/functions/multiply/multiply-by-one.json | 5 ----- .../{multiply-decimals.json => same-types-decimals.json} | 0 ...e-positive.json => same-types-negative-positive-int.json} | 0 ...e-values.json => same-types-negative-values-decimal.json} | 0 ...multiply-null-values.json => same-types-null-values.json} | 0 ...-two-negatives.json => same-types-two-negatives-int.json} | 0 .../{multiply-by-zero.json => same-types-zero-int.json} | 0 .../CommonTests/shared-tests/functions/plus/adding-zero.json | 5 ----- ...ding-one-null-value.json => diff-types-decimal-null.json} | 0 ...tive-values.json => diff-types-negative-int-decimal.json} | 0 ...ing-multiple-values.json => error-multiple-decimals.json} | 0 .../{adding-one-argument.json => error-one-argument.json} | 0 .../plus/{adding-decimals.json => same-types-decimals.json} | 0 ...o-positive.json => same-types-negative-positive-int.json} | 0 .../{adding-null-values.json => same-types-null-values.json} | 0 39 files changed, 15 deletions(-) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-one-null-value.json => diff-types-null-decimal.json} (100%) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-one-argument.json => error-one-argument.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-by-zero.json => error-zero-divisor.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-decimals.json => same-types-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-multiple-decimals.json => same-types-multiple-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-negative-values.json => same-types-negative-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-negative-by-positive.json => same-types-negative-positive-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-two-negatives.json => same-types-negatives-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-null-values.json => same-types-null-values.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-with-remainder.json => same-types-with-remainder.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{divide-zero-by-number.json => same-types-zero-by-number-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-one-null-value.json => diff-types-one-null-value.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-one-argument.json => error-one-argument.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-decimals.json => same-types-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-from-zero.json => same-types-from-zero-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-multiple-decimals.json => same-types-multiple-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-negative-values.json => same-types-negative-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-negative-from-positive.json => same-types-negative-from-positive-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-null-values.json => same-types-null-values.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{subtracting-zero.json => same-types-zero-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-one-null-value.json => diff-types-null-decimal.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-multiple-decimals.json => error-multiple-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-one-argument.json => error-one-argument.json} (100%) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-decimals.json => same-types-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-negative-positive.json => same-types-negative-positive-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-negative-values.json => same-types-negative-values-decimal.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-null-values.json => same-types-null-values.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-two-negatives.json => same-types-two-negatives-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{multiply-by-zero.json => same-types-zero-int.json} (100%) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-one-null-value.json => diff-types-decimal-null.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-negative-values.json => diff-types-negative-int-decimal.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-multiple-values.json => error-multiple-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-one-argument.json => error-one-argument.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-decimals.json => same-types-decimals.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-negative-to-positive.json => same-types-negative-positive-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{adding-null-values.json => same-types-null-values.json} (100%) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-null-value.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json deleted file mode 100644 index 4cf8fbede0..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-one.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle dividing by one", - "expression": ["divide", 42, 1], - "expects": 42 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-one-argument.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-by-zero.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-multiple-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-multiple-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-negative-by-positive.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-two-negatives.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-null-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-with-remainder.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide-zero-by-number.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-null-value.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-one-argument.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-from-zero.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-multiple-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-multiple-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-from-positive-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-negative-from-positive.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-from-positive-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-null-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/subtracting-zero.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-null-value.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-multiple-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-multiple-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-one-argument.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json deleted file mode 100644 index fc5b6db16e..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-one.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle multiplying by one", - "expression": ["multiply", 42, 1], - "expects": 42 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-positive.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-values-decimal.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-negative-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-values-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-null-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-two-negatives.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply-by-zero.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json deleted file mode 100644 index 984ffcaecf..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-zero.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle adding zero", - "expression": ["plus", 42, 0], - "expects": 42 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-null-value.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-multiple-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-multiple-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-multiple-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-one-argument.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-negative-to-positive.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/adding-null-values.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json From f78d4231489889c5fb4fc7b4f245099367fc07cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 12:48:04 +0100 Subject: [PATCH 17/24] Added same-types-negative-positive-decimal tests for consistency with int tests --- ...-types-float-int.json => diff-types-float-int-valid.json} | 0 ...-null-decimal.json => diff-types-null-decimal-valid.json} | 0 ...s-multiple-decimals.json => error-multiple-decimals.json} | 0 .../divide/same-types-negative-positive-decimal.json | 5 +++++ .../minus/same-types-negative-positive-decimal.json | 5 +++++ ...sitive-int.json => same-types-negative-positive-int.json} | 0 ...-values-decimal.json => same-types-negative-decimal.json} | 0 .../multiply/same-types-negative-positive-decimal.json | 5 +++++ .../functions/plus/same-types-negative-positive-decimal.json | 5 +++++ 9 files changed, 20 insertions(+) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{diff-types-float-int.json => diff-types-float-int-valid.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{diff-types-null-decimal.json => diff-types-null-decimal-valid.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{same-types-multiple-decimals.json => error-multiple-decimals.json} (100%) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{same-types-negative-from-positive-int.json => same-types-negative-positive-int.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{same-types-negative-values-decimal.json => same-types-negative-decimal.json} (100%) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-multiple-decimals.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-multiple-decimals.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json new file mode 100644 index 0000000000..f9d22855df --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json @@ -0,0 +1,5 @@ +{ + "name": "Should divide negative by positive decimal", + "expression": ["divide", -0.1, 0.2], + "expects": -0.5 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json new file mode 100644 index 0000000000..e8cfa5c368 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json @@ -0,0 +1,5 @@ +{ + "name": "Should subtract negative from positive decimal", + "expression": ["minus", 50.55, -30.77], + "expects": 81.32 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-from-positive-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-from-positive-int.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-values-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-values-decimal.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json new file mode 100644 index 0000000000..73d75e6059 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json @@ -0,0 +1,5 @@ +{ + "name": "Should multiply negative and positive decimal numbers", + "expression": ["multiply", -5.55, 6.66], + "expects": -36.963 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json new file mode 100644 index 0000000000..884dae2c41 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json @@ -0,0 +1,5 @@ +{ + "name": "Should add negative and positive decimal numbers", + "expression": ["plus", 50.55, -30.66], + "expects": 19.89 +} From 9d9d715d10fb69c2ef8948be99de539c0a57cd49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 13:59:42 +0100 Subject: [PATCH 18/24] Implemented suggested changes by code rabbit --- .../Internal/Expressions/ExpressionEvaluator.cs | 11 ++++++----- .../LayoutExpressions/CommonTests/TestFunctions.cs | 2 +- .../functions/divide/diff-types-null-zero.json | 5 +++++ .../shared-tests/functions/divide/error-bool-int.json | 2 +- ...le-decimals.json => error-too-many-arguments.json} | 0 ...le-decimals.json => error-too-many-arguments.json} | 0 ...le-decimals.json => error-too-many-arguments.json} | 0 ...le-decimals.json => error-too-many-arguments.json} | 0 8 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/{error-multiple-decimals.json => error-too-many-arguments.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/{same-types-multiple-decimals.json => error-too-many-arguments.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/{error-multiple-decimals.json => error-too-many-arguments.json} (100%) rename test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/{error-multiple-decimals.json => error-too-many-arguments.json} (100%) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index d23abed75d..23b236ec99 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -11,7 +11,7 @@ namespace Altinn.App.Core.Internal.Expressions; /// /// Static class used to evaluate expressions. Holds the implementation for all expression functions. /// -public static class ExpressionEvaluator +public static partial class ExpressionEvaluator { /// /// Shortcut for evaluating a boolean expression on a given property on a @@ -865,11 +865,9 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) ); } - private static readonly Regex _numberRegex = new(@"^-?\d+(\.\d+)?$"); - internal static decimal? ParseNumber(string s, bool throwException = true) { - if (_numberRegex.IsMatch(s) && decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) + if (NumberRegex().IsMatch(s) && decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) { return d; } @@ -913,7 +911,7 @@ private static bool LessThan(ExpressionValue[] args) private static decimal? Divide(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); - if (b == 0) + if (a != null && b == 0) { throw new ExpressionEvaluatorTypeErrorException("The second argument is 0, cannot divide by 0"); } @@ -992,4 +990,7 @@ private static ExpressionValue Argv(ExpressionValue[] args, ExpressionValue[]? p return positionalArguments[index.Value]; } + + [GeneratedRegex(@"^-?\d+(\.\d+)?$")] + private static partial Regex NumberRegex(); } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 6c0f1da5d8..9e0a6bdb77 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -288,7 +288,7 @@ private async Task RunTestCase(string testName, string folder) e.ValueKind switch { JsonValueKind.String => e.GetString(), - JsonValueKind.Number => e.GetDouble(), + JsonValueKind.Number => e.GetDecimal(), JsonValueKind.True => true, JsonValueKind.False => false, JsonValueKind.Null => null, diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json new file mode 100644 index 0000000000..1074841209 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json @@ -0,0 +1,5 @@ +{ + "name": "Should return null when dividend is null and divisor is zero", + "expression": ["divide", null, 0], + "expects": null +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json index 53c6437054..fcb3692158 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json @@ -1,5 +1,5 @@ { "name": "Should fail with [boolean, integer]", - "expression": ["divide", 100, true], + "expression": ["divide", true, 100], "expectsFailure": "Expected number, got value true" } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-multiple-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json similarity index 100% rename from test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-multiple-decimals.json rename to test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json From 0c11ff44a6fc59114af5e785a23846d55dd36f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 14:07:21 +0100 Subject: [PATCH 19/24] Implemented suggested changes from code rabbit --- .../functions/divide/same-types-with-remainder.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json deleted file mode 100644 index 81c6f32a4a..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-with-remainder.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle division with remainder", - "expression": ["divide", 10, 3], - "expects": 3.3333333333333333333333333333 -} From 1debfe3433115a03cf5b5a71f1610448d42c9c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 16:17:51 +0100 Subject: [PATCH 20/24] Changed to single json file for each arithmetic operation. --- .../CommonTests/ExpressionTestCaseRoot.cs | 5 +- .../TestBackendExclusiveFunctions.cs | 5 +- .../CommonTests/TestFunctions.cs | 26 ++-- .../CommonTests/TestInvalid.cs | 7 +- .../divide/diff-types-float-int-valid.json | 5 - .../divide/diff-types-null-decimal-valid.json | 5 - .../divide/diff-types-null-zero.json | 5 - .../divide/diff-types-string-float-valid.json | 5 - .../divide/diff-types-string-int-valid.json | 5 - .../shared-tests/functions/divide/divide.json | 130 ++++++++++++++++++ .../functions/divide/error-bool-int.json | 5 - .../divide/error-invalid-string.json | 5 - .../functions/divide/error-no-decimals.json | 5 - .../functions/divide/error-one-argument.json | 5 - .../divide/error-too-many-arguments.json | 5 - .../functions/divide/error-zero-divisor.json | 5 - .../functions/divide/same-types-decimals.json | 5 - .../functions/divide/same-types-int.json | 5 - .../divide/same-types-negative-decimals.json | 5 - .../same-types-negative-positive-decimal.json | 5 - .../same-types-negative-positive-int.json | 5 - .../divide/same-types-negatives-int.json | 5 - .../divide/same-types-null-values.json | 5 - .../divide/same-types-zero-by-number-int.json | 5 - .../divide/scientific-notation-mixed.json | 5 - ...scientific-notation-negative-exponent.json | 5 - .../divide/scientific-notation-simple.json | 5 - .../divide/scientific-notation-string.json | 5 - .../functions/divide/very-large-numbers.json | 5 - .../functions/divide/very-small-numbers.json | 5 - .../functions/minus/diff-types-float-int.json | 5 - .../minus/diff-types-one-null-value.json | 5 - .../minus/diff-types-string-float-valid.json | 5 - .../minus/diff-types-string-int-valid.json | 5 - .../functions/minus/error-bool-int.json | 5 - .../functions/minus/error-invalid-string.json | 5 - .../functions/minus/error-no-decimals.json | 5 - .../functions/minus/error-one-argument.json | 5 - .../minus/error-too-many-arguments.json | 5 - .../shared-tests/functions/minus/minus.json | 120 ++++++++++++++++ .../functions/minus/same-types-decimals.json | 5 - .../minus/same-types-from-zero-int.json | 5 - .../functions/minus/same-types-int.json | 5 - .../minus/same-types-negative-decimals.json | 5 - .../same-types-negative-positive-decimal.json | 5 - .../same-types-negative-positive-int.json | 5 - .../minus/same-types-null-values.json | 5 - .../functions/minus/same-types-zero-int.json | 5 - .../minus/scientific-notation-mixed.json | 5 - ...scientific-notation-negative-exponent.json | 5 - .../minus/scientific-notation-simple.json | 5 - .../minus/scientific-notation-string.json | 5 - .../functions/minus/very-large-numbers.json | 5 - .../functions/minus/very-small-numbers.json | 5 - .../multiply/diff-types-float-int.json | 5 - .../multiply/diff-types-null-decimal.json | 5 - .../diff-types-string-float-valid.json | 5 - .../multiply/diff-types-string-int-valid.json | 5 - .../functions/multiply/error-bool-int.json | 5 - .../multiply/error-invalid-string.json | 5 - .../functions/multiply/error-no-decimals.json | 5 - .../multiply/error-one-argument.json | 5 - .../multiply/error-too-many-arguments.json | 5 - .../functions/multiply/multiply.json | 120 ++++++++++++++++ .../multiply/same-types-decimals.json | 5 - .../functions/multiply/same-types-int.json | 5 - .../multiply/same-types-negative-decimal.json | 5 - .../same-types-negative-positive-decimal.json | 5 - .../same-types-negative-positive-int.json | 5 - .../multiply/same-types-null-values.json | 5 - .../same-types-two-negatives-int.json | 5 - .../multiply/same-types-zero-int.json | 5 - .../multiply/scientific-notation-mixed.json | 5 - ...scientific-notation-negative-exponent.json | 5 - .../multiply/scientific-notation-simple.json | 5 - .../multiply/scientific-notation-string.json | 5 - .../multiply/very-large-numbers.json | 5 - .../multiply/very-small-numbers.json | 5 - .../plus/diff-types-decimal-null.json | 5 - .../functions/plus/diff-types-float-int.json | 5 - .../plus/diff-types-negative-int-decimal.json | 5 - .../plus/diff-types-string-float-valid.json | 5 - .../plus/diff-types-string-int-valid.json | 5 - .../functions/plus/error-bool-int.json | 5 - .../functions/plus/error-invalid-string.json | 5 - .../functions/plus/error-no-decimals.json | 5 - .../functions/plus/error-one-argument.json | 5 - .../plus/error-too-many-arguments.json | 5 - .../shared-tests/functions/plus/plus.json | 110 +++++++++++++++ .../functions/plus/same-types-decimals.json | 5 - .../functions/plus/same-types-int.json | 5 - .../same-types-negative-positive-decimal.json | 5 - .../same-types-negative-positive-int.json | 5 - .../plus/same-types-null-values.json | 5 - .../plus/scientific-notation-mixed.json | 5 - ...scientific-notation-negative-exponent.json | 5 - .../plus/scientific-notation-simple.json | 5 - .../plus/scientific-notation-string.json | 5 - .../functions/plus/very-large-numbers.json | 5 - .../functions/plus/very-small-numbers.json | 5 - 100 files changed, 508 insertions(+), 475 deletions(-) delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json delete mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs index d1a0d9de3b..54d22f29e8 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs @@ -29,7 +29,7 @@ public class ExpressionTestCaseRoot public string? Name { get; set; } [JsonPropertyName("expression")] - public Expression Expression { get; set; } + public Expression? Expression { get; set; } [JsonPropertyName("context")] public ComponentContextForTestSpec? Context { get; set; } @@ -42,6 +42,9 @@ public class ExpressionTestCaseRoot public class TestCaseItem { + [JsonPropertyName("name")] + public string? Name { get; set; } + [JsonPropertyName("expression")] public required Expression Expression { get; set; } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs index 5ce7e4a049..72aafdf502 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Altinn.App.Core.Internal.Expressions; +using Altinn.App.Core.Models.Expressions; using Altinn.App.Core.Models.Layout; using Altinn.App.Core.Tests.LayoutExpressions.TestUtilities; using Altinn.App.Core.Tests.TestUtils; @@ -90,7 +91,7 @@ private async Task RunTestCase(string testName, string folder) { await ExpressionEvaluator.EvaluateExpression( state, - test.Expression, + test.Expression ?? new Expression(), await test.GetContextOrNull(state) ); }; @@ -104,7 +105,7 @@ await test.GetContextOrNull(state) var result = await ExpressionEvaluator.EvaluateExpression( state, - test.Expression, + test.Expression ?? new Expression(), await test.GetContextOrNull(state)! ); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 9e0a6bdb77..a24db29e73 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -373,17 +373,20 @@ private async Task RunTestCase(string testName, string folder) test.ParsingException.Should().BeNull("Loading of test failed"); - await RunTestCaseItem( - new ExpressionTestCaseRoot.TestCaseItem() - { - Expects = test.Expects, - Expression = test.Expression, - ExpectsFailure = test.ExpectsFailure, - }, - state, - context, - positionalArguments - ); + if (test.Expression != null) + { + await RunTestCaseItem( + new ExpressionTestCaseRoot.TestCaseItem() + { + Expects = test.Expects, + Expression = test.Expression ?? new Expression(), + ExpectsFailure = test.ExpectsFailure, + }, + state, + context, + positionalArguments + ); + } if (test.TestCases != null) { @@ -401,6 +404,7 @@ private async Task RunTestCaseItem( object?[]? positionalArguments ) { + _output.WriteLine(test.Name ?? ""); if (test.ExpectsFailure is not null) { _output.WriteLine($"Expecting failure: {test.ExpectsFailure}"); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs index c935f44554..07a2e9270d 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs @@ -1,5 +1,6 @@ using System.Text.Json; using Altinn.App.Core.Internal.Expressions; +using Altinn.App.Core.Models.Expressions; using Altinn.App.Core.Models.Layout; using Altinn.App.Core.Tests.LayoutExpressions.TestUtilities; using Altinn.App.Core.Tests.TestUtils; @@ -53,7 +54,11 @@ public async Task Simple_Theory(string testName, string folder) test.FrontEndSettings ?? new() ); - await ExpressionEvaluator.EvaluateExpression(state, test.Expression, await test.GetContextOrNull(state)); + await ExpressionEvaluator.EvaluateExpression( + state, + test.Expression ?? new Expression(), + await test.GetContextOrNull(state) + ); }; (await act.Should().ThrowAsync()).WithMessage(testCase.ExpectsFailure + "*"); } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json deleted file mode 100644 index 8978f2bfcf..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-float-int-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide [float, integer]", - "expression": ["divide", 30.0, 6], - "expects": 5.0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json deleted file mode 100644 index 7e30c95f52..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-decimal-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when one of the arguments is null", - "expression": ["divide", null, 2.1], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json deleted file mode 100644 index 1074841209..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-null-zero.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when dividend is null and divisor is zero", - "expression": ["divide", null, 0], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json deleted file mode 100644 index ca98307301..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-float-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide [string, float] when string is valid number", - "expression": ["divide", "22.0", 4.0], - "expects": 5.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json deleted file mode 100644 index efe744a093..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/diff-types-string-int-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide [string, integer] when string is valid number", - "expression": ["divide", "30", 6], - "expects": 5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json new file mode 100644 index 0000000000..23200bb6dd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json @@ -0,0 +1,130 @@ +{ + "name": "Divide tests", + "testCases": [ + { + "name": "Should divide the first argument with the second", + "expression": ["divide", 0.1, 0.2], + "expects": 0.5 + }, + { + "name": "Should divide the first argument with the second", + "expression": ["divide", -0.1, -0.2], + "expects": 0.5 + }, + { + "name": "Should return null when both of the arguments are null", + "expression": ["divide", null, null], + "expects": null + }, + { + "name": "Should return null when one of the arguments is null", + "expression": ["divide", null, 2.1], + "expects": null + }, + { + "name": "Should divide two integers", + "expression": ["divide", 30, 6], + "expects": 5 + }, + { + "name": "Should divide [float, integer]", + "expression": ["divide", 30.0, 6], + "expects": 5.0 + }, + { + "name": "Should divide [string, integer] when string is valid number", + "expression": ["divide", "30", 6], + "expects": 5 + }, + { + "name": "Should divide [string, float] when string is valid number", + "expression": ["divide", "22.0", 4.0], + "expects": 5.5 + }, + { + "name": "Should handle dividing zero by a number", + "expression": ["divide", 0, 42], + "expects": 0 + }, + { + "name": "Should divide negative by positive", + "expression": ["divide", -30, 6], + "expects": -5 + }, + { + "name": "Should divide two negative numbers", + "expression": ["divide", -30, -6], + "expects": 5 + }, + { + "name": "Should divide numbers in scientific notation", + "expression": ["divide", 6e3, 2e3], + "expects": 3 + }, + { + "name": "Should divide numbers with negative exponents", + "expression": ["divide", 6e-3, 2e-3], + "expects": 3 + }, + { + "name": "Should divide scientific notation by regular number", + "expression": ["divide", 5e2, 10], + "expects": 50 + }, + { + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["divide", 100, "not a number"], + "expectsFailure": "Expected number, got value \"not a number\"" + }, + { + "name": "Should fail with string with no decimals after dot", + "expression": ["divide", "55.", 5], + "expectsFailure": "Expected number, got value \"55.\"" + }, + { + "name": "Should handle very large numbers", + "expression": ["divide", 1000000000000, 1000000], + "expects": 1000000 + }, + { + "name": "Should handle very small numbers", + "expression": ["divide", 0.00000001, 0.0001], + "expects": 0.0001 + }, + { + "name": "Should divide string scientific notation by number", + "expression": ["divide", "5e2", 10], + "expectsFailure": "Expected number, got value \"5e2\"" + }, + { + "name": "Should throw exception when less than two arguments are provided", + "expression": ["divide", 2.1], + "expectsFailure": "Invalid" + }, + { + "name": "Should throw exception when more than two arguments are present", + "expression": ["divide", 0.1, 0.2, 15, 1.50], + "expectsFailure": "Invalid" + }, + { + "name": "Should divide negative by positive decimal", + "expression": ["divide", -0.1, 0.2], + "expects": -0.5 + }, + { + "name": "Should return null when dividend is null and divisor is zero", + "expression": ["divide", null, 0], + "expects": null + }, + { + "name": "Should throw exception when trying to divide by zero", + "expression": ["divide", 15, 0], + "expectsFailure": "The second argument is 0, cannot divide by 0" + }, + { + "name": "Should fail with [boolean, integer]", + "expression": ["divide", true, 100], + "expectsFailure": "Expected number, got value true" + } + ] +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json deleted file mode 100644 index fcb3692158..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-bool-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with [boolean, integer]", - "expression": ["divide", true, 100], - "expectsFailure": "Expected number, got value true" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json deleted file mode 100644 index 0c2f5d13fd..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-invalid-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with invalid string that cannot be parsed as number", - "expression": ["divide", 100, "not a number"], - "expectsFailure": "Expected number, got value \"not a number\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json deleted file mode 100644 index 036b0197b2..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-no-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with string with no decimals after dot", - "expression": ["divide", "55.", 5], - "expectsFailure": "Expected number, got value \"55.\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json deleted file mode 100644 index b0f5029b8f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-one-argument.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when less than two arguments are provided", - "expression": ["divide", 2.1], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json deleted file mode 100644 index dd5c3ab793..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-too-many-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when more than two arguments are present", - "expression": ["divide", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json deleted file mode 100644 index abb25771a4..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/error-zero-divisor.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when trying to divide by zero", - "expression": ["divide", 15, 0], - "expectsFailure": "The second argument is 0, cannot divide by 0" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json deleted file mode 100644 index 9c4061d3d3..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide the first argument with the second", - "expression": ["divide", 0.1, 0.2], - "expects": 0.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json deleted file mode 100644 index a43facfbd8..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide two integers", - "expression": ["divide", 30, 6], - "expects": 5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json deleted file mode 100644 index 7f69aa3791..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide the first argument with the second", - "expression": ["divide", -0.1, -0.2], - "expects": 0.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json deleted file mode 100644 index f9d22855df..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide negative by positive decimal", - "expression": ["divide", -0.1, 0.2], - "expects": -0.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json deleted file mode 100644 index 6f4e35a1b7..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negative-positive-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide negative by positive", - "expression": ["divide", -30, 6], - "expects": -5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json deleted file mode 100644 index 13ab2377de..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-negatives-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide two negative numbers", - "expression": ["divide", -30, -6], - "expects": 5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json deleted file mode 100644 index a54e895801..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-null-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when both of the arguments are null", - "expression": ["divide", null, null], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json deleted file mode 100644 index d77942848b..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/same-types-zero-by-number-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle dividing zero by a number", - "expression": ["divide", 0, 42], - "expects": 0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json deleted file mode 100644 index ac46999b05..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-mixed.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide scientific notation by regular number", - "expression": ["divide", 5e2, 10], - "expects": 50 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json deleted file mode 100644 index 921c675b8b..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-negative-exponent.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide numbers with negative exponents", - "expression": ["divide", 6e-3, 2e-3], - "expects": 3 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json deleted file mode 100644 index 03cb93e6aa..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-simple.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide numbers in scientific notation", - "expression": ["divide", 6e3, 2e3], - "expects": 3 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json deleted file mode 100644 index 92bd77b87f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/scientific-notation-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should divide string scientific notation by number", - "expression": ["divide", "5e2", 10], - "expectsFailure": "Expected number, got value \"5e2\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json deleted file mode 100644 index 9dddd5601a..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-large-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very large numbers", - "expression": ["divide", 1000000000000, 1000000], - "expects": 1000000 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json deleted file mode 100644 index dea4395d2c..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/very-small-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very small numbers", - "expression": ["divide", 0.00000001, 0.0001], - "expects": 0.0001 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json deleted file mode 100644 index 0ab080ad44..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-float-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract [float, integer]", - "expression": ["minus", 50.5, 20], - "expects": 30.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json deleted file mode 100644 index 9e37685657..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-one-null-value.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when one of the arguments is null", - "expression": ["minus", null, 2.1], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json deleted file mode 100644 index b41b7ccbdf..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-float-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract [string, float] when string is valid number", - "expression": ["minus", "50.8", 20.3], - "expects": 30.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json deleted file mode 100644 index 44652a480e..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/diff-types-string-int-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract [string, integer] when string is valid number", - "expression": ["minus", "50", 20], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json deleted file mode 100644 index ee6de42e44..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-bool-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with [boolean, integer]", - "expression": ["minus", false, 10], - "expectsFailure": "Expected number, got value false" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json deleted file mode 100644 index 97a579aab5..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-invalid-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with invalid string that cannot be parsed as number", - "expression": ["minus", 50, "not a number"], - "expectsFailure": "Expected number, got value \"not a number\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json deleted file mode 100644 index 86329aca19..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-no-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with string with no decimals after dot", - "expression": ["minus", "55.", 10], - "expectsFailure": "Expected number, got value \"55.\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json deleted file mode 100644 index 80c8034fc8..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-one-argument.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when less than two arguments are provided", - "expression": ["minus", 0.2], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json deleted file mode 100644 index 17df0e15f2..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/error-too-many-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when more than two arguments are present", - "expression": ["minus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json new file mode 100644 index 0000000000..ffd9cd501c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json @@ -0,0 +1,120 @@ +{ + "name": "Minus tests", + "testCases": [ + { + "name": "Should subtract the second argument from the first", + "expression": ["minus", 0.1, 0.2], + "expects": -0.1 + }, + { + "name": "Should subtract the second negative argument from the first", + "expression": ["minus", -0.1, -0.2], + "expects": 0.1 + }, + { + "name": "Should return null when both of the arguments are null", + "expression": ["minus", null, null], + "expects": null + }, + { + "name": "Should return null when one of the arguments is null", + "expression": ["minus", null, 2.1], + "expects": null + }, + { + "name": "Should subtract two integers", + "expression": ["minus", 50, 20], + "expects": 30 + }, + { + "name": "Should subtract [float, integer]", + "expression": ["minus", 50.5, 20], + "expects": 30.5 + }, + { + "name": "Should subtract [string, integer] when string is valid number", + "expression": ["minus", "50", 20], + "expects": 30 + }, + { + "name": "Should subtract [string, float] when string is valid number", + "expression": ["minus", "50.8", 20.3], + "expects": 30.5 + }, + { + "name": "Should handle subtracting zero", + "expression": ["minus", 42, 0], + "expects": 42 + }, + { + "name": "Should handle subtracting from zero", + "expression": ["minus", 0, 42], + "expects": -42 + }, + { + "name": "Should subtract negative from positive", + "expression": ["minus", 50, -30], + "expects": 80 + }, + { + "name": "Should subtract numbers in scientific notation", + "expression": ["minus", 5e3, 2e3], + "expects": 3000 + }, + { + "name": "Should subtract numbers with negative exponents", + "expression": ["minus", 5e-3, 2e-3], + "expects": 0.003 + }, + { + "name": "Should subtract scientific notation from regular number", + "expression": ["minus", 150, 1e2], + "expects": 50 + }, + { + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["minus", 50, "not a number"], + "expectsFailure": "Expected number, got value \"not a number\"" + }, + { + "name": "Should fail with [boolean, integer]", + "expression": ["minus", false, 10], + "expectsFailure": "Expected number, got value false" + }, + { + "name": "Should fail with string with no decimals after dot", + "expression": ["minus", "55.", 10], + "expectsFailure": "Expected number, got value \"55.\"" + }, + { + "name": "Should handle very large numbers", + "expression": ["minus", 9007199254740992, 1], + "expects": 9007199254740991 + }, + { + "name": "Should handle very small numbers", + "expression": ["minus", 0.0000003, 0.0000001], + "expects": 0.0000002 + }, + { + "name": "Should throw exception when less than two arguments are provided", + "expression": ["minus", 0.2], + "expectsFailure": "Invalid" + }, + { + "name": "Should subtract string scientific notation from number", + "expression": ["minus", 150, "1e2"], + "expectsFailure": "Expected number, got value \"1e2\"" + }, + { + "name": "Should throw exception when more than two arguments are present", + "expression": ["minus", 0.1, 0.2, 15, 1.50], + "expectsFailure": "Invalid" + }, + { + "name": "Should subtract negative from positive decimal", + "expression": ["minus", 50.55, -30.77], + "expects": 81.32 + } + ] +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json deleted file mode 100644 index adc5cc16f7..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract the second argument from the first", - "expression": ["minus", 0.1, 0.2], - "expects": -0.1 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json deleted file mode 100644 index b8ca6df6e1..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-from-zero-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle subtracting from zero", - "expression": ["minus", 0, 42], - "expects": -42 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json deleted file mode 100644 index 7fd077accf..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract two integers", - "expression": ["minus", 50, 20], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json deleted file mode 100644 index 7c7eab7535..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract the second negative argument from the first", - "expression": ["minus", -0.1, -0.2], - "expects": 0.1 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json deleted file mode 100644 index e8cfa5c368..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract negative from positive decimal", - "expression": ["minus", 50.55, -30.77], - "expects": 81.32 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json deleted file mode 100644 index 143e924fa6..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-negative-positive-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract negative from positive", - "expression": ["minus", 50, -30], - "expects": 80 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json deleted file mode 100644 index 07166edea4..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-null-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when both of the arguments are null", - "expression": ["minus", null, null], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json deleted file mode 100644 index f17ab56c68..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/same-types-zero-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle subtracting zero", - "expression": ["minus", 42, 0], - "expects": 42 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json deleted file mode 100644 index e9b14d9735..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-mixed.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract scientific notation from regular number", - "expression": ["minus", 150, 1e2], - "expects": 50 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json deleted file mode 100644 index ab71a94afe..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-negative-exponent.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract numbers with negative exponents", - "expression": ["minus", 5e-3, 2e-3], - "expects": 0.003 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json deleted file mode 100644 index 2c319861b6..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-simple.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract numbers in scientific notation", - "expression": ["minus", 5e3, 2e3], - "expects": 3000 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json deleted file mode 100644 index 5b9e31fb3d..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/scientific-notation-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should subtract string scientific notation from number", - "expression": ["minus", 150, "1e2"], - "expectsFailure": "Expected number, got value \"1e2\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json deleted file mode 100644 index 9a387dd08e..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-large-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very large numbers", - "expression": ["minus", 9007199254740992, 1], - "expects": 9007199254740991 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json deleted file mode 100644 index ee28da24b6..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/very-small-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very small numbers", - "expression": ["minus", 0.0000003, 0.0000001], - "expects": 0.0000002 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json deleted file mode 100644 index 9a5f03cae1..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-float-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply [float, integer]", - "expression": ["multiply", 7.5, 4], - "expects": 30.0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json deleted file mode 100644 index c3e7cc0927..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-null-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when one of the arguments is null", - "expression": ["multiply", null, 2.1], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json deleted file mode 100644 index 8fd2a39091..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-float-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply [string, float] when string is valid number", - "expression": ["multiply", "5.5", 4.0], - "expects": 22.0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json deleted file mode 100644 index e0bcc31140..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/diff-types-string-int-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply [string, integer] when string is valid number", - "expression": ["multiply", "5", 6], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json deleted file mode 100644 index db28d0d6c5..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-bool-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with [boolean, integer]", - "expression": ["multiply", true, 5], - "expectsFailure": "Expected number, got value true" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json deleted file mode 100644 index 958508e642..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-invalid-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with invalid string that cannot be parsed as number", - "expression": ["multiply", "not a number", 5], - "expectsFailure": "Expected number, got value \"not a number\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json deleted file mode 100644 index b4abc63e60..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-no-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with string with no decimals after dot", - "expression": ["multiply", "55.", 5], - "expectsFailure": "Expected number, got value \"55.\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json deleted file mode 100644 index 1984c25515..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-one-argument.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when less than two arguments are provided", - "expression": ["multiply", 0.1], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json deleted file mode 100644 index a0d5ab0f86..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/error-too-many-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when more than two arguments are present", - "expression": ["multiply", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json new file mode 100644 index 0000000000..eed78c01ce --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json @@ -0,0 +1,120 @@ +{ + "name": "Mutiply tests", + "testCases": [ + { + "name": "Should multiply the two arguments", + "expression": ["multiply", 0.1, 0.2], + "expects": 0.02 + }, + { + "name": "Should return null when both of the arguments are null", + "expression": ["multiply", null, null], + "expects": null + }, + { + "name": "Should multiply the two negative arguments", + "expression": ["multiply", -0.1, -0.2], + "expects": 0.02 + }, + { + "name": "Should return null when one of the arguments is null", + "expression": ["multiply", null, 2.1], + "expects": null + }, + { + "name": "Should multiply two integers", + "expression": ["multiply", 5, 6], + "expects": 30 + }, + { + "name": "Should multiply [float, integer]", + "expression": ["multiply", 7.5, 4], + "expects": 30.0 + }, + { + "name": "Should multiply [string, integer] when string is valid number", + "expression": ["multiply", "5", 6], + "expects": 30 + }, + { + "name": "Should multiply [string, float] when string is valid number", + "expression": ["multiply", "5.5", 4.0], + "expects": 22.0 + }, + { + "name": "Should handle multiplying by zero", + "expression": ["multiply", 42, 0], + "expects": 0 + }, + { + "name": "Should multiply negative and positive numbers", + "expression": ["multiply", -5, 6], + "expects": -30 + }, + { + "name": "Should multiply two negative numbers", + "expression": ["multiply", -5, -6], + "expects": 30 + }, + { + "name": "Should multiply numbers in scientific notation", + "expression": ["multiply", 2e3, 3e2], + "expects": 600000 + }, + { + "name": "Should multiply numbers with negative exponents", + "expression": ["multiply", 2e-3, 3e-2], + "expects": 0.00006 + }, + { + "name": "Should multiply scientific notation with regular number", + "expression": ["multiply", 1e2, 5], + "expects": 500 + }, + { + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["multiply", "not a number", 5], + "expectsFailure": "Expected number, got value \"not a number\"" + }, + { + "name": "Should fail with [boolean, integer]", + "expression": ["multiply", true, 5], + "expectsFailure": "Expected number, got value true" + }, + { + "name": "Should fail with string with no decimals after dot", + "expression": ["multiply", "55.", 5], + "expectsFailure": "Expected number, got value \"55.\"" + }, + { + "name": "Should handle very large numbers", + "expression": ["multiply", 1000000, 1000000], + "expects": 1000000000000 + }, + { + "name": "Should handle very small numbers", + "expression": ["multiply", 0.0001, 0.0001], + "expects": 0.00000001 + }, + { + "name": "Should multiply string scientific notation with number", + "expression": ["multiply", "1e2", 5], + "expectsFailure": "Expected number, got value \"1e2\"" + }, + { + "name": "Should throw exception when less than two arguments are provided", + "expression": ["multiply", 0.1], + "expectsFailure": "Invalid" + }, + { + "name": "Should throw exception when more than two arguments are present", + "expression": ["multiply", 0.1, 0.2, 15, 1.50], + "expectsFailure": "Invalid" + }, + { + "name": "Should multiply negative and positive decimal numbers", + "expression": ["multiply", -5.55, 6.66], + "expects": -36.963 + } + ] +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json deleted file mode 100644 index 624b14366b..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply the two arguments", - "expression": ["multiply", 0.1, 0.2], - "expects": 0.02 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json deleted file mode 100644 index 1141fd27d9..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply two integers", - "expression": ["multiply", 5, 6], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json deleted file mode 100644 index 22edf04a9a..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply the two negative arguments", - "expression": ["multiply", -0.1, -0.2], - "expects": 0.02 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json deleted file mode 100644 index 73d75e6059..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply negative and positive decimal numbers", - "expression": ["multiply", -5.55, 6.66], - "expects": -36.963 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json deleted file mode 100644 index 72ad362aa5..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-negative-positive-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply negative and positive numbers", - "expression": ["multiply", -5, 6], - "expects": -30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json deleted file mode 100644 index 691f4bdb58..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-null-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when both of the arguments are null", - "expression": ["multiply", null, null], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json deleted file mode 100644 index 2190343ae0..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-two-negatives-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply two negative numbers", - "expression": ["multiply", -5, -6], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json deleted file mode 100644 index 48883ca8e1..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/same-types-zero-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle multiplying by zero", - "expression": ["multiply", 42, 0], - "expects": 0 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json deleted file mode 100644 index b25cda13d4..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-mixed.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply scientific notation with regular number", - "expression": ["multiply", 1e2, 5], - "expects": 500 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json deleted file mode 100644 index 0a1e24417f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-negative-exponent.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply numbers with negative exponents", - "expression": ["multiply", 2e-3, 3e-2], - "expects": 0.00006 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json deleted file mode 100644 index 85f7327624..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-simple.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply numbers in scientific notation", - "expression": ["multiply", 2e3, 3e2], - "expects": 600000 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json deleted file mode 100644 index f85745118a..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/scientific-notation-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should multiply string scientific notation with number", - "expression": ["multiply", "1e2", 5], - "expectsFailure": "Expected number, got value \"1e2\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json deleted file mode 100644 index cd943c82c0..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-large-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very large numbers", - "expression": ["multiply", 1000000, 1000000], - "expects": 1000000000000 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json deleted file mode 100644 index bcb5a934a2..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/very-small-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very small numbers", - "expression": ["multiply", 0.0001, 0.0001], - "expects": 0.00000001 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json deleted file mode 100644 index 3a04d0c977..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-decimal-null.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when one of the arguments is null", - "expression": ["plus", 4.3, null], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json deleted file mode 100644 index 8c6ae279f4..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-float-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add [float, integer]", - "expression": ["plus", 10.5, 20], - "expects": 30.5 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json deleted file mode 100644 index 72d79d9af7..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-negative-int-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add two negative numbers together", - "expression": ["plus", -4, -0.2], - "expects": -4.2 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json deleted file mode 100644 index 8398f8db8c..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-float-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add [string, float] when string is valid number", - "expression": ["plus", "10.5", 20.3], - "expects": 30.8 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json deleted file mode 100644 index 062c414d24..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/diff-types-string-int-valid.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add [string, integer] when string is valid number", - "expression": ["plus", "10", 20], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json deleted file mode 100644 index 20feae704f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-bool-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with [boolean, integer]", - "expression": ["plus", true, 10], - "expectsFailure": "Expected number, got value true" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json deleted file mode 100644 index 9749de05ec..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-invalid-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with invalid string that cannot be parsed as number", - "expression": ["plus", "not a number", 10], - "expectsFailure": "Expected number, got value \"not a number\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json deleted file mode 100644 index 0ea8299c08..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-no-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should fail with string with no decimals after dot", - "expression": ["plus", "55.", 10], - "expectsFailure": "Expected number, got value \"55.\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json deleted file mode 100644 index f06256fd35..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-one-argument.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when less than two arguments are provided", - "expression": ["plus", 0.2], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json deleted file mode 100644 index 45d19d78b0..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/error-too-many-arguments.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should throw exception when more than two arguments are present", - "expression": ["plus", 0.1, 0.2, 15, 1.50], - "expectsFailure": "Invalid" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json new file mode 100644 index 0000000000..0f646f5ee3 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json @@ -0,0 +1,110 @@ +{ + "name": "Plus tests", + "testCases": [ + { + "name": "Should add the two given numbers together", + "expression": ["plus", 0.1, 0.2], + "expects": 0.3 + }, + { + "name": "Should add two negative numbers together", + "expression": ["plus", -4, -0.2], + "expects": -4.2 + }, + { + "name": "Should return null when both of the arguments are null", + "expression": ["plus", null, null], + "expects": null + }, + { + "name": "Should return null when one of the arguments is null", + "expression": ["plus", 4.3, null], + "expects": null + }, + { + "name": "Should add two integers", + "expression": ["plus", 10, 20], + "expects": 30 + }, + { + "name": "Should add [float, integer]", + "expression": ["plus", 10.5, 20], + "expects": 30.5 + }, + { + "name": "Should add [string, integer] when string is valid number", + "expression": ["plus", "10", 20], + "expects": 30 + }, + { + "name": "Should add [string, float] when string is valid number", + "expression": ["plus", "10.5", 20.3], + "expects": 30.8 + }, + { + "name": "Should add negative and positive numbers", + "expression": ["plus", 50, -30], + "expects": 20 + }, + { + "name": "Should add numbers in scientific notation", + "expression": ["plus", 1e3, 2e3], + "expects": 3000 + }, + { + "name": "Should add numbers with negative exponents", + "expression": ["plus", 1e-3, 2e-3], + "expects": 0.003 + }, + { + "name": "Should add scientific notation with regular number", + "expression": ["plus", 1e2, 50], + "expects": 150 + }, + { + "name": "Should fail with invalid string that cannot be parsed as number", + "expression": ["plus", "not a number", 10], + "expectsFailure": "Expected number, got value \"not a number\"" + }, + { + "name": "Should fail with [boolean, integer]", + "expression": ["plus", true, 10], + "expectsFailure": "Expected number, got value true" + }, + { + "name": "Should fail with string with no decimals after dot", + "expression": ["plus", "55.", 10], + "expectsFailure": "Expected number, got value \"55.\"" + }, + { + "name": "Should handle very large numbers", + "expression": ["plus", 9007199254740991, 1], + "expects": 9007199254740992 + }, + { + "name": "Should handle very small numbers", + "expression": ["plus", 0.0000001, 0.0000002], + "expects": 0.0000003 + }, + { + "name": "Should add string scientific notation with number", + "expression": ["plus", "1e2", 50], + "expectsFailure": "Expected number, got value \"1e2\"" + }, + { + "name": "Should throw exception when less than two arguments are provided", + "expression": ["plus", 0.2], + "expectsFailure": "Invalid" + }, + { + "name": "Should throw exception when more than two arguments are present", + "expression": ["plus", 0.1, 0.2, 15, 1.50], + "expectsFailure": "Invalid" + }, + { + "name": "Should add negative and positive decimal numbers", + "expression": ["plus", 50.55, -30.66], + "expects": 19.89 + } + ] +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json deleted file mode 100644 index 3588338e12..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-decimals.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add the two given numbers together", - "expression": ["plus", 0.1, 0.2], - "expects": 0.3 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json deleted file mode 100644 index f1fef6afe7..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add two integers", - "expression": ["plus", 10, 20], - "expects": 30 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json deleted file mode 100644 index 884dae2c41..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-decimal.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add negative and positive decimal numbers", - "expression": ["plus", 50.55, -30.66], - "expects": 19.89 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json deleted file mode 100644 index 55c895a688..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-negative-positive-int.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add negative and positive numbers", - "expression": ["plus", 50, -30], - "expects": 20 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json deleted file mode 100644 index b49bc24fc9..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/same-types-null-values.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should return null when both of the arguments are null", - "expression": ["plus", null, null], - "expects": null -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json deleted file mode 100644 index 93589c50d7..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-mixed.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add scientific notation with regular number", - "expression": ["plus", 1e2, 50], - "expects": 150 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json deleted file mode 100644 index 3ce291514e..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-negative-exponent.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add numbers with negative exponents", - "expression": ["plus", 1e-3, 2e-3], - "expects": 0.003 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json deleted file mode 100644 index c1981169bc..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-simple.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add numbers in scientific notation", - "expression": ["plus", 1e3, 2e3], - "expects": 3000 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json deleted file mode 100644 index bcb831157c..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/scientific-notation-string.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should add string scientific notation with number", - "expression": ["plus", "1e2", 50], - "expectsFailure": "Expected number, got value \"1e2\"" -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json deleted file mode 100644 index 80a195e06f..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-large-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very large numbers", - "expression": ["plus", 9007199254740991, 1], - "expects": 9007199254740992 -} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json deleted file mode 100644 index 7ea180d925..0000000000 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/very-small-numbers.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Should handle very small numbers", - "expression": ["plus", 0.0000001, 0.0000002], - "expects": 0.0000003 -} From 362899eb290d45546ae6e2cab7cfe4b397511367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Wed, 11 Feb 2026 16:46:20 +0100 Subject: [PATCH 21/24] Reverted change to ExpressionValue --- .../Internal/Expressions/ExpressionValue.cs | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 374180685a..225e0a31b3 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -15,8 +15,8 @@ namespace Altinn.App.Core.Internal.Expressions; { private readonly string? _stringValue = null; - // decimal is a value type where nullable takes extra space, and we only read it when it should be set - private readonly decimal _numberValue = 0; + // double is a value type where nullable takes extra space, and we only read it when it should be set + private readonly double _numberValue = 0; // private readonly Dictionary? _objectValue = null; // private readonly ExpressionValue[]? _arrayValue = null; @@ -64,7 +64,7 @@ private ExpressionValue(bool? value) } } - private ExpressionValue(decimal? value) + private ExpressionValue(double? value) { if (value.HasValue) { @@ -101,9 +101,9 @@ private ExpressionValue(string? value) public static implicit operator ExpressionValue(bool? value) => new(value); /// - /// Convert a nullable decimal to ExpressionValue + /// Convert a nullable double to ExpressionValue /// - public static implicit operator ExpressionValue(decimal? value) => new(value); + public static implicit operator ExpressionValue(double? value) => new(value); /// /// Convert a nullable string to ExpressionValue @@ -131,8 +131,8 @@ public static ExpressionValue FromObject(object? value) null => Null, bool boolValue => boolValue, string stringValue => stringValue, - float numberValue => ValidateAndCastFloatingPoint(numberValue), // expressions uses decimal which needs an explicit cast - double numberValue => ValidateAndCastFloatingPoint(numberValue), // expressions uses decimal which needs an explicit cast + float numberValue => numberValue, + double numberValue => numberValue, byte numberValue => numberValue, sbyte numberValue => numberValue, short numberValue => numberValue, @@ -141,7 +141,7 @@ public static ExpressionValue FromObject(object? value) uint numberValue => numberValue, long numberValue => numberValue, ulong numberValue => numberValue, - decimal numberValue => numberValue, + decimal numberValue => (double?)numberValue, // expressions uses double which needs an explicit cast DateTime dateTimeValue => JsonSerializer .Serialize(dateTimeValue, _unsafeSerializerOptionsForSerializingDates) .Trim( @@ -227,7 +227,7 @@ public static ExpressionValue FromObject(object? value) /// /// Get the value as a number (or throw if it isn't a number ValueKind) /// - public decimal Number => + public double Number => ValueKind switch { JsonValueKind.Number => _numberValue, @@ -587,23 +587,6 @@ private static bool IsSupportedNumericType(Type type) || type == typeof(ushort) || type == typeof(sbyte); } - - private static decimal? ValidateAndCastFloatingPoint(double value) - { - if ( - double.IsNaN(value) - || double.IsInfinity(value) - || value > (double)decimal.MaxValue - || value < (double)decimal.MinValue - ) - { - throw new ExpressionEvaluatorTypeErrorException( - $"Cannot convert non-finite or out-of-range number to decimal: {value}" - ); - } - - return (decimal?)value; - } } /// @@ -619,7 +602,7 @@ public override ExpressionValue Read(ref Utf8JsonReader reader, Type typeToConve JsonTokenType.True => true, JsonTokenType.False => false, JsonTokenType.String => reader.GetString(), - JsonTokenType.Number => reader.GetDecimal(), + JsonTokenType.Number => reader.GetDouble(), JsonTokenType.Null => ExpressionValue.Null, // JsonTokenType.StartObject => ReadObject(ref reader), // JsonTokenType.StartArray => ReadArray(ref reader), From 200b432590839bed96976926fa0f60cee5689ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Thu, 12 Feb 2026 09:31:22 +0100 Subject: [PATCH 22/24] Fixes --- .../Expressions/ExpressionEvaluator.cs | 20 +++++++++---------- .../ExpressionValueTests.cs | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 23b236ec99..1ff690d361 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -614,8 +614,8 @@ private static int StringLength(ExpressionValue[] args) throw new ExpressionEvaluatorTypeErrorException($"Expected 2-3 arguments, got {args.Length}"); } string? subject = args[0].ToStringForEquals(); - decimal? start = PrepareNumericArg(args[1]); - decimal? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; + double? start = PrepareNumericArg(args[1]); + double? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; bool hasEnd = args.Length == 3; if (start == null || (hasEnd && end == null)) @@ -810,7 +810,7 @@ ExpressionValue[] args return !PrepareBooleanArg(args[0]); } - private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) + private static (double?, double?) PrepareNumericArgs(ExpressionValue[] args) { if (args.Length != 2) { @@ -824,7 +824,7 @@ private static (decimal?, decimal?) PrepareNumericArgs(ExpressionValue[] args) return (a, b); } - private static decimal? PrepareNumericArg(ExpressionValue arg) + private static double? PrepareNumericArg(ExpressionValue arg) { return arg.ValueKind switch { @@ -865,9 +865,9 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) ); } - internal static decimal? ParseNumber(string s, bool throwException = true) + internal static double? ParseNumber(string s, bool throwException = true) { - if (NumberRegex().IsMatch(s) && decimal.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) + if (NumberRegex().IsMatch(s) && double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) { return d; } @@ -890,25 +890,25 @@ private static bool LessThan(ExpressionValue[] args) return a < b; // Actual implementation } - private static decimal? Plus(ExpressionValue[] args) + private static double? Plus(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); return a + b; } - private static decimal? Minus(ExpressionValue[] args) + private static double? Minus(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); return a - b; } - private static decimal? Multiply(ExpressionValue[] args) + private static double? Multiply(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); return a * b; } - private static decimal? Divide(ExpressionValue[] args) + private static double? Divide(ExpressionValue[] args) { var (a, b) = PrepareNumericArgs(args); if (a != null && b == 0) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 3b5e98d495..6e8168d328 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -57,15 +57,15 @@ public void TestString() [Fact] public void TestDecimal() { - decimal decimalValue = 123.456m; - ExpressionValue value = decimalValue; - Assert.Equal(decimalValue, value.ToObject()); - Assert.Equal(decimalValue, value.Number); + double doubleValue = 123.456; + ExpressionValue value = doubleValue; + Assert.Equal(doubleValue, value.ToObject()); + Assert.Equal(doubleValue, value.Number); - value = ExpressionValue.FromObject(decimalValue); - Assert.Equal(decimalValue, value.ToObject()); + value = ExpressionValue.FromObject(doubleValue); + Assert.Equal(doubleValue, value.ToObject()); - Assert.Equal(decimalValue.ToString(CultureInfo.InvariantCulture), value.ToString()); + Assert.Equal(doubleValue.ToString(CultureInfo.InvariantCulture), value.ToString()); Assert.Throws(() => value.GetHashCode()); // Assert.Equal(decimalValue.GetHashCode(), value.GetHashCode()); } @@ -259,7 +259,7 @@ public void TestObjectsFail() public void TestTryDeserializeVariousTypes() { TestTryDeserialize(2, 2.0, true); - TestTryDeserialize(2.5m, 2.5, true); + TestTryDeserialize(2.5, 2.5, true); TestTryDeserialize("test", "test", true); TestTryDeserialize(true, true, true); TestTryDeserialize(false, false, true); From 5258676c5c495bec2a1154902e022efbc74fb009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Fri, 13 Feb 2026 16:30:51 +0100 Subject: [PATCH 23/24] Improved support for unit tests nested in testCases in shared json test files. Only convert to decimal when doing arithmetic operations. --- .../Expressions/ExpressionEvaluator.cs | 113 ++++++++++++++---- .../Internal/Expressions/ExpressionValue.cs | 4 +- .../Models/Expressions/ExpressionConverter.cs | 4 +- .../CommonTests/ExpressionTestCaseRoot.cs | 10 ++ .../CommonTests/TestFunctions.cs | 44 ++++--- .../shared-tests/functions/divide/divide.json | 20 ++++ .../shared-tests/functions/minus/minus.json | 22 +++- .../functions/multiply/multiply.json | 20 ++++ .../shared-tests/functions/plus/plus.json | 22 +++- .../ExpressionEvaluatorTests/EqualsTests.cs | 4 +- .../ExpressionValueTests.cs | 31 ----- ...ouldNotChange_Unintentionally.verified.txt | 4 +- .../TestUtils/FileNamesInFolderAttribute.cs | 23 +--- .../TestUtils/TestAttributeHelper.cs | 26 ++++ .../TestUtils/TestCasesAttribute.cs | 38 ++++++ 15 files changed, 283 insertions(+), 102 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/TestUtils/TestAttributeHelper.cs create mode 100644 test/Altinn.App.Core.Tests/TestUtils/TestCasesAttribute.cs diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index 1ff690d361..73c4a478db 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Globalization; +using System.Numerics; using System.Text.Json; using System.Text.RegularExpressions; using Altinn.App.Core.Models; @@ -614,8 +615,8 @@ private static int StringLength(ExpressionValue[] args) throw new ExpressionEvaluatorTypeErrorException($"Expected 2-3 arguments, got {args.Length}"); } string? subject = args[0].ToStringForEquals(); - double? start = PrepareNumericArg(args[1]); - double? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; + double? start = PrepareNumericArg(args[1]); + double? end = args.Length == 3 ? PrepareNumericArg(args[2]) : null; bool hasEnd = args.Length == 3; if (start == null || (hasEnd && end == null)) @@ -663,13 +664,13 @@ private static string Round(ExpressionValue[] args) ); } - var number = PrepareNumericArg(args[0]) ?? 0; + var number = PrepareNumericArg(args[0]) ?? 0; int precision = 0; if (args.Length == 2) { - precision = (int)(PrepareNumericArg(args[1]) ?? 0); + precision = (int)(PrepareNumericArg(args[1]) ?? 0); } return number.ToString($"N{precision}", CultureInfo.InvariantCulture); @@ -810,33 +811,51 @@ ExpressionValue[] args return !PrepareBooleanArg(args[0]); } - private static (double?, double?) PrepareNumericArgs(ExpressionValue[] args) + private static (T?, T?) PrepareNumericArgs(ExpressionValue[] args) + where T : struct, INumber { if (args.Length != 2) { throw new ExpressionEvaluatorTypeErrorException("Invalid number of args"); } - var a = PrepareNumericArg(args[0]); + var a = PrepareNumericArg(args[0]); - var b = PrepareNumericArg(args[1]); + var b = PrepareNumericArg(args[1]); return (a, b); } - private static double? PrepareNumericArg(ExpressionValue arg) + private static T? PrepareNumericArg(ExpressionValue arg) + where T : struct, INumber { return arg.ValueKind switch { JsonValueKind.True or JsonValueKind.False or JsonValueKind.Array or JsonValueKind.Object => throw new ExpressionEvaluatorTypeErrorException($"Expected number, got value {arg}"), - JsonValueKind.String => ParseNumber(arg.String, throwException: true), - JsonValueKind.Number => arg.Number, + JsonValueKind.String => ParseNumber(arg.String, throwException: true), + JsonValueKind.Number => CastNumber(arg.Number), _ => null, }; } + private static T? CastNumber(double? number) + where T : struct, INumber + { + if (typeof(T) != typeof(decimal)) + { + return number.HasValue ? T.CreateChecked(number.Value) : null; + } + + if (number.HasValue && ValidFloatingPoint(number.Value)) + { + return T.CreateChecked(number.Value); + } + + return null; + } + private static ExpressionValue IfImpl(ExpressionValue[] args) { if (args.Length == 2) @@ -865,9 +884,13 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) ); } - internal static double? ParseNumber(string s, bool throwException = true) + /// + /// Parses a number from a string representation. + /// + internal static T? ParseNumber(string s, bool throwException = true) + where T : struct, INumber { - if (NumberRegex().IsMatch(s) && double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) + if (NumberRegex().IsMatch(s) && T.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var d)) { return d; } @@ -881,7 +904,7 @@ private static ExpressionValue IfImpl(ExpressionValue[] args) private static bool LessThan(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -892,35 +915,35 @@ private static bool LessThan(ExpressionValue[] args) private static double? Plus(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); - return a + b; + var (a, b) = PrepareNumericArgs(args); + return PerformArithmetic(a, b, (x, y) => x + y); } private static double? Minus(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); - return a - b; + var (a, b) = PrepareNumericArgs(args); + return PerformArithmetic(a, b, (x, y) => x - y); } private static double? Multiply(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); - return a * b; + var (a, b) = PrepareNumericArgs(args); + return PerformArithmetic(a, b, (x, y) => x * y); } private static double? Divide(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a != null && b == 0) { throw new ExpressionEvaluatorTypeErrorException("The second argument is 0, cannot divide by 0"); } - return a / b; + return PerformArithmetic(a, b, (x, y) => x / y); } private static bool LessThanEq(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -931,7 +954,7 @@ private static bool LessThanEq(ExpressionValue[] args) private static bool GreaterThan(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -942,7 +965,7 @@ private static bool GreaterThan(ExpressionValue[] args) private static bool GreaterThanEq(ExpressionValue[] args) { - var (a, b) = PrepareNumericArgs(args); + var (a, b) = PrepareNumericArgs(args); if (a is null || b is null) { @@ -973,7 +996,7 @@ private static ExpressionValue Argv(ExpressionValue[] args, ExpressionValue[]? p throw new ExpressionEvaluatorTypeErrorException($"Expected 1 argument(s), got {args.Length}"); } - var index = (int?)PrepareNumericArg(args[0]); + var index = (int?)PrepareNumericArg(args[0]); if (!index.HasValue) { throw new ExpressionEvaluatorTypeErrorException($"Expected number, got value \"{args[0]}\""); @@ -991,6 +1014,46 @@ private static ExpressionValue Argv(ExpressionValue[] args, ExpressionValue[]? p return positionalArguments[index.Value]; } + /// + /// Performs arithmetic operation using decimal precision to avoid floating point precision issues. + /// Converts doubles to decimal, performs the operation, and converts back to double. + /// + /// First operand + /// Second operand + /// Function that performs the arithmetic operation on two decimals + /// Result of the operation as double, or null if any operand is null + private static double? PerformArithmetic( + decimal? aDecimal, + decimal? bDecimal, + Func operation + ) + { + if (aDecimal.HasValue is false || bDecimal.HasValue is false) + { + return null; + } + + var result = operation(aDecimal.Value, bDecimal.Value); + + return (double)result; + } + + private static bool ValidFloatingPoint(double value) + { + if ( + double.IsNaN(value) + || double.IsInfinity(value) + || value > (double)decimal.MaxValue + || value < (double)decimal.MinValue + ) + { + throw new ExpressionEvaluatorTypeErrorException( + $"Cannot convert non-finite or out-of-range number to decimal: {value}" + ); + } + return true; + } + [GeneratedRegex(@"^-?\d+(\.\d+)?$")] private static partial Regex NumberRegex(); } diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs index 225e0a31b3..ce5e9b0fa0 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionValue.cs @@ -420,7 +420,7 @@ public override int GetHashCode() "0" => false, { } sValue when sValue.Equals("true", StringComparison.OrdinalIgnoreCase) => true, { } sValue when sValue.Equals("false", StringComparison.OrdinalIgnoreCase) => false, - _ => ExpressionEvaluator.ParseNumber(String, throwException: false) switch + _ => ExpressionEvaluator.ParseNumber(String, throwException: false) switch { 1 => true, 0 => false, @@ -523,7 +523,7 @@ public bool TryDeserialize(Type type, out object? result) // Support parsing numbers from strings for numeric types case JsonValueKind.String when IsSupportedNumericType(underlyingType): { - var parsedNumber = ExpressionEvaluator.ParseNumber(String, throwException: false); + var parsedNumber = ExpressionEvaluator.ParseNumber(String, throwException: false); if (parsedNumber.HasValue) { result = Convert.ChangeType(parsedNumber.Value, underlyingType, CultureInfo.InvariantCulture); diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs index 477b2178d2..3095ad950b 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionConverter.cs @@ -27,7 +27,7 @@ public static Expression ReadStatic(JsonElement element) => JsonValueKind.True => new Expression(true), JsonValueKind.False => new Expression(false), JsonValueKind.String => new Expression(element.GetString()), - JsonValueKind.Number => new Expression(element.GetDecimal()), + JsonValueKind.Number => new Expression(element.GetDouble()), JsonValueKind.Null => new Expression(ExpressionValue.Null), JsonValueKind.Array => ReadArray(element), JsonValueKind.Object => throw new JsonException("Invalid type \"object\""), @@ -44,7 +44,7 @@ public static Expression ReadStatic(ref Utf8JsonReader reader, JsonSerializerOpt JsonTokenType.True => new Expression(true), JsonTokenType.False => new Expression(false), JsonTokenType.String => new Expression(reader.GetString()), - JsonTokenType.Number => new Expression(reader.GetDecimal()), + JsonTokenType.Number => new Expression(reader.GetDouble()), JsonTokenType.Null => new Expression(ExpressionValue.Null), JsonTokenType.StartArray => ReadArray(ref reader, options), JsonTokenType.StartObject => throw new JsonException("Invalid type \"object\""), diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs index 54d22f29e8..9086f68c83 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs @@ -10,6 +10,16 @@ namespace Altinn.App.Core.Tests.LayoutExpressions.CommonTests; public class ExpressionTestCaseRoot { + public ExpressionTestCaseRoot(TestCaseItem testCaseItem) + { + Name = testCaseItem.Name; + Expression = testCaseItem.Expression; + Expects = testCaseItem.Expects; + ExpectsFailure = testCaseItem.ExpectsFailure; + } + + public ExpressionTestCaseRoot() { } + [JsonIgnore] public string? Filename { get; set; } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index a24db29e73..59fac88461 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -204,20 +204,24 @@ public TestFunctions(ITestOutputHelper output) public async Task StringLength_Theory(string testName, string folder) => await RunTestCase(testName, folder); [Theory] - [SharedTest("plus")] - public async Task Plus_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [SharedTestCases("plus")] + public async Task Plus_Theory(string testName, ExpressionTestCaseRoot.TestCaseItem testCaseItem) => + await RunTestCase(testName, new ExpressionTestCaseRoot(testCaseItem)); [Theory] - [SharedTest("minus")] - public async Task Minus_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [SharedTestCases("minus")] + public async Task Minus_Theory(string testName, ExpressionTestCaseRoot.TestCaseItem testCaseItem) => + await RunTestCase(testName, new ExpressionTestCaseRoot(testCaseItem)); [Theory] - [SharedTest("multiply")] - public async Task Multiply_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [SharedTestCases("multiply")] + public async Task Multiply_Theory(string testName, ExpressionTestCaseRoot.TestCaseItem testCaseItem) => + await RunTestCase(testName, new ExpressionTestCaseRoot(testCaseItem)); [Theory] - [SharedTest("divide")] - public async Task Divide_Theory(string testName, string folder) => await RunTestCase(testName, folder); + [SharedTestCases("divide")] + public async Task Divide_Theory(string testName, ExpressionTestCaseRoot.TestCaseItem testCaseItem) => + await RunTestCase(testName, new ExpressionTestCaseRoot(testCaseItem)); [Theory] [SharedTest("round")] @@ -253,10 +257,15 @@ private static async Task LoadTestCase(string file, stri private async Task RunTestCase(string testName, string folder) { var test = await LoadTestCase(testName, folder); - _output.WriteLine(test.Name); + await RunTestCase(testName, test); + } + + private async Task RunTestCase(string testName, ExpressionTestCaseRoot test) + { + _output.WriteLine(testName); _output.WriteLine($"{test.Folder}{Path.DirectorySeparatorChar}{test.Filename}"); - _output.WriteLine(test.RawJson); - _output.WriteLine(test.FullPath); + _output.WriteLine(test.RawJson ?? ""); + _output.WriteLine(test.FullPath ?? ""); IInstanceDataAccessor dataAccessor; List dataTypes = new(); @@ -288,7 +297,7 @@ private async Task RunTestCase(string testName, string folder) e.ValueKind switch { JsonValueKind.String => e.GetString(), - JsonValueKind.Number => e.GetDecimal(), + JsonValueKind.Number => e.GetDouble(), JsonValueKind.True => true, JsonValueKind.False => false, JsonValueKind.Null => null, @@ -451,7 +460,7 @@ private async Task RunTestCaseItem( Assert.Null(result); break; case JsonValueKind.Number: - Assert.Equal(test.Expects.GetDecimal(), result); + Assert.Equal(test.Expects.GetDouble(), result); break; case JsonValueKind.Undefined: @@ -477,7 +486,10 @@ public void Ensure_tests_For_All_Folders() var testMethods = this.GetType() .GetMethods() .Select(m => - m.CustomAttributes.FirstOrDefault(ca => ca.AttributeType == typeof(SharedTestAttribute)) + m.CustomAttributes.FirstOrDefault(ca => + ca.AttributeType == typeof(SharedTestAttribute) + || ca.AttributeType == typeof(SharedTestCasesAttribute) + ) ?.ConstructorArguments.FirstOrDefault() .Value ) @@ -493,3 +505,7 @@ public class SharedTestAttribute(string folder) : FileNamesInFolderDataAttribute( Path.Join("LayoutExpressions", "CommonTests", "shared-tests", "functions", folder) ) { } + +// Can be used when you only want to run the tests listed in the testCases array in the json file +public class SharedTestCasesAttribute(string folder) + : TestCasesAttribute(Path.Join("LayoutExpressions", "CommonTests", "shared-tests", "functions", folder)) { } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json index 23200bb6dd..83f4f37025 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/divide/divide.json @@ -125,6 +125,26 @@ "name": "Should fail with [boolean, integer]", "expression": ["divide", true, 100], "expectsFailure": "Expected number, got value true" + }, + { + "name": "Should throw exception when any argument is double max value", + "expression": ["divide", 0, 1.7976931348623157E+308], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is double min value", + "expression": ["divide", -1.7976931348623157E+308, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float max value", + "expression": ["divide", 3.4028235E+38, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float min value", + "expression": ["divide", 0, -3.402823e+38], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" } ] } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json index ffd9cd501c..86a92d9c68 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/minus/minus.json @@ -89,7 +89,7 @@ { "name": "Should handle very large numbers", "expression": ["minus", 9007199254740992, 1], - "expects": 9007199254740991 + "expects": 9007199254740989 }, { "name": "Should handle very small numbers", @@ -115,6 +115,26 @@ "name": "Should subtract negative from positive decimal", "expression": ["minus", 50.55, -30.77], "expects": 81.32 + }, + { + "name": "Should throw exception when any argument is double max value", + "expression": ["minus", 0, 1.7976931348623157E+308], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is double min value", + "expression": ["minus", -1.7976931348623157E+308, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float max value", + "expression": ["minus", 3.4028235E+38, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float min value", + "expression": ["minus", 0, -3.402823e+38], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" } ] } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json index eed78c01ce..ca3b0794ff 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/multiply/multiply.json @@ -115,6 +115,26 @@ "name": "Should multiply negative and positive decimal numbers", "expression": ["multiply", -5.55, 6.66], "expects": -36.963 + }, + { + "name": "Should throw exception when any argument is double max value", + "expression": ["multiply", 0, 1.7976931348623157E+308], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is double min value", + "expression": ["multiply", -1.7976931348623157E+308, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float max value", + "expression": ["multiply", 3.4028235E+38, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float min value", + "expression": ["multiply", 0, -3.402823e+38], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" } ] } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json index 0f646f5ee3..21d32e9005 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/plus/plus.json @@ -79,7 +79,7 @@ { "name": "Should handle very large numbers", "expression": ["plus", 9007199254740991, 1], - "expects": 9007199254740992 + "expects": 9007199254740991 }, { "name": "Should handle very small numbers", @@ -105,6 +105,26 @@ "name": "Should add negative and positive decimal numbers", "expression": ["plus", 50.55, -30.66], "expects": 19.89 + }, + { + "name": "Should throw exception when any argument is double max value", + "expression": ["plus", 0, 1.7976931348623157E+308], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is double min value", + "expression": ["plus", -1.7976931348623157E+308, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float max value", + "expression": ["plus", 3.4028235E+38, 0], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" + }, + { + "name": "Should throw exception when any argument is float min value", + "expression": ["plus", 0, -3.402823e+38], + "expectsFailure": "Cannot convert non-finite or out-of-range number to decimal:" } ] } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs index 9122e60f29..938eb0373d 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/EqualsTests.cs @@ -54,8 +54,8 @@ public static TheoryData GetNumericTestData(double value) (ulong)uint.MaxValue + 1, (decimal)int.MaxValue + 1, (decimal)uint.MaxValue + 1, - (decimal)long.MaxValue + 1, - (decimal)ulong.MaxValue + 1, + (double)((decimal)long.MaxValue + 1), + (double)((decimal)ulong.MaxValue + 1), }; [Theory] diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index 6e8168d328..a5d3708e9f 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -70,37 +70,6 @@ public void TestDecimal() // Assert.Equal(decimalValue.GetHashCode(), value.GetHashCode()); } - [Theory] - [InlineData(double.MaxValue)] - [InlineData(float.MaxValue)] - [InlineData(double.MinValue)] - [InlineData(float.MinValue)] - public void FromObject_FloatingPointMaxAndMinValue_ThrowsExpressionEvaluatorTypeErrorException(object obj) - { - var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); - Assert.Contains("Cannot convert non-finite or out-of-range number to decimal: ", exception.Message); - } - - [Theory] - [InlineData(Double.NaN)] - [InlineData(Single.NaN)] - public void FromObject_FloatingPointNan_ThrowsExpressionEvaluatorTypeErrorException(object obj) - { - var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); - Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); - } - - [Theory] - [InlineData(Double.NegativeInfinity)] - [InlineData(Double.PositiveInfinity)] - [InlineData(Single.NegativeInfinity)] - [InlineData(Single.PositiveInfinity)] - public void FromObject_FloatingPointInfinite_ThrowsExpressionEvaluatorTypeErrorException(object obj) - { - var exception = Assert.Throws(() => ExpressionValue.FromObject(obj)); - Assert.Equal($"Cannot convert non-finite or out-of-range number to decimal: {obj}", exception.Message); - } - [Theory] [InlineData(true)] [InlineData(false)] diff --git a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt index a0771c2076..ac60716416 100644 --- a/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt +++ b/test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt @@ -3122,7 +3122,7 @@ namespace Altinn.App.Core.Internal.Expressions { public ExpressionValue() { } public bool Bool { get; } - public decimal Number { get; } + public double Number { get; } public string String { get; } public System.Text.Json.JsonValueKind ValueKind { get; } public static Altinn.App.Core.Internal.Expressions.ExpressionValue False { get; } @@ -3141,7 +3141,7 @@ namespace Altinn.App.Core.Internal.Expressions public bool TryDeserialize(out T? result) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue FromObject(object? value) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(bool? value) { } - public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(decimal? value) { } + public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(double? value) { } public static Altinn.App.Core.Internal.Expressions.ExpressionValue op_Implicit(string? value) { } public static bool operator !=(Altinn.App.Core.Internal.Expressions.ExpressionValue left, Altinn.App.Core.Internal.Expressions.ExpressionValue right) { } public static bool operator ==(Altinn.App.Core.Internal.Expressions.ExpressionValue left, Altinn.App.Core.Internal.Expressions.ExpressionValue right) { } diff --git a/test/Altinn.App.Core.Tests/TestUtils/FileNamesInFolderAttribute.cs b/test/Altinn.App.Core.Tests/TestUtils/FileNamesInFolderAttribute.cs index d7009ccab8..cb1ff3166f 100644 --- a/test/Altinn.App.Core.Tests/TestUtils/FileNamesInFolderAttribute.cs +++ b/test/Altinn.App.Core.Tests/TestUtils/FileNamesInFolderAttribute.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using Xunit.Sdk; namespace Altinn.App.Core.Tests.TestUtils; @@ -11,7 +10,7 @@ public FileNamesInFolderDataAttribute(string[] folderParts) public override IEnumerable GetData(MethodInfo testMethod) { - var basePath = AltinnAppTestsBasePath(); + var basePath = TestAttributeHelper.AltinnAppTestsBasePath(); var folder = Path.Join(basePath, folderName); if (!Directory.Exists(folder)) { @@ -27,24 +26,4 @@ public override IEnumerable GetData(MethodInfo testMethod) } ); } - - private static string AltinnAppTestsBasePath([CallerFilePath] string? callerFilePath = null) - { - if (callerFilePath is null) - { - throw new Exception("Caller path is null"); - } - var testUtilsDirectoryPath = Path.GetDirectoryName(callerFilePath); - if (testUtilsDirectoryPath is null) - { - throw new Exception("Caller path is null"); - } - var callerDirectoryPath = Path.GetDirectoryName(testUtilsDirectoryPath); - if (callerDirectoryPath is null) - { - throw new Exception("Caller path is null"); - } - - return callerDirectoryPath; - } } diff --git a/test/Altinn.App.Core.Tests/TestUtils/TestAttributeHelper.cs b/test/Altinn.App.Core.Tests/TestUtils/TestAttributeHelper.cs new file mode 100644 index 0000000000..27de2819c3 --- /dev/null +++ b/test/Altinn.App.Core.Tests/TestUtils/TestAttributeHelper.cs @@ -0,0 +1,26 @@ +using System.Runtime.CompilerServices; + +namespace Altinn.App.Core.Tests.TestUtils; + +public static class TestAttributeHelper +{ + public static string AltinnAppTestsBasePath([CallerFilePath] string? callerFilePath = null) + { + if (callerFilePath is null) + { + throw new Exception("Caller path is null"); + } + var testUtilsDirectoryPath = Path.GetDirectoryName(callerFilePath); + if (testUtilsDirectoryPath is null) + { + throw new Exception("Caller path is null"); + } + var callerDirectoryPath = Path.GetDirectoryName(testUtilsDirectoryPath); + if (callerDirectoryPath is null) + { + throw new Exception("Caller path is null"); + } + + return callerDirectoryPath; + } +} diff --git a/test/Altinn.App.Core.Tests/TestUtils/TestCasesAttribute.cs b/test/Altinn.App.Core.Tests/TestUtils/TestCasesAttribute.cs new file mode 100644 index 0000000000..8fb329e0cf --- /dev/null +++ b/test/Altinn.App.Core.Tests/TestUtils/TestCasesAttribute.cs @@ -0,0 +1,38 @@ +using System.Reflection; +using System.Text.Json; +using Altinn.App.Core.Tests.LayoutExpressions.CommonTests; +using Xunit.Sdk; + +namespace Altinn.App.Core.Tests.TestUtils; + +public class TestCasesAttribute(string folderName) : DataAttribute +{ + private static readonly JsonSerializerOptions _jsonSerializerOptions = new() + { + ReadCommentHandling = JsonCommentHandling.Skip, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + }; + + public override IEnumerable GetData(MethodInfo testMethod) + { + var basePath = TestAttributeHelper.AltinnAppTestsBasePath(); + var folder = Path.Join(basePath, folderName); + if (!Directory.Exists(folder)) + { + throw new DirectoryNotFoundException($"Folder not found: {folder}"); + } + var files = Directory.GetFiles(folder); + var theoryData = new List(); + foreach (var file in files) + { + var data = File.ReadAllText(file); + var rootCases = JsonSerializer.Deserialize(data, _jsonSerializerOptions)!; + if (rootCases.TestCases is not null) + { + theoryData.AddRange(rootCases.TestCases); + } + } + + return theoryData.Select(x => new object[] { x.Name ?? string.Empty, x }); + } +} From 597fcaf2505f7fde69ebe1302677448f79120e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rlie?= Date: Fri, 13 Feb 2026 17:11:46 +0100 Subject: [PATCH 24/24] Reverted change making expression nullable in ExpressionTestCaseRoot --- .../CommonTests/ExpressionTestCaseRoot.cs | 2 +- .../TestBackendExclusiveFunctions.cs | 4 +-- .../CommonTests/TestFunctions.cs | 25 ++++++++----------- .../CommonTests/TestInvalid.cs | 6 +---- .../ExpressionValueTests.cs | 4 +-- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs index 9086f68c83..a45da8a56f 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/ExpressionTestCaseRoot.cs @@ -39,7 +39,7 @@ public ExpressionTestCaseRoot() { } public string? Name { get; set; } [JsonPropertyName("expression")] - public Expression? Expression { get; set; } + public Expression Expression { get; set; } [JsonPropertyName("context")] public ComponentContextForTestSpec? Context { get; set; } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs index 72aafdf502..7d2ddbfd8f 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestBackendExclusiveFunctions.cs @@ -91,7 +91,7 @@ private async Task RunTestCase(string testName, string folder) { await ExpressionEvaluator.EvaluateExpression( state, - test.Expression ?? new Expression(), + test.Expression, await test.GetContextOrNull(state) ); }; @@ -105,7 +105,7 @@ await test.GetContextOrNull(state) var result = await ExpressionEvaluator.EvaluateExpression( state, - test.Expression ?? new Expression(), + test.Expression, await test.GetContextOrNull(state)! ); diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 59fac88461..212b823635 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -382,20 +382,17 @@ private async Task RunTestCase(string testName, ExpressionTestCaseRoot test) test.ParsingException.Should().BeNull("Loading of test failed"); - if (test.Expression != null) - { - await RunTestCaseItem( - new ExpressionTestCaseRoot.TestCaseItem() - { - Expects = test.Expects, - Expression = test.Expression ?? new Expression(), - ExpectsFailure = test.ExpectsFailure, - }, - state, - context, - positionalArguments - ); - } + await RunTestCaseItem( + new ExpressionTestCaseRoot.TestCaseItem() + { + Expects = test.Expects, + Expression = test.Expression, + ExpectsFailure = test.ExpectsFailure, + }, + state, + context, + positionalArguments + ); if (test.TestCases != null) { diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs index 07a2e9270d..d8c47ca911 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestInvalid.cs @@ -54,11 +54,7 @@ public async Task Simple_Theory(string testName, string folder) test.FrontEndSettings ?? new() ); - await ExpressionEvaluator.EvaluateExpression( - state, - test.Expression ?? new Expression(), - await test.GetContextOrNull(state) - ); + await ExpressionEvaluator.EvaluateExpression(state, test.Expression, await test.GetContextOrNull(state)); }; (await act.Should().ThrowAsync()).WithMessage(testCase.ExpectsFailure + "*"); } diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs index a5d3708e9f..037d8f7ba4 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/ExpressionEvaluatorTests/ExpressionValueTests.cs @@ -55,7 +55,7 @@ public void TestString() } [Fact] - public void TestDecimal() + public void TestDouble() { double doubleValue = 123.456; ExpressionValue value = doubleValue; @@ -67,7 +67,7 @@ public void TestDecimal() Assert.Equal(doubleValue.ToString(CultureInfo.InvariantCulture), value.ToString()); Assert.Throws(() => value.GetHashCode()); - // Assert.Equal(decimalValue.GetHashCode(), value.GetHashCode()); + // Assert.Equal(doubleValue.GetHashCode(), value.GetHashCode()); } [Theory]