Esempio n. 1
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"));
        }
Esempio n. 2
0
        public void RemoveLink()
        {
            WordDatabase db = new WordDatabase();

            db.AddWords(new List <Word> {
                cat, bat, baseball, sport, ports, port
            });
            db.AddLink(batBaseball);
            db.AddLink(baseballSport);
            Assert.IsTrue(db.ContainsLink(sport, port));
            db.RemoveLink(sportPort);
            Assert.IsFalse(db.ContainsLink(sport, port));
            Assert.ThrowsException <System.Exception>(() => db.RemoveLink(portsParts));
        }
Esempio n. 3
0
        public void ContainsLink()
        {
            WordDatabase db = new WordDatabase();

            db.AddWords(new List <Word> {
                cat, bat, baseball, sport, ports, port
            });
            db.AddLink(new Link(bat, baseball, LinkType.WordAssociation));
            Assert.IsTrue(db.ContainsLink(cat, bat));
            Assert.IsTrue(db.ContainsLink(bat, cat));
            Assert.IsTrue(db.ContainsLink(bat, baseball));
            Assert.IsTrue(db.ContainsLink("SPORT", "PORTS"));
            Assert.IsFalse(db.ContainsLink(cat, sport));
            Assert.IsFalse(db.ContainsLink("CAT", "RAT"));
        }