public void LongPhrase_CreatesSubPuzzles() { const string AUTHOR = "Malala Yousafzai"; const string PHRASE = "In some parts of the world, students are going to school every day. It's their normal life. But in other part of the world, we are starving for education... it's like a precious gift. It's like a diamond."; PhraseSegmentPuzzle puzzle = new PhraseSegmentPuzzle { Phrase = PHRASE, Author = AUTHOR }; puzzle.PlacePhrase(); Assert.AreEqual(3, puzzle.SubPuzzles.Count); StringBuilder piecePhraseTogetherAgain = new StringBuilder(); for (var index = 0; index < puzzle.SubPuzzles.Count; index++) { var subPuzzle = puzzle.SubPuzzles[index]; if (index == 2) { Assert.AreEqual(AUTHOR, puzzle.SubPuzzles[2].Author); } else { Assert.AreEqual("", subPuzzle.Author); } piecePhraseTogetherAgain.Append(subPuzzle.Phrase); piecePhraseTogetherAgain.Append(" "); } Assert.AreEqual(PHRASE + " ", piecePhraseTogetherAgain.ToString()); }
public void ExampleTwo_SetsExpectedProperties() { const string AUTHOR = "Chip"; const string PHRASE = "The fat cat sat in the bath."; PhraseSegmentPuzzle puzzle = new PhraseSegmentPuzzle { Phrase = PHRASE, Author = AUTHOR }; puzzle.PlacePhrase(); Assert.AreEqual(36, puzzle.CompleteLength, "Unexpected Complete Length"); Assert.AreEqual(4, puzzle.SpacesBeforeAuthor, "Unexpected SpacesBeforeAuthor"); Assert.AreEqual(PHRASE + " " + AUTHOR, puzzle.CompletePhrase, "Unexpected CompletePhrase"); }
public void LongPuzzle_ReturnsExpectedResult(bool includeSolution) { const string HTML_DIRECTORY = @"html\PhraseSegment\"; string SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "PhraseSegment"; const string AUTHOR = "Malala Yousafzai"; const string PHRASE = "In some parts of the world, students are going to school every day. It's their normal life. But in other part of the world, we are starving for education... it's like a precious gift. It's like a diamond."; PhraseSegmentPuzzle puzzle = new PhraseSegmentPuzzle { Phrase = PHRASE, Author = AUTHOR, RandomSeed = 42 }; puzzle.PlacePhrase(); string generatedHtml = puzzle.FormatHtmlForGoogle(includeSolution); var actualFileName = "actualExample2.html"; if (includeSolution) { actualFileName = "actualExampleWithSolution2.html"; } File.WriteAllText(HTML_DIRECTORY + actualFileName, generatedHtml); var expectedFileName = "expectedExample2.html"; if (includeSolution) { expectedFileName = "expectedExampleWithSolution2.html"; } string[] expectedLines = new[] { " " };// need to have something to be different from generated file. if (File.Exists(HTML_DIRECTORY + expectedFileName)) { expectedLines = File.ReadAllLines(HTML_DIRECTORY + expectedFileName); } var actualLines = File.ReadAllLines(HTML_DIRECTORY + actualFileName); bool anyLinesDifferent = false; for (var index = 0; index < expectedLines.Length; index++) { string expectedLine = expectedLines[index]; string actualLine = "End of file already reached."; if (index >= 0 && actualLines.Length > index) { actualLine = actualLines[index]; } if (expectedLine != actualLine) { anyLinesDifferent = true; Console.WriteLine($"Expected Line {index}:{expectedLine}"); Console.WriteLine($" Actual Line {index}:{expectedLine}"); } } if (anyLinesDifferent) { Console.WriteLine("Updating source file. Will show up as a difference in source control."); File.WriteAllLines(SOURCE_DIRECTORY + $@"\{expectedFileName}", actualLines); } Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different."); }
public void ExamplePuzzle_ReturnsExpectedResult(bool includeSolution) { const string HTML_DIRECTORY = @"html\PhraseSegment\"; string SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "PhraseSegment"; const string AUTHOR = "Chip"; const string PHRASE = "The fat cat sat on the bat."; PhraseSegmentPuzzle puzzle = new PhraseSegmentPuzzle { Phrase = PHRASE, Author = AUTHOR, RandomSeed = 42 }; puzzle.PlacePhrase(); string generatedHtml = puzzle.FormatHtmlForGoogle(includeSolution); var actualFileName = "actualExample1.html"; if (includeSolution) { actualFileName = "actualExampleWithSolution1.html"; } File.WriteAllText(HTML_DIRECTORY + actualFileName, generatedHtml); var expectedFileName = "expectedExample1.html"; if (includeSolution) { expectedFileName = "expectedExampleWithSolution1.html"; } string[] expectedLines = new[] { " " };// need to have something to be different from generated file. if (File.Exists(HTML_DIRECTORY + expectedFileName)) { expectedLines = File.ReadAllLines(HTML_DIRECTORY + expectedFileName); } var actualLines = File.ReadAllLines(HTML_DIRECTORY + actualFileName); bool anyLinesDifferent = false; for (var index = 0; index < expectedLines.Length; index++) { string expectedLine = expectedLines[index]; string actualLine = "End of file already reached."; if (index >= 0 && actualLines.Length > index) { actualLine = actualLines[index]; } if (expectedLine != actualLine) { anyLinesDifferent = true; Console.WriteLine($"Expected Line {index}:{expectedLine}"); Console.WriteLine($" Actual Line {index}:{expectedLine}"); } } if (anyLinesDifferent) { Console.WriteLine("Updating source file. Will show up as a difference in source control."); File.WriteAllLines(SOURCE_DIRECTORY + $@"\{expectedFileName}", actualLines); } Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different."); }