示例#1
0
            public void RemoveAll()
            {
                HashSet <int> list2 = new HashSet <int> ();

                hashset.Add(4);
                hashset.Add(5);
                hashset.Add(6);
                list2.Add(5);
                list2.Add(7);
                list2.Add(4);
                hashset.RemoveAll(list2);
                Assert.IsTrue(IC.eq(hashset, 6));
                hashset.Add(5);
                hashset.Add(4);
                list2.Clear();
                list2.Add(6);
                list2.Add(5);
                hashset.RemoveAll(list2);
                Assert.IsTrue(IC.eq(hashset, 4));
                list2.Clear();
                list2.Add(7);
                list2.Add(8);
                list2.Add(9);
                hashset.RemoveAll(list2);
                Assert.IsTrue(IC.eq(hashset, 4));
            }
示例#2
0
文件: Clone.cs 项目: ggeurts/nhive
        private static void realtester <U>(U extensible) where U : class, IExtensible <int>, new()
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            System.IO.Stream stream = new System.IO.MemoryStream();
            formatter.Serialize(stream, extensible);
            stream.Flush();
            stream.Seek(0L, System.IO.SeekOrigin.Begin);
            object clone = formatter.Deserialize(stream);

            Assert.IsNotNull(clone);
            Assert.AreEqual(typeof(U), clone.GetType(),
                            String.Format("Wrong type '{0}' of clone of '{1}'", clone.GetType(), typeof(U)));
            U theClone = clone as U;

            Assert.IsTrue(theClone.Check(), "Clone does not pass Check()");
            if (typeof(ICollection <int>).IsAssignableFrom(typeof(U)))
            {
                Assert.IsTrue(EqualityComparer <U> .Default.Equals(extensible, theClone), "Clone has wrong contents");
            }
            else //merely extensible
            {
                Assert.IsTrue(IC.eq(theClone, extensible.ToArray()), "Clone has wrong contents");
            }
        }
示例#3
0
 public void Simple2()
 {
     loadup2();
     Assert.IsTrue(queue.Check());
     Assert.AreEqual(5, queue.Count);
     Assert.IsTrue(IC.eq(queue, 15, 1000, 1001, 1002, 1003));
     Assert.AreEqual(15, queue.Choose());
 }
示例#4
0
 public void Simple()
 {
     loadup1();
     Assert.IsTrue(queue.Check());
     Assert.AreEqual(5, queue.Count);
     Assert.IsTrue(IC.eq(queue, 12, 13, 103, 14, 15));
     Assert.AreEqual(12, queue.Choose());
 }
示例#5
0
 public void RemoveAllCopies()
 {
     hashbag.Add(5); hashbag.Add(7); hashbag.Add(5);
     Assert.AreEqual(2, hashbag.ContainsCount(5));
     Assert.AreEqual(1, hashbag.ContainsCount(7));
     hashbag.RemoveAllCopies(5);
     Assert.AreEqual(0, hashbag.ContainsCount(5));
     Assert.AreEqual(1, hashbag.ContainsCount(7));
     hashbag.Add(5); hashbag.Add(8); hashbag.Add(5);
     hashbag.RemoveAllCopies(8);
     Assert.IsTrue(IC.eq(hashbag, 7, 5, 5));
 }
示例#6
0
        public static void DTester <U>() where U : class, IDictionary <int, int>, new()
        {
            U dict = new U();

            realDtester <U>(dict);
            dict.Add(12, 4);
            dict.Add(23, 6);
            dict.Add(56, 1);
            realDtester <U>(dict);
            Assert.IsTrue(IC.eq((ICollectionValue <int>)serializeAndDeserialize(dict.Keys), dict.Keys.ToArray()), "Keys clone has wrong contents");
            Assert.IsTrue(IC.eq((ICollectionValue <int>)serializeAndDeserialize(dict.Values), dict.Values.ToArray()), "Values Clone has wrong contents");
        }
示例#7
0
        public void RetainAll()
        {
            HashBag <int> list2 = new HashBag <int>();

            hashbag.Add(4); hashbag.Add(5); hashbag.Add(4); hashbag.Add(6); hashbag.Add(4);
            list2.Add(5); list2.Add(4); list2.Add(7); list2.Add(4);
            hashbag.RetainAll(list2);
            Assert.IsTrue(IC.seteq(hashbag, 4, 4, 5));
            hashbag.Add(6);
            list2.Clear();
            list2.Add(7); list2.Add(8); list2.Add(9);
            hashbag.RetainAll(list2);
            Assert.IsTrue(IC.eq(hashbag));
        }
