コード例 #1
0
        private static string MakeHTML(KindOfWorld aCounterexample, string aColor)
        {
            StringBuilder lText = new StringBuilder();

            lText.AddLine("<div style=\"color:{0}\" class=\"counterexample\">", aColor);
            lText.AddLine("<h3>Kind of World</h3>");
            if (aCounterexample.Predicates.Any())
            {
                lText.AddLine("<h4>Nullary Predicates:</h4>");
                lText.AddLine("<ul><li style=\"{0}\">", aColor);
                foreach (NullPredicate lPredicate in aCounterexample.Predicates)
                {
                    if (aCounterexample.Affirms(lPredicate))
                    {
                        lText.Append(lPredicate.ToString());
                    }
                    else
                    {
                        lText.AppendFormat("<span style=\"text-decoration:overline;\">{0}</span>", lPredicate);
                    }
                }
                lText.AddLine("</li></ul>");
            }
            if (aCounterexample.KindsOfObjects.Any())
            {
                lText.AddLine("<h4>Kinds of Objects:</h4>");
                lText.AddLine("<ul>");
                foreach (KindOfObject lKindOfObject in aCounterexample.KindsOfObjects)
                {
                    lText.AppendFormat("<li>{0} {1}", lKindOfObject.NumberOfDistinguishableInstances, lKindOfObject.Predicates.Count() == 0 ? "distinct" : "&times; ");
                    foreach (UnaryPredicate lPredicate in lKindOfObject.Predicates)
                    {
                        if (lKindOfObject.Affirms(lPredicate))
                        {
                            lText.Append(lPredicate.ToString());
                        }
                        if (lKindOfObject.Denies(lPredicate))
                        {
                            lText.AppendFormat("<span style=\"text-decoration:overline;\">{0}</span>", lPredicate);
                        }
                    }
                    lText.AddLine("</li>");
                }
                lText.AddLine("</ul>");
            }
            lText.AddLine("</div>");

            return(lText.ToString().Replace("</span><span style=\"text-decoration:overline;\">", ""));
        }
コード例 #2
0
        public void AddLine()
        {
            StringBuilder builder = new StringBuilder();

            builder.AddLine();
            Assert.IsTrue(builder.ToString() == Environment.NewLine);
        }
コード例 #3
0
ファイル: CrashHandler.cs プロジェクト: yordidec/NohBoard
        /// <summary>
        /// Returns a string describing the exception.
        /// </summary>
        private static string ShowException(Exception ex, int depth = 0)
        {
            var sb = new StringBuilder();

            sb.AddLine(ex.GetType().FullName);
            sb.AddLine($"Message: '{ex.Message}'.");
            sb.AddLine("Stack trace:");
            sb.AddLine(ex.StackTrace);

            if (!(ex.InnerException is null) && (depth < 10))
            {
                sb.AppendLine();
                sb.AddLine("Inner exception:");
                sb.Append(ShowException(ex.InnerException, depth + 1));
            }

            return(sb.ToString());
        }
コード例 #4
0
    public static string WriteContent(this Dictionary <string, string> source)
    {
        var sb = new StringBuilder();

        foreach (var kvp in source)
        {
            sb.AddLine("Key: {0} Value: {1}", kvp.Key, kvp.Value);
        }
        return(sb.ToString());
    }
コード例 #5
0
        private static string MakeHTMLForExample(ModalCounterexample aExample)
        {
            StringBuilder lText = new StringBuilder();

            lText.AddLine("<div class=\"counterexample\">");
            lText.AddLine("<h3>Example</h3>");
            lText.AddLine("<p>This is an interpretation of predicates in which the statement is possibly true."
                          + "  <span style=\"color:red\">Red text</span> indicates a kind of world in which the statement is true."
                          + "  <span style=\"color:black;font-weight:bold\">Black text</span> indicates a kind of world in which the statement is false.</p>");
            foreach (KindOfWorld lKindOfWorld in aExample.Counterexamples)
            {
                lText.AddLine(MakeHTML(lKindOfWorld, "red"));
            }
            foreach (KindOfWorld lKindOfWorld in aExample.NonCounterexamples)
            {
                lText.AddLine(MakeHTML(lKindOfWorld, "black"));
            }
            lText.AddLine("</div>");
            return(lText.ToString());
        }
