public void Example_ReturnsTrue() { WordSquare square = new WordSquare(); Assert.IsFalse(square.IsLastLineAWord()); square.SetWordAtIndex("words", 4); Assert.IsTrue(square.IsLastLineAWord()); }
public void CreatesDeepCopy() { WordSquare original = new WordSquare("_____"); original.SetWordAtIndex("alpha", 0); WordSquare copy = new WordSquare(original); original.SetWordAtIndex("beta2", 1); copy.SetWordAtIndex("delta", 0); }
public void Taste_ReturnsExpectedResults() { WordSquare square = new WordSquare("taste"); Assert.AreEqual( @"t____ _a___ __s__ ___t_ ____e", square.ToString()); }
public void PopulatedObject_CreatesExpectedFile() { WeekOfPuzzles weekOfPuzzles = new WeekOfPuzzles { Theme = "WeeklyTheme" }; WordSquare mondayWordSquare = new WordSquare("_____") { Clues = new [] { "first clue", "second clue", "third clue", "fourth clue", "fifth clue" }, Theme = "Theme" }; mondayWordSquare.SetWordAtIndex("acorn", 0); mondayWordSquare.SetWordAtIndex("curio", 1); int indexToSet = 2; mondayWordSquare.SetWordAtIndex("orals", indexToSet); mondayWordSquare.SetWordAtIndex("rille", 3); mondayWordSquare.SetWordAtIndex("nosed", 4); weekOfPuzzles.MondayWordSquare = mondayWordSquare; VowelMovement tuesdayVowelMovementPuzzle = new VowelMovement("The MICE MISS their MOOSE.") { InitialConsonant = "m", FinalConsonant = "s", Theme = "Theme" }; weekOfPuzzles.TuesdayVowelMovement = tuesdayVowelMovementPuzzle; ALittleAlliteration wednesdayAlliterationPuzzle = new ALittleAlliteration() { Clue = "Convey vegetable automobile", Solution = "carry carrot car", Theme = "VegetableWeek" }; weekOfPuzzles.WednesdayALittleAlliteration = wednesdayAlliterationPuzzle; string fileName = $"EmptyObject_example_{Process.GetCurrentProcess().Id}.xml"; if (File.Exists(fileName)) { File.Delete(fileName); } weekOfPuzzles.Serialize(fileName); var actualText = File.ReadAllText(fileName); Console.WriteLine(actualText); Assert.AreEqual(EXPECTED_TEXT, actualText); }
public void Taste_0_ReturnsExpectedResults() { WordSquare square = new WordSquare("taste"); square.SetWordAtIndex("there", 0); Assert.AreEqual( @"there ha___ e_s__ r__t_ e___e", square.ToString()); }
public void MoreRecentUsage_DecreasesDaysSinceLastUse() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-10)); Assert.AreEqual(10, history.DaysSinceLastUse["thank"]); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-9)); Assert.AreEqual(9, history.DaysSinceLastUse["thank"]); }
public void LessRecentUsage_DoesNotChangeDaysSinceLastUse() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-10)); Assert.AreEqual(10, history.DaysSinceLastUse["thank"]); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-12)); Assert.AreEqual(10, history.DaysSinceLastUse["thank"]); }
public void SameSquare_ReturnsTwentyFive() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); wordSquare.SetWordAtIndex("human", 1); wordSquare.SetWordAtIndex("amuse", 2); wordSquare.SetWordAtIndex("nasal", 3); wordSquare.SetWordAtIndex("knelt", 4); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-5)); Assert.AreEqual(25, history.CalculateScore(wordSquare)); }
public void DifferentSquare_ReturnsThreeHundred() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); wordSquare.SetWordAtIndex("human", 1); wordSquare.SetWordAtIndex("amuse", 2); wordSquare.SetWordAtIndex("nasal", 3); wordSquare.SetWordAtIndex("knelt", 4); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-5)); Assert.AreEqual(300, history.CalculateScore(new WordSquare("_____"))); }
public void SHOE_ReturnsExpectedResult() { const string HTML_DIRECTORY = @"html\WordSquares\"; string SOURCE_DIRECTORY = ConfigurationManager.AppSettings["SourceDirectory"] + "WordSquares"; WordSquare square = new WordSquare("____"); square.SetWordAtIndex("shoe", 0); square.SetWordAtIndex("heal", 1); square.SetWordAtIndex("oaks", 2); square.SetWordAtIndex("else", 3); square.Clues[0] = "Something you wear on your foot."; square.Clues[1] = "Recover from an illness."; square.Clues[2] = "Trees that grow from acorns."; square.Clues[3] = "Clue for else."; string generatedHtml = square.FormatHtmlForGoogle(); File.WriteAllText(HTML_DIRECTORY + "actualExample1.html", generatedHtml); var expectedLines = File.ReadAllLines(HTML_DIRECTORY + "expectedExample1.html"); var actualLines = File.ReadAllLines(HTML_DIRECTORY + "actualExample1.html"); 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 + @"\expectedExample1.html", actualLines); } Assert.IsFalse(anyLinesDifferent, "Didn't expect any lines to be different."); }
public void Deserialize(string fileName) { using (TextReader reader = new StreamReader(fileName)) { if (_xmlSerializer.Deserialize(reader) is WeekOfPuzzles deserializedPuzzles) { MondayWordSquare = deserializedPuzzles.MondayWordSquare; TuesdayVowelMovement = deserializedPuzzles.TuesdayVowelMovement; WednesdayALittleAlliteration = deserializedPuzzles.WednesdayALittleAlliteration; ThursdayVowelMovement = deserializedPuzzles.ThursdayVowelMovement; FridayALittleAlliteration = deserializedPuzzles.FridayALittleAlliteration; SelectedWords = deserializedPuzzles.SelectedWords; Theme = deserializedPuzzles.Theme; MondayOfWeekPosted = deserializedPuzzles.MondayOfWeekPosted; } } }
public void SHOE_ReturnsExpectedResult() { WordSquare square = new WordSquare("____"); square.SetWordAtIndex("shoe", 0); square.SetWordAtIndex("heal", 1); square.SetWordAtIndex("oaks", 2); square.SetWordAtIndex("else", 3); square.Clues[0] = "Something you wear on your foot."; square.Clues[1] = "Recover from an illness."; square.Clues[2] = "Trees that grow from acorns."; square.Clues[3] = "Clue for else."; const string EXPECTED_TEXT = "Something you wear on your foot.\t\t\t\t\r\nRecover from an illness.\t\t\t\t\r\nTrees that grow from acorns.\t\t\t\t\r\nClue for else.\t\t\t\t\r\n"; Assert.AreEqual(EXPECTED_TEXT, square.FormatForGoogle()); }
public void PopulatesDictionary() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); wordSquare.SetWordAtIndex("human", 1); wordSquare.SetWordAtIndex("amuse", 2); wordSquare.SetWordAtIndex("nasal", 3); wordSquare.SetWordAtIndex("knelt", 4); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-1)); Assert.AreEqual(5, history.DaysSinceLastUse.Count); foreach (string expectedWord in new[] { "thank", "human", "amuse", "nasal", "knelt" }) { Assert.IsTrue(history.DaysSinceLastUse.ContainsKey(expectedWord)); Assert.AreEqual(1, history.DaysSinceLastUse[expectedWord]); } }
public void Example_ReturnsExpectedValue() { WordSquareHistory history = new WordSquareHistory(); var wordSquare = new WordSquare(); wordSquare.SetWordAtIndex("thank", 0); wordSquare.SetWordAtIndex("human", 1); wordSquare.SetWordAtIndex("amuse", 2); wordSquare.SetWordAtIndex("nasal", 3); wordSquare.SetWordAtIndex("knelt", 4); history.AddWordSquare(wordSquare, DateTime.Now.AddDays(-5)); Assert.AreEqual(5, history.DaysSinceLastUse.Count); foreach (string expectedWord in new[] { "thank", "human", "amuse", "nasal", "knelt" }) { Assert.AreEqual(5, history.CalculateScore(expectedWord)); } Assert.AreEqual(60, history.CalculateScore("word not in the history")); }
// ReSharper disable IdentifierTypo public void epszq_2_ReturnsExpectedResults() // ReSharper restore IdentifierTypo { WordSquare square = new WordSquare("taste"); square.SetWordAtIndex("there", 0); Assert.AreEqual( @"there ha___ e_s__ r__t_ e___e", square.ToString()); var results = square.GetWordCandidates(0); Assert.LessOrEqual(0, results.Count, "Expected at least one word in first row."); square.SetWordAtIndex("happy", 1); Assert.AreEqual( @"there happy eps__ rp_t_ ey__e", square.ToString()); int indexToSet = 2; // ReSharper disable StringLiteralTypo square.SetWordAtIndex("epszq", indexToSet); Assert.AreEqual( @"there happy epszq rpzt_ eyq_e", square.ToString()); // ReSharper restore StringLiteralTypo Assert.IsFalse(square.IsLastLineAWord(), "Last line is not a word."); }
// ReSharper disable IdentifierTypo public void rpztj_3_ReturnsExpectedResults() // ReSharper restore IdentifierTypo { WordSquare square = new WordSquare("taste"); square.SetWordAtIndex("there", 0); Assert.AreEqual( @"there ha___ e_s__ r__t_ e___e", square.ToString()); square.SetWordAtIndex("happy", 1); Assert.AreEqual( @"there happy eps__ rp_t_ ey__e", square.ToString()); int indexToSet = 2; // ReSharper disable StringLiteralTypo square.SetWordAtIndex("epszq", indexToSet); Assert.AreEqual( @"there happy epszq rpzt_ eyq_e", square.ToString()); square.SetWordAtIndex("rpztj", 3); Assert.AreEqual( @"there happy epszq rpztj eyqje", square.ToString()); // ReSharper restore StringLiteralTypo }
public void HashtagTheme_ProducesExpectedText() { WordSquare square = new WordSquare("_____"); square.SetWordAtIndex("guppy", 0); square.SetWordAtIndex("uvula", 1); int indexToSet = 2; square.SetWordAtIndex("purer", indexToSet); square.SetWordAtIndex("plead", 3); square.SetWordAtIndex("yards", 4); square.Clues[1] = "Thing that hangs above your throat"; square.Clues[2] = "Less tainted"; square.Clues[3] = "Beg"; square.Clues[4] = "Measurements of distance"; square.Theme = "#ThemeWeek"; const string EXPECTED_STRING = @"#ThemeWeek #MagicWordSquare G**** ***** ***** ***** ***** Top word is part of this week's theme! Remaining (unordered) clues: Beg Less tainted Measurements of distance Thing that hangs above your throat #HowToPlay: https://t.co/rSa0rUCvRC "; Assert.AreEqual(EXPECTED_STRING, square.GetTweet()); }
public void Default_ProducesExpectedText() { WordSquare square = new WordSquare("_____"); const string EXPECTED_STRING = @"#MagicWordSquare _**** ***** ***** ***** ***** Top word is part of this week's theme! Remaining (unordered) clues: #HowToPlay: https://t.co/rSa0rUCvRC "; Assert.AreEqual(EXPECTED_STRING, square.GetTweet()); }
//[Ignore("Takes more than 3 seconds.")] //Covers a lot of the class. public void CanReadSize4File() { var results = WordSquare.ReadAllWordSquaresFromFile(@"data\area.txt", 4); Assert.AreEqual(5, results.Count, "Expected to read 5 word squares."); }