示例#8
0
文件: WrappersTest.cs 项目: suzuke/C5
            public void FilterShouldRaiseAnExceptionInStrictMemoryMode()
            {
                if (MemoryType != MemoryType.Strict)
                {
                    return;
                }

                int[] inner = new int[] { 3, 4, 6, 5, 7 };
                WrappedArray <int> outerwrapped = new WrappedArray <int>(inner, MemoryType);

                WrappedArray <int> wrapped = (WrappedArray <int>)outerwrapped.View(1, 3);
                Func <int, bool>   is4     = delegate(int i) { return(i == 4); };

                if (MemoryType == MemoryType.Strict)
                {
                    Assert.Throws <Exception>(() => IC.eq(wrapped.Filter(is4), 4));
                }
            }
示例#9
0
文件: Clone.cs 项目: ggeurts/nhive
        public static void RealTester <U>(U extensible) where U : class, IExtensible <int>, new()
        {
            object clone = extensible.Clone();

            Assert.IsNotNull(clone);
            Assert.AreEqual(typeof(U), clone.GetType(),
                            String.Format("Wrong type '{0}' of clone of '{1}'", clone.GetType(), typeof(U)));
            U theClone = clone as U;

            Assert.IsTrue(theClone.Check(), "Clone does not pass Check()");
            if (typeof(ICollection <int>).IsAssignableFrom(typeof(U)))
            {
                Assert.IsTrue(EqualityComparer <U> .Default.Equals(extensible, theClone), "Clone has wrong contents");
            }
            else //merely extensible
            {
                Assert.IsTrue(IC.eq(theClone, extensible.ToArray()), "Clone has wrong contents");
            }
        }
示例#10
0
 public void Expand()
 {
     Assert.IsTrue(queue.Check());
     loadup3();
     Assert.IsTrue(IC.eq(queue, 14, 15, 16, 17));
 }