コード例 #6
0
ファイル: CrashHandler.cs プロジェクト: yordidec/NohBoard
        /// <summary>
        /// Collects the current state of the program.
        /// </summary>
        /// <returns>The state of the program.</returns>
        private static string CollectState()
        {
            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AddLine("Current settings:");
            sb.AddLine(FileHelper.Serialize(GlobalSettings.Settings));

            if (!(GlobalSettings.CurrentDefinition is null))
            {
                sb.AppendLine();
                sb.AddLine("Current definition:");
                sb.AddLine(FileHelper.Serialize(GlobalSettings.CurrentDefinition));
            }

            if (!(GlobalSettings.CurrentStyle is null))
            {
                sb.AppendLine();
                sb.AddLine("Current style:");
                sb.AddLine(FileHelper.Serialize(GlobalSettings.CurrentStyle));
            }

            return(sb.ToString());
        }
コード例 #7
0
        static void Main(string[] args)
        {
            int lTrials;

            if (args.Length > 0)
            {
                try
                {
                    lTrials = Convert.ToInt32(args[0]);
                }
                catch (Exception)
                {
                    lTrials = DefaultNumberOfTrials;
                }
            }
            else
            {
                lTrials = DefaultNumberOfTrials;
            }

            string lNote;

            if (args.Length > 1)
            {
                lNote = string.Join(" ", args.Skip(1).ToArray());
            }
            else
            {
                lNote = "";
            }

            StringBuilder lContentsOfTestFiles = new StringBuilder();
            StringBuilder lTimingResults       = new StringBuilder();
            List <long>   lTimes = new List <long>();

            foreach (string lTestFileName in TestFileNames)
            {
                Console.Write("{0,32}... ", lTestFileName);
                try
                {
                    string[] lFileText     = File.ReadAllLines(Path.Combine(LocationOfTestFiles, lTestFileName));
                    long     lDecisionTime = ObserveDecisionTime(
                        Parser.Parse(lFileText),
                        NamesOfSlowTestFiles.Contains(lTestFileName) ? 1 : lTrials);
                    Console.WriteLine("{0:X16} - {1} seconds", lDecisionTime, TimeSpan.FromTicks(lDecisionTime).TotalSeconds);
                    lContentsOfTestFiles.AppendLine();
                    lContentsOfTestFiles.AddLine("// Test File {0}:", lTestFileName);
                    lContentsOfTestFiles.Append(string.Join(Environment.NewLine, lFileText));
                    lTimingResults.AddLine("{0:X16}\t{1}", lDecisionTime, lTestFileName);
                    lTimes.Add(lDecisionTime);
                }
                catch (Exception lException)
                {
                    lTimingResults.AddLine(@"Failed to test {0}: {1}", lTestFileName, lException);
                }
            }

            StreamWriter lOutput = CreateOutputStream();

            lOutput.WriteLine("Test run, " + DateTime.Now.ToString());
            lOutput.Write(lTimingResults);
            lOutput.WriteLine("Mean\tMedian");
            lTimes.Sort();
            lOutput.WriteLine("{0}\t{1}", lTimes.Average(), lTimes.ElementAt(lTimes.Count() / 2));
            lOutput.WriteLine();
            lOutput.WriteLine(LogicSourceCode);
            lOutput.WriteLine(lContentsOfTestFiles);
            lOutput.Close();

#if DEBUG
            Console.WriteLine("Done.");
            Console.ReadKey();
#endif
        }
コード例 #8
0
            public void AddLine_OnGoodStringBuilder_WithEmptyString_WithLineWriter_StringBuilderContainsNewLine()
            {
                var mockLineWriter = new Mock<ILineWriter>();
                var emptyString = string.Empty;
                var stringBuilder = new StringBuilder();
                ILineWriter lineWriter = mockLineWriter.Object;
                var actual = stringBuilder.AddLine(emptyString, lineWriter).ToString();

                Assert.That(() => actual, Is.EqualTo(Environment.NewLine));
            }
コード例 #9
0
            public void AddLine_OnGoodStringBuilder_WithGoodString_WithLineWriter_StringBuilderContainsStringAndNewLine()
            {
                var fixture = new LatinStringFixture();
                var testString = fixture.Create<string>();
                var stringBuilder = new StringBuilder();
                var mockLineWriter = new Mock<ILineWriter>();
                ILineWriter lineWriter = mockLineWriter.Object;
                var actual = stringBuilder.AddLine(testString, lineWriter);

                Assert.That(() => actual.ToString(), Is.EqualTo(testString + Environment.NewLine));
            }