コード例 #1
0
        public virtual void TestCoreMap()
        {
            ICoreMap @object = new ArrayCoreMap(0);

            NUnit.Framework.Assert.IsFalse(@object.ContainsKey(typeof(CoreMapTest.StringA)));
            @object.Set(typeof(CoreMapTest.StringA), "stem");
            NUnit.Framework.Assert.IsTrue(@object.ContainsKey(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual("stem", @object.Get(typeof(CoreMapTest.StringA)));
            @object.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.AreEqual("hi", @object.Get(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual(null, @object.Get(typeof(CoreMapTest.IntegerA)));
            @object.Set(typeof(CoreMapTest.IntegerA), 4);
            NUnit.Framework.Assert.AreEqual(int.Parse(4), @object.Get(typeof(CoreMapTest.IntegerA)));
            @object.Set(typeof(CoreMapTest.StringB), "Yes");
            NUnit.Framework.Assert.AreEqual("Wrong # objects", 3, @object.KeySet().Count);
            NUnit.Framework.Assert.AreEqual("Wrong keyset", new HashSet <Type>(Arrays.AsList(typeof(CoreMapTest.StringA), typeof(CoreMapTest.IntegerA), typeof(CoreMapTest.StringB))), @object.KeySet());
            NUnit.Framework.Assert.AreEqual("Wrong remove value", int.Parse(4), @object.Remove(typeof(CoreMapTest.IntegerA)));
            NUnit.Framework.Assert.AreEqual("Wrong # objects", 2, @object.KeySet().Count);
            NUnit.Framework.Assert.AreEqual("Wrong keyset", new HashSet <Type>(Arrays.AsList(typeof(CoreMapTest.StringA), typeof(CoreMapTest.StringB))), @object.KeySet());
            NUnit.Framework.Assert.AreEqual("Wrong value", "hi", @object.Get(typeof(CoreMapTest.StringA)));
            NUnit.Framework.Assert.AreEqual("Wrong value", "Yes", @object.Get(typeof(CoreMapTest.StringB)));
            NUnit.Framework.Assert.AreEqual(null, @object.Set(typeof(CoreMapTest.IntegerA), 7));
            NUnit.Framework.Assert.AreEqual(int.Parse(7), @object.Get(typeof(CoreMapTest.IntegerA)));
            NUnit.Framework.Assert.AreEqual(int.Parse(7), @object.Set(typeof(CoreMapTest.IntegerA), 3));
            NUnit.Framework.Assert.AreEqual(int.Parse(3), @object.Get(typeof(CoreMapTest.IntegerA)));
        }
コード例 #2
0
        public virtual void TestEquality()
        {
            ICoreMap a = new ArrayCoreMap();
            ICoreMap b = new ArrayCoreMap();

            NUnit.Framework.Assert.IsTrue(a.Equals(b));
            NUnit.Framework.Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            a.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.IsFalse(a.Equals(b));
            NUnit.Framework.Assert.IsFalse(a.GetHashCode() == b.GetHashCode());
            b.Set(typeof(CoreMapTest.StringA), "hi");
            NUnit.Framework.Assert.IsTrue(a.Equals(b));
            NUnit.Framework.Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            a.Remove(typeof(CoreMapTest.StringA));
            NUnit.Framework.Assert.IsFalse(a.Equals(b));
            NUnit.Framework.Assert.IsFalse(a.GetHashCode() == b.GetHashCode());
        }
コード例 #3
0
        public virtual void TestRemove()
        {
            ArrayCoreMap foo = new ArrayCoreMap();

            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "F");
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(2, foo.Size());
            foo.Remove(typeof(CoreAnnotations.TextAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "bar");
            NUnit.Framework.Assert.AreEqual("bar", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            NUnit.Framework.Assert.AreEqual(2, foo.Size());
            foo.Remove(typeof(CoreAnnotations.TextAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual("F", foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(0, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            // Removing an element that doesn't exist
            // shouldn't blow up on us in any way
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(0, foo.Size());
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
            // after removing all sorts of stuff, the original ArrayCoreMap
            // should now be equal to a new empty one
            ArrayCoreMap bar = new ArrayCoreMap();

            NUnit.Framework.Assert.AreEqual(foo, bar);
            foo.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            foo.Set(typeof(CoreAnnotations.PartOfSpeechAnnotation), "F");
            bar.Set(typeof(CoreAnnotations.TextAnnotation), "foo");
            NUnit.Framework.Assert.IsFalse(foo.Equals(bar));
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(foo, bar);
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            foo.Remove(typeof(CoreAnnotations.PartOfSpeechAnnotation));
            NUnit.Framework.Assert.AreEqual(1, foo.Size());
            NUnit.Framework.Assert.AreEqual("foo", foo.Get(typeof(CoreAnnotations.TextAnnotation)));
            NUnit.Framework.Assert.AreEqual(null, foo.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)));
        }