예제 #1
0
        public void HDFM()
        {
            var testCases = new Dictionary <string, Dictionary <string, string> >();

            #region Get Testing Configurations
            using (StreamReader sr = new StreamReader("TestCases_FMExecution.txt"))
            {
                string str;
                Dictionary <string, string> testContent = null;

                while ((str = sr.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str) || str.StartsWith("//"))//Commenting
                    {
                        continue;
                    }
                    else if (str.StartsWith("[Test"))
                    {
                        testContent = new Dictionary <string, string>();
                        testCases.Add(str, testContent);
                    }
                    else if (null != testContent)
                    {
                        string[] pair = str.Replace(" ", string.Empty)
                                        .Split(new char[] { ':' }, 2);

                        testContent.Add(pair[0], pair[1]);
                    }
                }
            }
            #endregion

            #region === Construct NGFMPrototype & ProcessEvent() ===

            HDFM HDFM = new HDFM();

            #endregion

            int j = 1;

            foreach (var kv in testCases)
            {
                #region Get Expected Results

                var lossesPerSubPeril = ReadGULossFromFile(kv.Value["DR"]);

                PartitionData pData = RMS.Prototype.NGFM.Utilities.DeserializePartitionData(kv.Value["RITE"]);

                if (kv.Value.ContainsKey("CDL"))
                {
                    string cdl = ReadCDL(kv.Value["CDL"]);
                    foreach (var ce in pData.Exposures)
                    {
                        ce.Contract.CDLString = cdl;
                    }
                }

                string[] res            = kv.Value["RESULT"].Split(new char[] { ';', ',', ' ' });
                var      expectedResult = new Dictionary <long, double>();
                for (int i = 0; i < res.Length - 1; i += 2)
                {
                    long id = long.Parse(res[i]);
                    if (!expectedResult.ContainsKey(id))
                    {
                        expectedResult.Add(id, double.Parse(res[i + 1]));
                    }
                }

                #endregion

                #region === ProcessEvent() ===

                Stopwatch sw = Stopwatch.StartNew();

                HDFM.Prepare(pData);

                sw.Stop();

                //Debug.WriteLine("Prepare(" + kv.Key + ") took " + ElapsedNanoSeconds(sw) + " ns!");

                sw.Restart();

                var payOutDict = HDFM.ProcessEvent(0, lossesPerSubPeril, false, 1);

                sw.Stop();

                //Debug.WriteLine("Process(" + kv.Key + ") took " + ElapsedNanoSeconds(sw) + " ns!");

                Debug.WriteLine(j + "," + ElapsedNanoSeconds(sw));

                j++;

                #endregion

                #region Comparison

                foreach (long id in expectedResult.Keys)
                {
                    double actualResult = (payOutDict.ContainsKey(id)) ? payOutDict[id].PayOut : -1;
                    Assert.AreEqual(expectedResult[id], actualResult, 0.01, "Test \"{0}\" (ID={1}) is failed.", kv.Key, id);

                    //string r = expectedResult[id];
                    //int n = r.Length - 1 - r.IndexOf('.');

                    //double payOut = (payOutDict.ContainsKey(id)) ? payOutDict[id].PayOut : -1;

                    //double d = Math.Round(payOut, n);
                    //string actualResult = d.ToString();
                    //Assert.AreEqual(expectedResult[id], actualResult, "Test \"{0}\" (ID={1}) is failed.", kv.Key, id);
                }

                #endregion
            }
        }
예제 #2
0
 public HDFM_API()
 {
     _handleHDFM = new HDFM();
 }