public void CrapMethodPercentIs0WhenThereIsNoCrapMethodData()
 {
     var crapSummary = new CrapStatsEntry(new List<CrapDataEntry>(), 2);
     Assert.AreEqual(0d, crapSummary.CalculateCrapMethodPercentage());
 }
 public void CrapMethodPercentIsCalculatedAsTheNumCrapMethodsOverNumMethods()
 {
     var crapSummary = new CrapStatsEntry(_crapMethodData, 2);
     Assert.AreEqual(66.666666666666657d, crapSummary.CalculateCrapMethodPercentage());
 }
        private XmlElement CreateStats(XmlDocument xmlDoc, CrapStatsEntry crapStatsEntry)
        {
            XmlElement stats = xmlDoc.CreateElement("stats");

            XmlElement elem = xmlDoc.CreateElement("name");
            var value = xmlDoc.CreateTextNode("name");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("totalCrap");
            value = xmlDoc.CreateTextNode(crapStatsEntry.CalculateTotalCrap().ToString("0.0"));
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("crap");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("median");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("average");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("stdDev");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("methodCount");
            value = xmlDoc.CreateTextNode(crapStatsEntry.CalculateTotalMethods().ToString());
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("crapMethodCount");
            value = xmlDoc.CreateTextNode(crapStatsEntry.CalculateTotalCrapMethods().ToString());
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("crapMethodPercent");
            value = xmlDoc.CreateTextNode(crapStatsEntry.CalculateCrapMethodPercentage().ToString("0.0"));
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("crapLoad");
            value = xmlDoc.CreateTextNode(crapStatsEntry.CalculateTotalCrapLoad().ToString("0"));
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("crapThreshold");
            value = xmlDoc.CreateTextNode(crapStatsEntry.Threshold.ToString());
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalAverage");
            value = xmlDoc.CreateTextNode("-1.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalCraploadAverage");
            value = xmlDoc.CreateTextNode("-1.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalCrapMethodAverage");
            value = xmlDoc.CreateTextNode("-1.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalTotalMethodAverage");
            value = xmlDoc.CreateTextNode("-1.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalAverageDiff");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalCraploadAverageDiff");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalCrapMethodAverageDiff");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("globalTotalMethodAverageDiff");
            value = xmlDoc.CreateTextNode("0.0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = xmlDoc.CreateElement("shareStatsUrl");
            value = xmlDoc.CreateTextNode("http://www.crap4j.org/benchmark/stats/new?stat[project_hash]=1290006074016&amp;stat[project_url]=test&amp;stat[crap]=50.00&amp;stat[crap_load]=5&amp;stat[crap_methods]=1&amp;stat[total_methods]=2&amp;stat[ones]=0&amp;stat[twos]=1&amp;stat[fours]=0&amp;stat[eights]=0&amp;stat[sixteens]=1&amp;stat[thirtytwos]=0&amp;stat[sixtyfours]=0&amp;stat[one28s]=0&amp;stat[two56s]=0");
            elem.AppendChild(value);
            stats.AppendChild(elem);

            elem = CreateHistogramElemnt(xmlDoc);
            stats.AppendChild(elem);

            return stats;
        }