Example #1
0
        /// <summary>
        /// Writes the testing function for 'F' to 'm_defSB'.
        /// The generated function returns success (1) or failure (0).
        /// </summary>
        /// <returns>The list of name name of the int() function which tests the function.</returns>
        public override List <string> WriteTestFunction()
        {
            StringBuilder defSB = (m_specification.m_inlineFunctions) ? m_cgd.m_inlineDefSB : m_cgd.m_defSB;

            List <string> testFuncNames = new List <string>();


            foreach (string floatName in m_fgs.FloatNames)
            {
                FloatType FT = m_specification.GetFloatType(floatName);

                string testFuncName = Util.GetTestingFunctionName(m_specification, m_cgd, m_funcName[FT.type]);

                if (m_gmvFunc) // GMV test
                {
                    testFuncNames.Add(testFuncName);
                    m_cgd.m_cog.EmitTemplate(defSB, "testEqualsGMV",
                                             "S=", m_specification,
                                             "FT=", FT,
                                             "gmvName=", FT.GetMangledName(m_specification, m_specification.m_GMV.Name),
                                             "testFuncName=", testFuncName,
                                             "targetFuncName=", m_funcName[FT.type],
                                             "randomScalarFuncName=", m_randomScalarFuncName[FT.type],
                                             "randomGmvFuncName=", m_randomVersorFuncName[FT.type],
                                             "addGmvFuncName=", m_gmvAddFuncName[FT.type]
                                             );
                }
                else if ((m_smv1 != null) &&
                         (m_smv2 != null) &&
                         m_smv1.CanConvertToGmv(m_specification) &&
                         m_smv2.CanConvertToGmv(m_specification) &&
                         MV.CanConvertSumToGmv(m_specification, m_smv1, m_smv2))
                { // SMV test
                    testFuncNames.Add(testFuncName);
                    System.Collections.Hashtable argTable = new System.Collections.Hashtable();
                    argTable["S"]                    = m_specification;
                    argTable["FT"]                   = FT;
                    argTable["testFuncName"]         = testFuncName;
                    argTable["smv1"]                 = m_smv1;
                    argTable["smv2"]                 = m_smv2;
                    argTable["smv1Name"]             = FT.GetMangledName(m_specification, m_smv1.Name);
                    argTable["smv2Name"]             = FT.GetMangledName(m_specification, m_smv2.Name);
                    argTable["gmvName"]              = FT.GetMangledName(m_specification, m_specification.m_GMV.Name);
                    argTable["targetFuncName"]       = m_funcName[FT.type];
                    argTable["randomScalarFuncName"] = m_randomScalarFuncName[FT.type];
                    argTable["randomSmv1FuncName"]   = m_randomSmv1FuncName[FT.type];
                    argTable["randomSmv2FuncName"]   = m_randomSmv2FuncName[FT.type];
                    argTable["subtractGmvFuncName"]  = m_gmvSubtractFuncName[FT.type];

                    m_cgd.m_cog.EmitTemplate(defSB, "testEqualsSMV", argTable);
                }
            }

            return(testFuncNames);
        } // end of WriteTestFunction()