Пример #1
0
        public void TestSingleWord()
        {
            var index = new WordIndex();

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[0]));

            index.Add("w1", "attr2");
            index.Add("w1", "attr1");
            index.Add("w1", "attr3");

            Assert.Throws <ArgumentException>(() => index.Add("w1", "attr1"));

            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] { "attr1", "attr2", "attr3" }));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] { "w1" }));
            Assert.That(index.GetWordNames("attr2"), Is.EquivalentTo(new string[] { "w1" }));
            Assert.That(index.GetWordNames("attr3"), Is.EquivalentTo(new string[] { "w1" }));

            Assert.Throws <KeyNotFoundException>(() => index.Remove("wX", "attr1"));
            Assert.Throws <KeyNotFoundException>(() => index.Remove("w1", "attrX"));

            index.Remove("w1", "attr2");
            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[] { "attr1", "attr3" }));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[] { "w1" }));
            Assert.That(index.GetWordNames("attr2"), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr3"), Is.EquivalentTo(new string[] { "w1" }));


            index.Remove("w1", "attr1");
            index.Remove("w1", "attr3");
            Assert.That(index.GetAttributes(), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr1"), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr2"), Is.EquivalentTo(new string[0]));
            Assert.That(index.GetWordNames("attr3"), Is.EquivalentTo(new string[0]));
        }
Пример #2
0
        public static void Main(String[] args)
        {
            WordIndex wi = new WordIndex();

            wi.Add("ja", 2);
            wi.Add("nej", 4);
            wi.Add("ja", 7);
            foreach (string s in wi.Keys)
            {
                Console.WriteLine(s + " -->");
                foreach (int line in wi[s])
                {
                    Console.WriteLine(" " + line);
                }
            }
        }