示例#11
0
            public void View()
            {
                int[] inner = new int[] { 3, 4, 6, 5, 7 };
                WrappedArray <int> outerwrapped = new WrappedArray <int>(inner);
                WrappedArray <int> wrapped      = (WrappedArray <int>)outerwrapped.View(1, 3);

                //
                Assert.AreEqual(6, wrapped[1]);
                Assert.IsTrue(IC.eq(wrapped[1, 2], 6, 5));
                //
                Fun <int, bool> is4 = delegate(int i) { return(i == 4); };

                Assert.AreEqual(EventTypeEnum.None, wrapped.ActiveEvents);
                Assert.AreEqual(false, wrapped.All(is4));
                Assert.AreEqual(true, wrapped.AllowsDuplicates);
                wrapped.Apply(delegate(int i) { });
                Assert.AreEqual("{ 5, 6, 4 }", wrapped.Backwards().ToString());
                Assert.AreEqual(true, wrapped.Check());
                wrapped.Choose();
                Assert.AreEqual(true, wrapped.Contains(4));
                Assert.AreEqual(true, wrapped.ContainsAll(new ArrayList <int>()));
                Assert.AreEqual(1, wrapped.ContainsCount(4));
                Assert.AreEqual(Speed.Linear, wrapped.ContainsSpeed);
                int[] extarray = new int[5];
                wrapped.CopyTo(extarray, 1);
                Assert.IsTrue(IC.eq(extarray, 0, 4, 6, 5, 0));
                Assert.AreEqual(3, wrapped.Count);
                Assert.AreEqual(Speed.Constant, wrapped.CountSpeed);
                Assert.AreEqual(EnumerationDirection.Forwards, wrapped.Direction);
                Assert.AreEqual(false, wrapped.DuplicatesByCounting);
                Assert.AreEqual(IntEqualityComparer.Default, wrapped.EqualityComparer);
                Assert.AreEqual(true, wrapped.Exists(is4));
                Assert.IsTrue(IC.eq(wrapped.Filter(is4), 4));
                int j = 5;

                Assert.AreEqual(true, wrapped.Find(ref j));
                Assert.AreEqual(true, wrapped.Find(is4, out j));
                Assert.AreEqual("[ 0:4 ]", wrapped.FindAll(is4).ToString());
                Assert.AreEqual(0, wrapped.FindIndex(is4));
                Assert.AreEqual(true, wrapped.FindLast(is4, out j));
                Assert.AreEqual(0, wrapped.FindLastIndex(is4));
                Assert.AreEqual(4, wrapped.First);
                wrapped.GetEnumerator();
                Assert.AreEqual(CHC.sequencedhashcode(4, 6, 5), wrapped.GetSequencedHashCode());
                Assert.AreEqual(CHC.unsequencedhashcode(4, 6, 5), wrapped.GetUnsequencedHashCode());
                Assert.AreEqual(Speed.Constant, wrapped.IndexingSpeed);
                Assert.AreEqual(2, wrapped.IndexOf(5));
                Assert.AreEqual(false, wrapped.IsEmpty);
                Assert.AreEqual(true, wrapped.IsReadOnly);
                Assert.AreEqual(false, wrapped.IsSorted());
                Assert.AreEqual(true, wrapped.IsValid);
                Assert.AreEqual(5, wrapped.Last);
                Assert.AreEqual(2, wrapped.LastIndexOf(5));
                Assert.AreEqual(EventTypeEnum.None, wrapped.ListenableEvents);
                Fun <int, string> i2s = delegate(int i) { return(string.Format("T{0}", i)); };

                Assert.AreEqual("[ 0:T4, 1:T6, 2:T5 ]", wrapped.Map <string>(i2s).ToString());
                Assert.AreEqual(1, wrapped.Offset);
                wrapped.Reverse();
                Assert.AreEqual("[ 0:5, 1:6, 2:4 ]", wrapped.ToString());
                IList <int> other = new ArrayList <int>(); other.AddAll <int>(new int[] { 4, 5, 6 });

                Assert.IsFalse(wrapped.SequencedEquals(other));
                j = 30;
                Assert.AreEqual(true, wrapped.Show(new System.Text.StringBuilder(), ref j, null));
                wrapped.Sort();
                Assert.AreEqual("[ 0:4, 1:5, 2:6 ]", wrapped.ToString());
                Assert.IsTrue(IC.eq(wrapped.ToArray(), 4, 5, 6));
                Assert.AreEqual("[ ... ]", wrapped.ToString("L4", null));
                Assert.AreEqual(outerwrapped, wrapped.Underlying);
                Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6));
                Assert.IsTrue(wrapped.UnsequencedEquals(other));
                //
                Assert.IsTrue(wrapped.TrySlide(1));
                Assert.IsTrue(IC.eq(wrapped, 5, 6, 7));
                Assert.IsTrue(wrapped.TrySlide(-1, 2));
                Assert.IsTrue(IC.eq(wrapped, 4, 5));
                Assert.IsFalse(wrapped.TrySlide(-2));
                Assert.IsTrue(IC.eq(wrapped.Span(outerwrapped.ViewOf(7)), 4, 5, 6, 7));
                //
                wrapped.Shuffle();
                Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5));
                Assert.IsTrue(wrapped.IsValid);
                wrapped.Dispose();
                Assert.IsFalse(wrapped.IsValid);
            }
