public void MultipleSeparateEnumeration() { WrappedArray <int> wrapped = new WrappedArray <int>(new int[] { 4, 6, 5 }, MemoryType); int j = 0; foreach (var item in wrapped) { j++; } Assert.AreEqual(j, 3); j = 0; foreach (var item2 in wrapped) { switch (j) { case 0: Assert.AreEqual(item2, 4); break; case 1: Assert.AreEqual(item2, 6); break; case 2: Assert.AreEqual(item2, 5); break; } j++; } Assert.AreEqual(j, 3); }
public void TryWrappedArrayAsSCIList1() { B[] myarray = new B[] { new B(), new B(), new C() }; System.Collections.IList list = new WrappedArray <B>(myarray); // Should be called with a three-element WrappedArray<B> Assert.AreEqual(3, list.Count); Assert.IsTrue(list.IsFixedSize); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Assert.AreEqual(myarray.SyncRoot, list.SyncRoot); Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C(); list[0] = b2; Assert.AreEqual(b2, list[0]); list[1] = c2; Assert.AreEqual(c2, list[1]); Assert.IsTrue(list.Contains(b2)); Assert.IsTrue(list.Contains(c2)); Array arrA = new A[3], arrB = new B[3]; list.CopyTo(arrA, 0); list.CopyTo(arrB, 0); Assert.AreEqual(b2, arrA.GetValue(0)); Assert.AreEqual(b2, arrB.GetValue(0)); Assert.AreEqual(c2, arrA.GetValue(1)); Assert.AreEqual(c2, arrB.GetValue(1)); Assert.AreEqual(0, list.IndexOf(b2)); Assert.AreEqual(-1, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c1)); Assert.IsFalse(list.Contains(b1)); Assert.IsFalse(list.Contains(c1)); }
public void ViewWithExc() { 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); // 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) { } //Should not throw //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) { } }
//Takes HexData object and serializes it, which converts it to binary, feeds that into a printstream public static void SaveMap(Hex[,] hexes) { var xx = WrappedArray.Wrap(hexes); Debug.Log(hexes.ToString() + xx.Hexes.Length); Debug.Log(xx.Hexes[0].ToString()); string serialized = JsonUtility.ToJson(xx, true); string path = Path.Combine(Application.persistentDataPath, "HexMap.xd"); Debug.Log("SaveMap " + path); Debug.Log(serialized); File.WriteAllText(path, serialized); }
public override void Initialize() { int size = (int)cfg.getDouble("size", 10); sampleTime = Time.fromSeconds(cfg.getDouble("timeSec", 5 * 60)); prices1 = new WrappedArray<FixedPointDecimal>(size); prices2 = new WrappedArray<FixedPointDecimal>(size); Id id2 = env.GetIdService().GetId(cfg.getString("ref"), cfg.getEnum<SymbolType>("symbolType")); instr2 = env.GetUniverseService().GetInstrument(id2); env.Scheduler.ScheduleAfterBackground(sampleTime, sample); }
public void WithExc() { WrappedArray <int> wrapped = new WrappedArray <int>(new int[] { 3, 4, 6, 5, 7 }, MemoryType); // 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) { } }
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)); } }
public void TryWrappedArrayAsSCIList2() { B[] myarray = new B[] { }; System.Collections.IList list = new WrappedArray <B>(myarray); // Should be called with an empty WrappedArray<B> Assert.AreEqual(0, list.Count); list.CopyTo(new A[0], 0); list.CopyTo(new B[0], 0); list.CopyTo(new C[0], 0); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C(); Assert.IsFalse(list.Contains(b2)); Assert.IsFalse(list.Contains(c2)); Assert.AreEqual(-1, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c1)); }
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)); // 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)); 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); 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)); 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); }
public void ViewWithExc() { 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); // 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) { } //Should not throw //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) { } }
// System.Array.FindLastIndex(T[], int, int, Predicate) public static int FindLastIndex <T>(T[] arr, int i, int n, Func <T, bool> p) { var j = new WrappedArray <T>(arr).View(i, n).FindIndex(p); return(j < 0 ? j : j + i); }
// System.Array.IndexOf(T[], T) public static int IndexOf <T>(T[] arr, T x) { var j = new WrappedArray <T>(arr).IndexOf(x); return(j < 0 ? -1 : j); }
// System.Array.IndexOf(T[], T, int) public static int IndexOf <T>(T[] arr, T x, int i) { var j = new WrappedArray <T>(arr).View(i, arr.Length - i).IndexOf(x); return(j < 0 ? -1 : j + i); }
// System.Array.LastIndexOf(T[], T, int, int) public static int LastIndexOf <T>(T[] arr, T x, int i, int n) { var j = new WrappedArray <T>(arr).View(i, n).LastIndexOf(x); return(j < 0 ? -1 : j + i); }
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); }
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)); } }
public void WithExc() { WrappedArray<int> wrapped = new WrappedArray<int>(new int[] { 3, 4, 6, 5, 7 }, MemoryType); // 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) { } }
public void NoExc() { WrappedArray <int> wrapped = new WrappedArray <int>(new int[] { 4, 6, 5 }); 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(0, 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(null, wrapped.Underlying); Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6)); Assert.IsTrue(wrapped.UnsequencedEquals(other)); wrapped.Shuffle(); Assert.IsTrue(IC.seteq(wrapped.UniqueItems(), 4, 5, 6)); }
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); }
public void TryWrappedArrayAsSCIList1() { B[] myarray = new B[] { new B(), new B(), new C() }; System.Collections.IList list = new WrappedArray<B>(myarray); // Should be called with a three-element WrappedArray<B> Assert.AreEqual(3, list.Count); Assert.IsTrue(list.IsFixedSize); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Assert.AreEqual(myarray.SyncRoot, list.SyncRoot); Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C(); list[0] = b2; Assert.AreEqual(b2, list[0]); list[1] = c2; Assert.AreEqual(c2, list[1]); Assert.IsTrue(list.Contains(b2)); Assert.IsTrue(list.Contains(c2)); Array arrA = new A[3], arrB = new B[3]; list.CopyTo(arrA, 0); list.CopyTo(arrB, 0); Assert.AreEqual(b2, arrA.GetValue(0)); Assert.AreEqual(b2, arrB.GetValue(0)); Assert.AreEqual(c2, arrA.GetValue(1)); Assert.AreEqual(c2, arrB.GetValue(1)); Assert.AreEqual(0, list.IndexOf(b2)); Assert.AreEqual(-1, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c1)); Assert.IsFalse(list.Contains(b1)); Assert.IsFalse(list.Contains(c1)); }
/// <summary> /// Extension method to perform sync/async version of DataServiceContext.Execute dynamically /// </summary> /// <typeparam name="TElement">The element type of the wrapped query results</typeparam> /// <param name="context">The context to call execute on</param> /// <param name="continuation">The asynchronous continuation</param> /// <param name="async">A value indicating whether or not to use async API</param> /// <param name="elementType">The element type of the query results</param> /// <param name="requestUri">The uri to make a request to</param> /// <param name="httpMethod">The HttpMethod to make a request</param> /// <param name="singleResult">Whether expect single item in result</param> /// <param name="operationParameters">Parameter for the request</param> /// <param name="onCompletion">A callback for when the call completes</param> public static void Execute <TElement>(this WrappedDataServiceContext context, IAsyncContinuation continuation, bool async, Type elementType, System.Uri requestUri, string httpMethod, bool singleResult, WrappedArray <WrappedOperationParameter> operationParameters, Action <WrappedIEnumerable <TElement> > onCompletion) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(context, "context"); AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedIEnumerable <TElement> >( continuation, async, () => context.Execute <TElement>(elementType, requestUri, httpMethod, singleResult, operationParameters), c => context.BeginExecute <TElement>(elementType, requestUri, c, null, httpMethod, singleResult, operationParameters), r => context.EndExecute <TElement>(elementType, r), onCompletion); }
/// <summary> /// Extension method to perform sync/async version of DataServiceContext.Execute dynamically /// </summary> /// <param name="context">The context to call execute on</param> /// <param name="continuation">The asynchronous continuation</param> /// <param name="async">A value indicating whether or not to use async API</param> /// <param name="requestUri">The uri to make a request to</param> /// <param name="httpMethod">The HttpMethod to make a request</param> /// <param name="operationParameters">Parameter for the request</param> /// <param name="onCompletion">A callback for when the call completes</param> public static void Execute(this WrappedDataServiceContext context, IAsyncContinuation continuation, bool async, System.Uri requestUri, string httpMethod, WrappedArray <WrappedOperationParameter> operationParameters, Action <WrappedObject> onCompletion) { ExceptionUtilities.CheckArgumentNotNull(context, "context"); // because EndExecute is reused for the async version, we need to do some work to get the right return type AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedObject>( continuation, async, () => context.Execute(requestUri, httpMethod, operationParameters), c => context.BeginExecute(requestUri, c, null, httpMethod, operationParameters), r => new WrappedObject(context.Scope, context.EndExecute(r).Product), onCompletion); }
/// <summary> /// Extension method to perform sync/async version of DataServiceContext.ExecuteBatch dynamically /// </summary> /// <param name="context">The context to call execute batch on</param> /// <param name="continuation">The asynchronous continuation</param> /// <param name="async">A value indicating whether or not to use async API</param> /// <param name="queries">The queries to execute</param> /// <param name="onCompletion">A callback for when the call completes</param> public static void ExecuteBatch(this WrappedDataServiceContext context, IAsyncContinuation continuation, bool async, WrappedArray <WrappedDataServiceRequest> queries, Action <WrappedDataServiceResponse> onCompletion) { ExceptionUtilities.CheckArgumentNotNull(context, "context"); AsyncHelpers.InvokeSyncOrAsyncMethodCall <WrappedDataServiceResponse>(continuation, async, () => context.ExecuteBatch(queries), c => context.BeginExecuteBatch(c, null, queries), r => context.EndExecuteBatch(r), onCompletion); }
public void TryWrappedArrayAsSCIList2() { B[] myarray = new B[] { }; System.Collections.IList list = new WrappedArray<B>(myarray); // Should be called with an empty WrappedArray<B> Assert.AreEqual(0, list.Count); list.CopyTo(new A[0], 0); list.CopyTo(new B[0], 0); list.CopyTo(new C[0], 0); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Object b1 = new B(), b2 = new B(), c1 = new C(), c2 = new C(); Assert.IsFalse(list.Contains(b2)); Assert.IsFalse(list.Contains(c2)); Assert.AreEqual(-1, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c1)); }
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); }
public GridComputer(int size, double returnThreshold = 0) { this.returnThreshold = returnThreshold; this.prices = new WrappedArray<FixedPointDecimal>(size); this.times = new WrappedArray<Time>(size); }
public void MultipleSeparateEnumeration() { WrappedArray<int> wrapped = new WrappedArray<int>(new int[] { 4, 6, 5 }, MemoryType); int j = 0; foreach (var item in wrapped) { j++; } Assert.AreEqual(j, 3); j = 0; foreach (var item2 in wrapped) { switch (j) { case 0: Assert.AreEqual(item2, 4); break; case 1: Assert.AreEqual(item2, 6); break; case 2: Assert.AreEqual(item2, 5); break; } j++; } Assert.AreEqual(j, 3); }