Ejemplo n.º 1
0
 public ConcurrentDictionary <long, ResultPosition> ProcessEvent_OLDAPI(int eventID,
                                                                        Dictionary <string, Dictionary <int, Dictionary <long, Tuple <double, uint, List <float> > > > > EventOccurrenceDRs,
                                                                        params long[] exposureIDs)
 {
     _handleNGFMPrototype.ProcessEvent_OLDNEWNEWAPI(eventID, EventOccurrenceDRs, exposureIDs);
     return(_handleNGFMPrototype.GetResultPositions(eventID, exposureIDs));
 }
Ejemplo n.º 2
0
        public void API_ExecuteFM()
        {
            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 ===

            NGFMPrototype ngfmPrototype = new NGFMPrototype();

            #endregion

            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() ===

                ngfmPrototype.Prepare(pData);

                // old API ----------------
                //var payOutDict = HDFM.ProcessEvent(EventOccurrenceDRs);
                //-------------------------

                // new new API ----------------
                int eventID = 0;
                ngfmPrototype.ProcessEvent_OLDNEWNEWAPI(eventID, lossesPerSubPeril);
                var payOutDict = ngfmPrototype.GetResultPositions(eventID, expectedResult.Keys.ToArray())
                                 .ToDictionary(p => p.Key, p => p.Value.PayOut);
                //-------------------------

                #endregion

                #region Comparison

                foreach (long id in expectedResult.Keys)
                {
                    double actualResult = (payOutDict.ContainsKey(id)) ? payOutDict[id] : -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] : -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
            }

            ngfmPrototype.Dispose();
        }