示例#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
            }));
        }
示例#2
0
        public static WordDatabase Deserialize(TextReader reader)
        {
            WordDatabase db = new WordDatabase();

            reader.ReadLine();
            foreach (string word in reader.ReadLine().Split(','))
            {
                db.AddWord(word.Trim());
            }

            reader.ReadLine();
            reader.ReadLine();
            while (reader.Peek() >= 0)
            {
                string[] tokens = reader.ReadLine().Split(' ');
                db.AddLink(new Link(new Word(tokens[0]), new Word(tokens[1]), LinkTypes.FromString(tokens[2])));
            }
            return(db);
        }
示例#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)));
        }