ABsoluteMaybe.Statistics.ABingoStyleFormatter.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString()
        {
            var retval = new StringBuilder();
            ABsoluteMaybeStatistics.ABsoluteMaybeStatisticsResult result;
            try
            {
                result = _statistics.Execute();
            }
            catch (ABsoluteMaybeException e)
            {
                return e.Message;
            }

            if (result.InsufficientSampleSize)
                retval.Append("Take these results with a grain of salt since your samples are so small: ");

            if (result.BestOption.ConversionRate == result.WorstOption.ConversionRate)
                retval.AppendFormat(
                    @"
                    Both options are currently converting at the same rate ({3}),
                    with [{0}] having {1} conversions from {2} participants.  ",
                     result.BestOption.Name,
                     result.BestOption.Conversions,
                     result.BestOption.Participants,
                     result.BestOption.ConversionRate.ToString("#0.##%")
                    );
            else
                retval.AppendFormat(
                    @"
                    The best option you have is: [{0}], which had
                    {1} conversions from {2} participants
                    ({3}).  The other option was [{4}],
                    which had {5} conversions from {6} participants
                    ({7}).  ",
                    result.BestOption.Name,
                    result.BestOption.Conversions,
                    result.BestOption.Participants,
                    result.BestOption.ConversionRate.ToString("#0.##%"),
                    result.WorstOption.Name,
                    result.WorstOption.Conversions,
                    result.WorstOption.Participants,
                    result.WorstOption.ConversionRate.ToString("#0.##%")
                    );

            if (result.ConfidenceLevel == 0)
                retval.Append("However, this difference is not statistically significant.");
            else
                retval.AppendFormat(
                    @"
                    This difference is <b>{0} likely to be statistically significant</b>, which means you can be
                    {1} that it is the result of your options actually mattering, rather than
                    being due to random chance.  However, this statistical test can't measure how likely the currently
                    observed magnitude of the difference is to be accurate or not.  It only says ""better"", not ""better
                    by so much"".  ",
                    result.ConfidenceLevel.ToString("#0.##%"),
                    Descriptions[result.ConfidenceLevel]
                    );

            return retval.ToString();
        }

Usage Example

        public void ShouldWork()
        {
            //arrange
            var participants = CreateRandomParticipationRecords(100, 200);
            var exp = new Experiment(null, null, null, DateTime.Now, null, participants, new[] { "false", "true" });

            //act
            var stats = new ABsoluteMaybeStatistics(exp);
            var formatted = new ABingoStyleFormatter(stats);

            //assert
            formatted.ShouldNotBeNull();
            formatted.ToString().ShouldNotEqual(string.Empty);
        }