diff --git a/ifrs17/Import/ImportScopeCalculation.ipynb b/ifrs17/Import/ImportScopeCalculation.ipynb index 59184a84..097661f1 100644 --- a/ifrs17/Import/ImportScopeCalculation.ipynb +++ b/ifrs17/Import/ImportScopeCalculation.ipynb @@ -549,7 +549,7 @@ "\n{", "\n private double[] NominalClaimsCashflow => GetStorage().GetClaims()", "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))", - "\n .Aggregate();", + "\n .AggregateDoubleArray();", "\n ", "\n private double nonPerformanceRiskRate => GetStorage().GetNonPerformanceRiskRate(Identity.Id);", "\n ", @@ -566,7 +566,7 @@ "\n{", "\n double[] NominalCashflow.Values => GetStorage().GetClaims()", "\n .Select(claim => GetStorage().GetValues(Identity.Id with {AocType = referenceAocStep.AocType, Novelty = referenceAocStep.Novelty}, claim, Identity.EstimateType, Identity.AccidentYear))", - "\n .Aggregate();", + "\n .AggregateDoubleArray();", "\n}" ], "metadata": {}, @@ -691,7 +691,7 @@ "\n .Values", "\n .Select(aoc => GetScope((Identity.Id with {AocType = aoc.AocType, Novelty = aoc.Novelty}, Identity.AmountType, Identity.EstimateType, Identity.Accidentyear)).Values)", "\n .Where(cf => cf.Count() > 0)", - "\n .Aggregate();", + "\n .AggregateDoubleArray();", "\n ", "\n double[] Values => Subtract(CurrentValues, PreviousValues);", "\n}" diff --git a/ifrs17/Test/AggregateDoubleArrayTest.ipynb b/ifrs17/Test/AggregateDoubleArrayTest.ipynb new file mode 100644 index 00000000..6849995e --- /dev/null +++ b/ifrs17/Test/AggregateDoubleArrayTest.ipynb @@ -0,0 +1,131 @@ +{ + "metadata": { + "authors": [], + "kernelspec": { + "display_name": "Formula Framework", + "language": "C#", + "name": "C#" + }, + "language_info": { + "file_extension": ".cs", + "mimetype": "text/plain", + "name": "C#" + } + }, + "nbformat": 4, + "nbformat_minor": 5, + "cells": [ + { + "cell_type": "code", + "source": [ + "#!import \"../Utils/Extensions\"", + "\n#!import \"../Utils/TestHelper\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public void CheckAggregateDoubleArray(double[][] arrayOfDoubleArrays, double[] bmAggregatedArray)", + "\n{", + "\n var aggregatedArray = arrayOfDoubleArrays.AggregateDoubleArray();", + "\n aggregatedArray.Should().BeEquivalentTo(bmAggregatedArray);", + "\n}" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "var array = new double [] [] {new[] {-100d,-50d }, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,}, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,}, new[] {-100d,-50d,-50d,-50d,0d,0d,0d,0d, 0d,0d,} };", + "\nCheckAggregateDoubleArray(array, new[] {-400d,-200d,-150d,-150d,0d,0d,0d,0d, 0d,0d,})" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {null, new[] {-100d,-50d }};", + "\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {new[] {-100d,-50d }, null};", + "\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {Enumerable.Empty().ToArray(), new[] {-100d,-50d }};", + "\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {Enumerable.Empty().ToArray(), Enumerable.Empty().ToArray()};", + "\nCheckAggregateDoubleArray(array, Enumerable.Empty().ToArray())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {new[] {-100d,-50d }};", + "\nCheckAggregateDoubleArray(array, new[] {-100d,-50d })" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {Enumerable.Empty().ToArray()};", + "\nCheckAggregateDoubleArray(array, Enumerable.Empty().ToArray())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "array = new double [] [] {null};", + "\nCheckAggregateDoubleArray(array, Enumerable.Empty().ToArray())" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/ifrs17/Test/Tests.ipynb b/ifrs17/Test/Tests.ipynb index e2f0e955..ef37f404 100644 --- a/ifrs17/Test/Tests.ipynb +++ b/ifrs17/Test/Tests.ipynb @@ -41,6 +41,15 @@ "metadata": {}, "execution_count": 0, "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#!eval-notebook \"AggregateDoubleArrayTest\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] } ] } \ No newline at end of file diff --git a/ifrs17/Utils/Extensions.ipynb b/ifrs17/Utils/Extensions.ipynb index a403aeff..9e335a22 100644 --- a/ifrs17/Utils/Extensions.ipynb +++ b/ifrs17/Utils/Extensions.ipynb @@ -36,6 +36,33 @@ "execution_count": 0, "outputs": [] }, + { + "cell_type": "markdown", + "source": [ + "# Loading external dependencies" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#r \"nuget:morelinq\"" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "using static MoreLinq.Extensions.ZipLongestExtension;" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, { "cell_type": "markdown", "source": [ @@ -96,7 +123,16 @@ { "cell_type": "code", "source": [ - "public static double[] Prune (this IEnumerable source, double precision = Precision) => source.Reverse().SkipWhile(x => Math.Abs(x) < precision).Reverse().ToArray();" + "public static double[] Prune(this IEnumerable source, double precision = Precision) => source.Reverse().SkipWhile(x => Math.Abs(x) < precision).Reverse().ToArray();" + ], + "metadata": {}, + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "public static double[] AggregateDoubleArray(this IEnumerable> source) => source.Where(x => x is not null).DefaultIfEmpty(Enumerable.Empty()).Aggregate((x, y) => x.ZipLongest(y, (a, b) => a + b)).ToArray();" ], "metadata": {}, "execution_count": 0,