예제 #1
0
파일: WrappersTest.cs 프로젝트: sestoft/C5
            public void WithExc()
            {
                WrappedArray <int> wrapped = new WrappedArray <int>(new int[] { 3, 4, 6, 5, 7 });

                //
                try { wrapped.Add(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.AddAll(null); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Clear(); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Dispose(); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                int j = 1;

                try { wrapped.FindOrAdd(ref j); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Insert(1, 1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Insert(wrapped.View(0, 0), 1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.InsertAll(1, null); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.InsertFirst(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.InsertLast(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Remove(); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Remove(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveAll(null); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveAllCopies(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveAt(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveFirst(); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveInterval(0, 0); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RemoveLast(); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.RetainAll(null); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.Update(1, out j); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
                try { wrapped.UpdateOrAdd(1); Assert.Fail("No throw"); }
                catch (FixedSizeCollectionException) { }
            }
예제 #2
0
 public void WithExc()
 {
     WrappedArray<int> wrapped = new WrappedArray<int>(new int[] { 3, 4, 6, 5, 7 });
     //
     try { wrapped.Add(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.AddAll(null); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Clear(); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Dispose(); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     int j = 1;
     try { wrapped.FindOrAdd(ref j); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Insert(1, 1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Insert(wrapped.View(0, 0), 1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.InsertAll(1, null); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.InsertFirst(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.InsertLast(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Remove(); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Remove(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveAll(null); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveAllCopies(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveAt(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveFirst(); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveInterval(0, 0); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RemoveLast(); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.RetainAll(null); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.Update(1, out j); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
     try { wrapped.UpdateOrAdd(1); Assert.Fail("No throw"); }
     catch (FixedSizeCollectionException) { }
 }
예제 #3
0
파일: WrappersTest.cs 프로젝트: sestoft/C5
            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));
                //
                bool is4(int i)
                {
                    return(i == 4);
                }

                Assert.AreEqual(EventType.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));
                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(EventType.None, wrapped.ListenableEvents);
                string i2s(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);
            }
예제 #4
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);
            }