Exemple #1
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));
        }
Exemple #2
0
        public void GetLinkBetween()
        {
            WordDatabase db = new WordDatabase();

            db.AddWords(new List <Word> {
                cat, bat, baseball, sport, ports, port
            });
            db.AddLink(batBaseball);
            db.AddLink(baseballSport);
            Assert.AreEqual(catBat, db.GetLinkBetween(cat, bat));
            Assert.AreEqual(baseballSport, db.GetLinkBetween(baseball, sport));
            Assert.AreEqual(null, db.GetLinkBetween(cat, baseball));
            Assert.AreEqual(null, db.GetLinkBetween(car, cat));
            Assert.AreEqual(null, db.GetLinkBetween("", "CAT"));
        }
Exemple #3
0
        public void FindChain()
        {
            WordDatabase db = new WordDatabase();

            db.AddWords(new List <Word> {
                cat, bat, baseball, sport, ports, port
            });
            db.AddLink(new Link(bat, baseball, LinkType.WordAssociation));
            db.AddLink(new Link(sport, baseball, LinkType.WordAssociation));
            Chain chain = db.FindChain(cat, port);

            Assert.AreEqual(5, chain.Count);
            Assert.AreEqual(catBat, chain[0]);
            Assert.AreEqual(batBaseball, chain[1]);
            Assert.AreEqual(baseballSport, chain[2]);
            Assert.AreEqual(sportPorts, chain[3]);
            Assert.AreEqual(portsPort, chain[4]);
        }
Exemple #4
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"));
        }
Exemple #5
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);
        }