Beispiel #1
0
        public void ImproperWordAdd()
        {
            WordDatabase db = new WordDatabase();

            db.AddWord(cat);
            Assert.IsTrue(db.GetAllWords().SetEquals(new HashSet <Word> {
                cat
            }));
            db.AddWord(cat);
            Assert.AreEqual(1, db.GetAllWords().Count);
            Assert.IsTrue(db.GetAllWords().SetEquals(new HashSet <Word> {
                cat
            }));
        }
Beispiel #2
0
        public void DeserializeDatabase()
        {
            string       expected = @"Words:
BASEBALL, BAT, CAT, PORT, PORTS, SPORT

Links:
BASEBALL BAT WordAssociation
BAT BASEBALL WordAssociation
BAT CAT OneLetterChange
CAT BAT OneLetterChange
PORT PORTS OneLetterAddOrRemove
PORT SPORT OneLetterAddOrRemove
PORTS PORT OneLetterAddOrRemove
PORTS SPORT Anagram
SPORT PORT OneLetterAddOrRemove
SPORT PORTS Anagram
";
            StringReader reader   = new StringReader(expected);
            WordDatabase db       = WordDatabase.Deserialize(reader);

            Assert.IsTrue(db.GetAllWords().SetEquals(new HashSet <Word> {
                baseball, bat, cat, sport, ports, port
            }));
            Assert.IsTrue(db.ContainsLink("BASEBALL", "BAT"));
            Assert.IsTrue(db.ContainsLink("BAT", "BASEBALL"));
            Assert.IsTrue(db.ContainsLink("PORTS", "SPORT"));
        }
Beispiel #3
0
        public void PopulatingDatabase()
        {
            WordDatabase db = new WordDatabase();

            db.AddWord(cat);
            db.AddWords(new List <Word> {
                bat, baseball, sport, ports, port
            });
            Assert.IsTrue(db.GetAllWords().SetEquals(new HashSet <Word> {
                cat, bat, baseball, sport, ports, port
            }));
            HashSet <Link> batLinks = db.GetLinksFor(bat);

            Assert.AreEqual(1, batLinks.Count);
            Assert.IsTrue(batLinks.Contains(catBat.Reverse()));
            HashSet <Link> portsLinks = db.GetLinksFor(ports);

            Assert.AreEqual(2, portsLinks.Count);
            Assert.IsTrue(portsLinks.Contains(new Link(ports, sport, LinkType.Anagram)));
            Assert.IsTrue(portsLinks.Contains(new Link(ports, port, LinkType.OneLetterAddOrRemove)));
        }