示例#12
0
文件: WrappersTest.cs 项目: suzuke/C5
            public void View()
            {
                int[] inner = new int[] { 3, 4, 6, 5, 7 };
                WrappedArray <int> outerwrapped = new WrappedArray <int>(inner, MemoryType);
                WrappedArray <int> wrapped      = (WrappedArray <int>)outerwrapped.View(1, 3);

                //
                Assert.AreEqual(6, wrapped[1]);
                Assert.IsTrue(IC.eq(wrapped[1, 2], 6, 5));
                //
                Func <int, bool> is4 = delegate(int i) { return(i == 4); };

                Assert.AreEqual(EventTypeEnum.None, wrapped.ActiveEvents);
                Assert.AreEqual(false, wrapped.All(is4));
                Assert.AreEqual(true, wrapped.AllowsDuplicates);
                wrapped.Apply(delegate(int i) { });
                Assert.AreEqual("{ 5, 6, 4 }", wrapped.Backwards().ToString());
                Assert.AreEqual(true, wrapped.Check());
                wrapped.Choose();
                Assert.AreEqual(true, wrapped.Contains(4));
                Assert.AreEqual(true, wrapped.ContainsAll(new ArrayList <int>()));
                Assert.AreEqual(1, wrapped.ContainsCount(4));
                Assert.AreEqual(Speed.Linear, wrapped.ContainsSpeed);
                int[] extarray = new int[5];
                wrapped.CopyTo(extarray, 1);
                Assert.IsTrue(IC.eq(extarray, 0, 4, 6, 5, 0));
                Assert.AreEqual(3, wrapped.Count);
                Assert.AreEqual(Speed.Constant, wrapped.CountSpeed);
                Assert.AreEqual(EnumerationDirection.Forwards, wrapped.Direction);
                Assert.AreEqual(false, wrapped.DuplicatesByCounting);
                Assert.AreEqual(System.Collections.Generic.EqualityComparer <int> .Default, wrapped.EqualityComparer);
                Assert.AreEqual(true, wrapped.Exists(is4));

                // The following condition can be tested only if we are not in memory strict mode.
                // the reason behind that is that the method Filter is not memory safe and thus
                // will cannot be used in MemoryType.Strict (it will raise an exception)
                if (MemoryType != MemoryType.Strict)
                {
                    Assert.IsTrue(IC.eq(wrapped.Filter(is4), 4));
                }

                int j = 5;

                Assert.AreEqual(true, wrapped.Find(ref j));
                Assert.AreEqual(true, wrapped.Find(is4, out j));
                Assert.AreEqual("[ 0:4 ]", wrapped.FindAll(is4).ToString());
                Assert.AreEqual(0, wrapped.FindIndex(is4));
                Assert.AreEqual(true, wrapped.FindLast(is4, out j));
                Assert.AreEqual(0, wrapped.FindLastIndex(is4));
                Assert.AreEqual(4, wrapped.First);

                // the using below is needed when testing MemoryType.Strict. In this memory mode
                // only one enumerator per collection is available. Requesting more than one enumerator
                // in this specific memory mode will raise an exception
                using (wrapped.GetEnumerator())
                {
                }
                Assert.AreEqual(CHC.sequencedhashcode(4, 6, 5), wrapped.GetSequencedHashCode());
                Assert.AreEqual(CHC.unsequencedhashcode(4, 6, 5), wrapped.GetUnsequencedHashCode());
                Assert.AreEqual(Speed.Constant, wrapped.IndexingSpeed);
                Assert.AreEqual(2, wrapped.IndexOf(5));
                Assert.AreEqual(false, wrapped.IsEmpty);
                Assert.AreEqual(true, wrapped.IsReadOnly);
                Assert.AreEqual(false, wrapped.IsSorted());
                Assert.AreEqual(true, wrapped.IsValid);
                Assert.AreEqual(5, wrapped.Last);
                Assert.AreEqual(2, wrapped.LastIndexOf(5));
                Assert.AreEqual(EventTypeEnum.None, wrapped.ListenableEvents);
                Func <int, string> i2s = delegate(int i) { return(string.Format("T{0}", i)); };

                Assert.AreEqual("[ 0:T4, 1:T6, 2:T5 ]", wrapped.Map <string>(i2s).ToString());
                Assert.AreEqual(1, wrapped.Offset);
                wrapped.Reverse();
                Assert.AreEqual("[ 0:5, 1:6, 2:4 ]", wrapped.ToString());
                IList <int> other = new ArrayList <int>(); other.AddAll(new int[] { 4, 5, 6 });

                Assert.IsFalse(wrapped.SequencedEquals(other));
                j = 30;
                Assert.AreEqual(true, wrapped.Show(new System.Text.StringBuilder(), ref j, null));
                wrapped.Sort();
                Assert.AreEqual("[ 0:4, 1:5, 2:6 ]", wrapped.ToString());
                Assert.IsTrue(IC.eq(wrapped.ToArray(), 4, 5, 6));
                Assert.AreEqual("[ ... ]", wrapped.ToString("L4", null));
                // TODO: Below line removed as NUnit 3.0 test fails trying to enumerate...
                // Assert.AreEqual(outerwrapped, wrapped.Underlying);
                Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6));
                Assert.IsTrue(wrapped.UnsequencedEquals(other));
                //
                Assert.IsTrue(wrapped.TrySlide(1));
                Assert.IsTrue(IC.eq(wrapped, 5, 6, 7));
                Assert.IsTrue(wrapped.TrySlide(-1, 2));
                Assert.IsTrue(IC.eq(wrapped, 4, 5));
                Assert.IsFalse(wrapped.TrySlide(-2));
                Assert.IsTrue(IC.eq(wrapped.Span(outerwrapped.ViewOf(7)), 4, 5, 6, 7));
                //
                wrapped.Shuffle();
                Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5));
                Assert.IsTrue(wrapped.IsValid);
                wrapped.Dispose();
                Assert.IsFalse(wrapped.IsValid);
            }