예제 #1
0
 public void SeqequalityComparerViaBuilder3()
 {
     SCG.IEqualityComparer <C5.IList <int> > h = C5.EqualityComparer <C5.IList <int> > .Default;
     C5.IList <int> s = new LinkedList <int>();
     s.Add(1); s.Add(2); s.Add(3);
     Assert.AreEqual(CHC.sequencedhashcode(1, 2, 3), h.GetHashCode(s));
 }
예제 #2
0
            public void SeqequalityComparerViaBuilder4()
            {
                SCG.IEqualityComparer <IBaz> h = C5.EqualityComparer <IBaz> .Default;
                IBaz s = new Baz();

                s.Add(1); s.Add(2); s.Add(3);
                Assert.AreEqual(CHC.sequencedhashcode(1, 2, 3), h.GetHashCode(s));
            }
예제 #3
0
파일: BasesTest.cs 프로젝트: 15139288365/C5
            public void SeqequalityComparerViaBuilder2()
            {
                SCG.IEqualityComparer <LinkedList <int> > h = C5.EqualityComparer <LinkedList <int> > .Default;
                LinkedList <int> s = new LinkedList <int>()
                {
                    1, 2, 3
                };

                Assert.AreEqual(CHC.sequencedhashcode(1, 2, 3), h.GetHashCode(s));
            }
예제 #4
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);
            }
예제 #5
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);
            }