Exemple #1
0
        public void Triangles_Should_Have_ProductName()
        {
            var productName = "TestProduct";
            var t           = new ClaimTriangle(productName, 1900, 1);

            Assert.Equal(productName, t.ProductName);
        }
Exemple #2
0
        /// <summary>
        /// Populates a precreated triangle with data from a set
        /// of incremental data.
        /// </summary>
        /// <param name="triangle">The initialised but empty triangle to populate</param>
        /// <param name="incrementalData">The data to insert into the triangle</param>
        /// <returns></returns>
        private ClaimTriangle PopulateTriangle(ClaimTriangle triangle, IEnumerable <DataRow> incrementalData)
        {
            if (triangle == null)
            {
                throw new ArgumentNullException(nameof(triangle));
            }
            if (incrementalData == null)
            {
                throw new ArgumentNullException(nameof(incrementalData));
            }


            for (int originYearIndex = 0; originYearIndex < triangle.DevelopmentYears; originYearIndex++)
            {
                var originYear = triangle.EarliestOriginYear + originYearIndex;

                for (int devYearIndex = 0; devYearIndex < triangle.DevelopmentYears - originYearIndex; devYearIndex++)
                {
                    var devYear = triangle.EarliestOriginYear + originYearIndex + devYearIndex;

                    var value = incrementalData
                                .Where(x => x.OriginYear == originYear && x.DevelopmentYear == devYear)
                                .Sum(x => x.IncrementalValue);

                    triangle.Matrix[originYear][devYearIndex] = value + (devYearIndex > 0 ? triangle.Matrix[originYear][devYearIndex - 1] : 0);
                }
            }

            return(triangle);
        }
Exemple #3
0
        public void ShouldAccumulateFullTriangle()
        {
            var expectedValues = new[] { "ProductA",
                                            "45.2", "110", "110",  "147",
                                                    "50",  "125",  "150",
                                                           "55",   "140",
                                                                   "100" };

            var triangle = new ClaimTriangle("ProductA", _collector);
            triangle[1990][1990] = 45.2;
            triangle[1990][1991] = 64.8;
            triangle[1990][1993] = 37;
            triangle[1991][1991] = 50;
            triangle[1991][1992] = 75;
            triangle[1991][1993] = 25;
            triangle[1992][1992] = 55;
            triangle[1992][1993] = 85;
            triangle[1993][1993] = 100;

            var actualValues = triangle.Accumulate().Flatten(new TriangleDimensions { OriginYear = 1990, DevelopmentYears = 4 });

            for (int i = 0; i < actualValues.Length; i++)
            {
                Assert.Equal(expectedValues[i], actualValues[i]);
            }
        }
Exemple #4
0
        public void Triangles_Should_Have_Same_Number_Of_Origin_And_Dev_YEars()
        {
            var developmentYears = 20;

            var t = new ClaimTriangle("TestProduct", 1900, developmentYears);

            Assert.Equal(t.Matrix.Keys.Count, t.Matrix[1900].Length);
        }
Exemple #5
0
        private List <ClaimTriangle> ToClaimSet(IGrouping <string, IncrementalClaimData> incrementalClaims)
        {
            var claimTriangles = new List <ClaimTriangle>();

            foreach (var data in incrementalClaims.OrderBy(x => x.OriginalYear).ThenBy(x => x.DevelopmentYear))
            {
                claimTriangles.Add(ClaimTriangle.Create(data.OriginalYear, data.DevelopmentYear, data.Increment));
            }

            return(claimTriangles);
        }
Exemple #6
0
        public void Triangles_Should_Have_Correct_Number_Of_Elements()
        {
            var developmentYears = 20;

            ClaimTriangle t = new ClaimTriangle("TestProduct", 1900, developmentYears);

            var numberOfElements = t.Matrix.Sum(year => year.Value.Length);

            var expectedNumberOfElements = (Math.Pow(developmentYears, 2) / 2) + developmentYears / 2;

            Assert.Equal(expectedNumberOfElements, numberOfElements);
        }
Exemple #7
0
        public void ShouldHandleMissingIncrementalValuesFrontEndOfTriangle()
        {
            var expectedValues = new[] {"ProductA",
                                            "0",  "0",  "0",   "0",
                                                  "0",  "0",   "0",
                                                        "110", "170",
                                                               "200"};

            var triangle = new ClaimTriangle("ProductA", _collector);
            triangle[1992][1992] = 110;
            triangle[1992][1993] = 170;
            triangle[1993][1993] = 200;

            var actualValues = triangle.Flatten(new TriangleDimensions{OriginYear = 1990, DevelopmentYears = 4});

            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.Equal(expectedValues[i], actualValues[i]);
            }
        }
Exemple #8
0
        public void ShouldAccumulateForSingleOriginBlock()
        {
            var expectedValues = new[] { "ProductA",
                                            "115", "213", "277", "330", "471",
                                                   "0",   "0",   "0",   "0",
                                                          "0",   "0",   "0",
                                                                 "0",   "0",
                                                                        "0"};

            var triangle = new ClaimTriangle("ProductA", _collector);
            triangle[1991][1991] = 115;
            triangle[1991][1992] = 98;
            triangle[1991][1993] = 64;
            triangle[1991][1994] = 53;
            triangle[1991][1995] = 141;

            var actualValues = triangle.Accumulate().Flatten(new TriangleDimensions { OriginYear = 1991, DevelopmentYears = 5 });

            for (int i = 0; i < actualValues.Length; i++)
            {
                Assert.Equal(expectedValues[i], actualValues[i]);
            }
        }