static void Main(string[] args) { try { // Get a file path. First from the command line args. // If no args are specified, ask the user for a path. var inputFilePath = Utilities.GetFileNameFromArgs(args) ?? Utilities.GetFileNameFromConsole(); if (inputFilePath == null) { // No file path was specified on either command // line args or by user so we wont do any more // work. We'll just allow the user to exit. ConsoleEx.DisplayMessage("No file was specified", ConsoleColor.Red); } else { using (Stream inputFileStream = Open(inputFilePath)) { // If inputFileStream is not null, user has // entered a valid file path. Let's proceed. // Other wise we'll just exit. if (inputFileStream != null) { var outputFilePath = Utilities.BuildOutputPath(inputFilePath); using (var outputStream = File.Create(outputFilePath)) { var triangleBuilder = new TriangleSetFactory(new StreamDataSource(inputFileStream)); var outputWriter = new OutputWriter(); outputWriter.WriteOutput(outputStream, triangleBuilder.Create()); } DisplayOutputDetails(outputFilePath); ConsoleEx.Prompt("Execution complete. Press any key to exit : ", ConsoleColor.Yellow); ConsoleEx.DisplayMessage("Closing", ConsoleColor.Green); } } } } catch (Exception ex) { ConsoleEx.DisplayMessage($"An error occured : {ex.Message}", ConsoleColor.Red); ConsoleEx.Prompt("Press any key to exit: ", ConsoleColor.Yellow); } }
public void Should_Calculate_Correct_Ealiest_OriginYear() { var inputData = new DataRow[] { new DataRow("Test Product 1", 1990, 1990, 1), new DataRow("Test Product 1", 1990, 1991, 2), new DataRow("Test Product 1", 1991, 1991, 1), new DataRow("Test Product 1", 1991, 1992, 2), new DataRow("Test Product 1", 1991, 1993, 3), }; var tsf = new TriangleSetFactory(); var result = tsf.Create(inputData); Assert.Equal(1990, result.EarliestOriginYear); }
public void Should_Calculate_Correct_Number_Of_dev_Years() { //Taking into account that some years might be missing if no claims. var inputData = new DataRow[] { new DataRow("Test Product 1", 1990, 1990, 1), new DataRow("Test Product 1", 1990, 1991, 2), new DataRow("Test Product 1", 1991, 1991, 1), new DataRow("Test Product 1", 1991, 1992, 2), new DataRow("Test Product 1", 1991, 1993, 3), }; var triangleSetBuilder = new TriangleSetFactory(); var result = triangleSetBuilder.Create(inputData); Assert.Equal(3, result.NumberOfDevelopmentYears); }
public void Should_Return_As_Many_Triangles_As_Products() { var inputData = new DataRow[] { new DataRow("Test Product 1", 1990, 1990, 2), new DataRow("Test Product 1", 1990, 1991, 3), new DataRow("Test Product 1", 1991, 1991, 1), new DataRow("Test Product 1", 1991, 1992, 9), new DataRow("Test Product 2", 1990, 1990, 2), new DataRow("Test Product 2", 1990, 1991, 3), new DataRow("Test Product 2", 1991, 1991, 1), new DataRow("Test Product 2", 1991, 1992, 9), }; var tsf = new TriangleSetFactory(); var result = tsf.Create(inputData); Assert.Equal(2, result.Triangles.Count()); }
public void Should_Calculate_Cummulative_Values() { //The last value of each origin year should equal the sum of all //incremental claims data for that year. var inputData = new DataRow[] { new DataRow("Test Product 1", 1990, 1990, 2), new DataRow("Test Product 1", 1990, 1991, 3), new DataRow("Test Product 1", 1990, 1992, 3), new DataRow("Test Product 1", 1991, 1991, 1), new DataRow("Test Product 1", 1991, 1992, 9), }; var tsf = new TriangleSetFactory(); var result = tsf.Create(inputData); Assert.Equal(8, result.Triangles.First().Matrix[1990].Last()); Assert.Equal(10, result.Triangles.First().Matrix[1991].Last()); }
public void Should_Include_All_Origin_Years_For_All_Products() { //Even if no claim data for the specified year has been included var inputData = new DataRow[] { new DataRow("Test Product 1", 1990, 1990, 2), new DataRow("Test Product 1", 1990, 1991, 3), new DataRow("Test Product 1", 1991, 1991, 1), new DataRow("Test Product 1", 1991, 1992, 9), new DataRow("Test Product 2", 1991, 1991, 1), new DataRow("Test Product 2", 1991, 1992, 9), }; var tsf = new TriangleSetFactory(); var result = tsf.Create(inputData); Assert.Equal(0, result.Triangles .Single(triangle => triangle.ProductName == "Test Product 2") .Matrix[1990] .Sum(y => y)); }