public static void Main(String[] args) { IList <int> list = new ArrayList <int>(); list.AddAll(new[] { 23, 29, 31, 37, 41, 43, 47, 53 }); // Reversing and swapping Console.WriteLine(list); list.Reverse(); Console.WriteLine(list); ReverseInterval(list, 2, 3); Console.WriteLine(list); SwapInitialFinal(list, 2); Console.WriteLine(list); // Clearing all or part of list list.CollectionCleared += delegate(Object c, ClearedEventArgs eargs) { ClearedRangeEventArgs ceargs = eargs as ClearedRangeEventArgs; if (ceargs != null) { Console.WriteLine("Cleared [{0}..{1}]", ceargs.Start, ceargs.Start + ceargs.Count - 1); } }; RemoveSublist1(list, 1, 2); Console.WriteLine(list); RemoveSublist2(list, 1, 2); Console.WriteLine(list); RemoveTail1(list, 3); Console.WriteLine(list); RemoveTail2(list, 2); Console.WriteLine(list); }
public static void UnindexedCollectionEvents() { ICollection <int> coll = new ArrayList <int>(); ICollection <int> bag1 = new HashBag <int>(); bag1.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 }); // Add change handler coll.CollectionChanged += o => Console.WriteLine("Collection changed"); // Add cleared handler coll.CollectionCleared += (o, a) => Console.WriteLine("Collection cleared"); // Add added handler coll.ItemsAdded += (o, args) => Console.WriteLine($"Item {args.Item} added"); // Add item count handler AddItemsAddedCounter(coll); AddItemsRemovedCounter(coll); coll.AddAll(bag1); coll.RemoveAll(new[] { 2, 5, 6, 3, 7, 2 }); coll.Clear(); ICollection <int> bag2 = new HashBag <int>(); // Add added handler with multiplicity bag2.ItemsAdded += (o, args) => Console.WriteLine($"{args.Count} copies of {args.Item} added"); bag2.AddAll(bag1); // Add removed handler with multiplicity bag2.ItemsRemoved += (o, args) => Console.WriteLine($"{args.Count} copies of {args.Item} removed"); bag2.RemoveAllCopies(7); }
public static void Main(String[] args) { ArrayList <int> list = new ArrayList <int>(), copy1, copy2; list.AddAll(new[] { 2, 3, 5, 7, 11, 13, 17, 19 }); copy1 = new ArrayList <int>(); copy1.AddAll(list); copy2 = new ArrayList <int>(); copy2.AddAll(list); const int N = 7; Console.WriteLine("-- With replacement:"); foreach (int x in RandomWith(list, N)) { Console.Write("{0} ", x); } Console.WriteLine("\n-- Without replacement:"); foreach (int x in RandomWithout1(copy1, N)) { Console.Write("{0} ", x); } Console.WriteLine("\n-- Without replacement:"); foreach (int x in RandomWithout2(copy2, N)) { Console.Write("{0} ", x); } Console.WriteLine(); }
public void TryViewOfGuardedListAsSCIList1() { B b1_ = new B(), b2_ = new B(); C c1_ = new C(), c2_ = new C(); ArrayList <B> mylist = new ArrayList <B>(); mylist.AddAll(new B[] { new B(), b1_, b2_, c1_, new B() }); System.Collections.IList list = new GuardedList <B>(mylist).View(1, 3); Object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_; // Should be called with a three-element view of a GuardedList<B> Assert.AreEqual(3, list.Count); Assert.IsTrue(list.IsFixedSize); Assert.IsTrue(list.IsReadOnly); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Assert.AreEqual(list.SyncRoot, ((System.Collections.IList)mylist).SyncRoot); Assert.IsTrue(list.Contains(b1)); Assert.IsTrue(list.Contains(b2)); Assert.IsTrue(list.Contains(c1)); Assert.IsFalse(list.Contains(c2)); Array arrA = new A[3], arrB = new B[3]; list.CopyTo(arrA, 0); list.CopyTo(arrB, 0); Assert.AreEqual(b1, arrA.GetValue(0)); Assert.AreEqual(b1, arrB.GetValue(0)); Assert.AreEqual(b2, arrA.GetValue(1)); Assert.AreEqual(b2, arrB.GetValue(1)); Assert.AreEqual(0, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c2)); }
public static void Main() { IList <bool> list = new ArrayList <bool>(); list.AddAll(new bool[] { false, false, true, true, false }); list.CollectionCleared += delegate(Object coll, ClearedEventArgs args) { ClearedRangeEventArgs crargs = args as ClearedRangeEventArgs; if (crargs != null) { Console.WriteLine("Cleared {0} to {1}", crargs.Start, crargs.Start + crargs.Count - 1); } else { Console.WriteLine("Cleared {0} items", args.Count); } }; list.RemoveInterval(2, 2); HashSet <int> hash = new HashSet <int>(); hash.ItemsRemoved += delegate { Console.WriteLine("Item was removed"); }; hash.ItemsAdded += delegate { Console.WriteLine("Item was added"); }; hash.UpdateOrAdd(2); hash.UpdateOrAdd(2); }
public void AddAllToIndexTest(int[] original, int index, int[] values, int[] expected) { ArrayList list = new ArrayList(original); list.AddAll(index, values); Assert.AreEqual(expected, list.GetArrayList()); }
protected override IList<Collider> Detect() { var detected = Physics.OverlapSphere(Vehicle.Position, _detectionRadius, LayersChecked); var list = new ArrayList<Collider>(); list.AddAll<Collider>(detected); return list; }
public static void Main(String[] args) { String[] cities = { "Tokyo", "Beijing", "Hangzhou", "Kyoto", "Beijing", "Copenhagen", "Seattle" }; IList <String> alst = new ArrayList <String>(); alst.AddAll(cities); foreach (int i in MySort.GetPermutation1(alst)) { Console.Write("{0} ", i); } Console.WriteLine(); IList <String> llst = new LinkedList <String>(); llst.AddAll(cities); foreach (int i in MySort.GetPermutation2(llst)) { Console.Write("{0} ", i); } Console.WriteLine(); Console.WriteLine("The rank of the cities:"); ArrayList <int> res = MySort.GetPermutation1(MySort.GetPermutation2(llst)); foreach (int i in res) { Console.Write("{0} ", i); } Console.WriteLine(); }
/// <summary> /// Checks the board against all of the current prayers /// and initiates the construction phase. /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void CheckLayout(int x, int y) { // Ignore empty prayers if (Game.State.Prayers.Count == 0) { return; } // We want to loop through the prayers ArrayList <Prayer> tmpPrayers = new ArrayList <Prayer>(); tmpPrayers.AddAll(Game.State.Prayers); foreach (Prayer prayer in tmpPrayers) { // Don't bother if we haven't been accepted if (!prayer.IsAccepted) { continue; } // Check the layout, if it returns true, we are done if (CheckLayouts(x, y, prayer)) { return; } } }
private void RandomBoardLayout(SCG.IEnumerable<Tile> tiles, SCG.IEnumerable<HexTile> hexes, int x1, int y1, int x2, int y2, int maxd1, int maxd2) { IList<HexTile> hexRandom = new ArrayList<HexTile>(); hexRandom.AddAll(from hex in hexes orderby RNG.Next() select hex); foreach (var t in tiles) { var d1 = this.tiles[x1][y1].DistanceTo(t); var d2 = this.tiles[x2][y2].DistanceTo(t); if (d1 == maxd1 && d2 >= maxd2 + 1 || d1 >= maxd1 + 1 && d2 == maxd2 || d1 == maxd1 + 1 && d2 == maxd2 + 1) { t.HexTile = new OceanHexTile(); } else if (d1 <= maxd1 && d2 <= maxd2) { if (hexRandom.Count == 0) { t.HexTile = new DesertHexTile(""); } else { t.HexTile = hexRandom.RemoveLast(); } } else { t.HexTile = null; } } }
public void AddAll() { for (int i = 0; i < 10; i++) { list.Add(10 * i + 5); } listen(); list.AddAll(new int[] { 45, 56, 67 }); seen.Check(new CollectionEvent <int>[] { new CollectionEvent <int>(EventType.Added, new ItemCountEventArgs <int>(45, 1), guarded), new CollectionEvent <int>(EventType.Added, new ItemCountEventArgs <int>(56, 1), guarded), new CollectionEvent <int>(EventType.Added, new ItemCountEventArgs <int>(67, 1), guarded), new CollectionEvent <int>(EventType.Changed, new EventArgs(), guarded) }); list.AddAll(new int[] { }); seen.Check(new CollectionEvent <int>[] { }); }
protected override IList <Collider> Detect() { var detected = Physics.OverlapSphere(Vehicle.Position, _detectionRadius, LayersChecked); var list = new ArrayList <Collider>(); list.AddAll <Collider>(detected); return(list); }
protected override IList <Collider> Detect() { Collider[] items = Physics.OverlapSphere(base.Vehicle.Position, this._detectionRadius, base.LayersChecked); ArrayList <Collider> arrayList = new ArrayList <Collider>(); arrayList.AddAll <Collider>(items); return(arrayList); }
public void Search_Test(int[] array, int val, int[] expected) { ArrayList list = new ArrayList(); list.AddAll(array); int[] actual = list.Search(val); Assert.AreEqual(expected, actual); }
public void AddAll_Test(int[] array, int index, int[] expected) { ArrayList list = new ArrayList(); list.AddAll(array, index); int[] actual = list.GetArray(); Assert.AreEqual(expected, actual); }
public void AddAll_at_index_Test(int[] array, int[] newarray, int[] expected, int idx) { ArrayList list = new ArrayList(array); list.AddAll(idx, newarray); int[] actual = list.GetArray(); Assert.AreEqual(expected, actual); }
public static void Main() { IList <char> lst = new ArrayList <char>(); lst.AddAll(new char[] { 'a', 'b', 'c', 'd' }); IList <char> v1 = lst.View(1, 1); Console.WriteLine("v1 = {0}", v1); InsertBeforeFirst(v1, '<', 'b'); InsertAfterFirst(v1, '>', 'b'); Console.WriteLine("v1 = {0}", v1); if (SequencePredecessor(v1, 'b', out char x)) { Console.WriteLine("Predecessor of b is " + x); } if (SequenceSuccessor(v1, 'b', out x)) { Console.WriteLine("Successor of b is " + x); } if (!SequencePredecessor(v1, 'c', out _)) { Console.WriteLine("c has no predecessor"); } if (!SequenceSuccessor(v1, 'a', out _)) { Console.WriteLine("a has no successor"); } IList <char> lst2 = new ArrayList <char>(); lst2.AddAll(new char[] { 'a', 'b', 'c', 'A', 'a', 'd', 'a' }); foreach (var i in IndexesOf(lst2, 'a')) { Console.Write("{0} ", i); } Console.WriteLine(); foreach (var i in ReverseIndexesOf(lst2, 'a')) { Console.Write("{0} ", i); } Console.WriteLine(); Console.WriteLine(lst2); IList <char> view = lst2.View(2, 0); InsertAtView(lst2, view, 'y'); Console.WriteLine(lst2); InsertIntoView(view, 'x'); Console.WriteLine(lst2); }
public void RemoveVal_Test(int[] array, int val, int[] expected) { ArrayList list = new ArrayList(); list.AddAll(array); list.Remove(val); int[] actual = list.GetArray(); Assert.AreEqual(expected, actual); }
public void Size_Test(int[] array, int expected) { ArrayList list = new ArrayList(); list.AddAll(array); int actual = list.Size(); Assert.AreEqual(expected, actual); }
public void Contains_Test(int[] array, int val, bool expected) { ArrayList list = new ArrayList(); list.AddAll(array); bool actual = list.Contains(val); Assert.AreEqual(expected, actual); }
public void IndexOf_Test(int[] array, int val, int expected) { ArrayList list = new ArrayList(); list.AddAll(array); int actual = list.IndexOf(val); Assert.AreEqual(expected, actual); }
public IList <UInt64> GetIDs() { IList <UInt64> keys = new ArrayList <UInt64>(); this.lReadWriteLock.AcquireReaderLock(30); keys.AddAll(this.mTunnels.Keys.ToArray()); this.lReadWriteLock.ReleaseLock(); return(keys); }
public void AddVal_Test2(int[] enter, int[] expected, int val) { ArrayList list = new ArrayList(); list.AddAll(enter); list.Add(val); int[] actual = list.GetArray(); Assert.AreEqual(expected, actual); }
public Script(SCG.IEnumerable <IScriptAtom> atoms) { ContractsCommon.NotNull(atoms, "atoms"); var newAtoms = new ArrayList <IScriptAtom>(); newAtoms.AddAll(atoms); newAtoms.CollectionChanged += AtomsChanged; Atoms = newAtoms; }
public Script(Script script) { ContractsCommon.NotNull(script, "script"); var atoms = new ArrayList <IScriptAtom>(script.Atoms.Count); atoms.AddAll(script.Atoms); atoms.CollectionChanged += AtomsChanged; Atoms = atoms; }
public async Task<LiveConnectSession> LogonAsync() { var scopes = new ArrayList(); scopes.AddAll(requestedScopes); var client = new LiveAuthClient(activity, CLIENTID); var loginAuthListener = new OneDriveAuthListener(); client.Login(activity, scopes, loginAuthListener); return await loginAuthListener.Task; }
public static void Main(String[] args) { IList<int> lst = new ArrayList<int>(); lst.AddAll(new[] { 2, 3, 5, 7, 11, 13 }); Console.WriteLine(lst); IList<int> v1 = lst.ViewOf(7); Console.WriteLine(v1); IList<int> v2 = (IList<int>)v1.Clone(); v2.Slide(1); Console.WriteLine(v1); Console.WriteLine(v2); }
private static BufferedImage MPIMaster(RGBDisplayModel model, int mask) { int n = Communicator.world.Size; ArrayList <BufferedImage> chunks = model.splitImage(model.getOriginalImage(), 100); for (int i = 1; i < n; i++) { ArrayList <ImageIcon> imageList = new ArrayList <ImageIcon>(); for (int j = 1; j < n; j++) { try { imageList.Add(new ImageIcon(chunks[(i - 1) * (n - 1) + (j - 1)])); } catch { Exception e; } { } } Communicator.world.Send(imageList, i, 0); Communicator.world.Send(mask, i, 0); } ArrayList <ImageIcon> resultsIcon = new ArrayList <ImageIcon>(); for (int i = 1; i < n; i++) { ArrayList <ImageIcon> aux = Communicator.world.Receive <ArrayList <ImageIcon> >(i, 0); resultsIcon.AddAll(aux); } ArrayList <BufferedImage> results = new ArrayList <BufferedImage>(); //Convert imageIcon to BufferedImage foreach (ImageIcon image in resultsIcon) { results.Add(convertToBufferedImage(image.getImage())); } BufferedImage resultImage = new BufferedImage(model.getOriginalImage().getWidth(), model.getOriginalImage().getHeight(), model.getOriginalImage().getType()); int howManyOnLine = (int)Math.Sqrt(results.ToArray().Length); for (int i = 0; i < howManyOnLine; i++) { for (int j = 0; j < howManyOnLine; j++) { resultImage.createGraphics().drawImage(results.ElementAt(i * howManyOnLine + j), 100 * i, 100 * j, null); } } return(resultImage); }
public static ArrayList <ArrayList <T> > CreateFrom2DArray <T>(T[][] arrays) { var arrayLists = new ArrayList <ArrayList <T> >(); foreach (T[] array in arrays) { var arrayList = new ArrayList <T>(); arrayList.AddAll(array); arrayLists.Add(arrayList); } return(arrayLists); }
public static bool seteq(ICollectionValue <KeyValuePair <int, int> > me, params int[] that) { ArrayList <KeyValuePair <int, int> > first = new ArrayList <KeyValuePair <int, int> >(); first.AddAll(me); ArrayList <KeyValuePair <int, int> > other = new ArrayList <KeyValuePair <int, int> >(); for (int i = 0; i < that.Length; i += 2) { other.Add(new KeyValuePair <int, int>(that[i], that[i + 1])); } return(other.UnsequencedEquals(first)); }
public void AddAllToIndexTestException(int[] original, int index, int[] values) { ArrayList list = new ArrayList(original); try { list.AddAll(index, values); }catch (ArgumentException e) { return; } Assert.Fail(); }
private static ArrayList <Pose> reconstructPath(Node node) { LinkedList <Pose> path = new LinkedList <Pose>(); Node rsNode = null; int subpathCount = 0; while (node != null) { if (node.action != null) { path.InsertFirst(node.pose); } else { ArrayList <Pose> subpath = ReedsSheppDriver.Discretize(node.from.pose, node.actionSet, VehicleModel.TurnRadius, GridResolution); subpathCount = subpath.Count; for (int i = subpathCount - 1; i >= 1; i--) { path.InsertFirst(subpath[i]); } rsNode = node; } node = node.from; } ArrayList <Pose> pathArray = new ArrayList <Pose>(); pathArray.AddAll(path); if (rsNode != null) { rsNode.rsIndex = pathArray.Count - subpathCount; } // Move every node's gear to it's parent node int count = pathArray.Count; Gear nextGear = pathArray[count - 1].Gear; for (int i = count - 2; i >= 0; i--) { Pose curr = pathArray[i]; Gear currGear = curr.Gear; curr.Gear = nextGear; pathArray[i] = curr; nextGear = currGear; } return(pathArray); }
public static void UnindexedCollectionEvents() { ICollection <int> coll = new ArrayList <int>(); ICollection <int> bag1 = new HashBag <int>(); bag1.AddAll(new[] { 3, 2, 5, 5, 7, 7, 5, 3, 7, 7 }); // Add change handler coll.CollectionChanged += delegate(Object c) { Console.WriteLine("Collection changed"); }; // Add cleared handler coll.CollectionCleared += delegate(Object c, ClearedEventArgs args) { Console.WriteLine("Collection cleared"); }; // Add added handler coll.ItemsAdded += delegate(Object c, ItemCountEventArgs <int> args) { Console.WriteLine("Item {0} added", args.Item); }; // Add item count handler AddItemsAddedCounter(coll); AddItemsRemovedCounter(coll); coll.AddAll(bag1); coll.RemoveAll(new[] { 2, 5, 6, 3, 7, 2 }); coll.Clear(); ICollection <int> bag2 = new HashBag <int>(); // Add added handler with multiplicity bag2.ItemsAdded += delegate(Object c, ItemCountEventArgs <int> args) { Console.WriteLine("{0} copies of {1} added", args.Count, args.Item); }; bag2.AddAll(bag1); // Add removed handler with multiplicity bag2.ItemsRemoved += delegate(Object c, ItemCountEventArgs <int> args) { Console.WriteLine("{0} copies of {1} removed", args.Count, args.Item); }; bag2.RemoveAllCopies(7); }
public static void Main(String[] args) { IList <int> lst = new ArrayList <int>(); lst.AddAll(new int[] { 2, 3, 5, 7, 11, 13 }); Console.WriteLine(lst); IList <int> v1 = lst.ViewOf(7); Console.WriteLine(v1); IList <int> v2 = (IList <int>)v1.Clone(); v2.Slide(1); Console.WriteLine(v1); Console.WriteLine(v2); }
public static void Main(String[] args) { IList<String> names = new ArrayList<String>(); names.AddAll(new String[] { "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy" }); // Print list: Console.WriteLine(names); // Print item 1 ("Roosevelt") in the list: Console.WriteLine(names[1]); // Create a list view comprising post-WW2 presidents: IList<String> postWWII = names.View(2, 3); // Print item 2 ("Kennedy") in the view: Console.WriteLine(postWWII[2]); // Enumerate and print the list view in reverse chronological order: foreach (String name in postWWII.Backwards()) Console.WriteLine(name); }
public void Serialize() { var source = new ArrayList<int>(); source.AddAll(new[] { 1, 2, 3, 4, 5 }); ArrayList<int> target; var formatter = new BinaryFormatter(); using (var stream = new MemoryStream()) { formatter.Serialize(stream, source); stream.Position = 0; target = (ArrayList<int>) formatter.Deserialize(stream); } CollectionAssert.AreEqual(source, target); }
public static void Main(String[] args) { IList<int> list1 = new ArrayList<int>(); list1.AddAll(new int[] { 2, 5, 7, 11, 37 }); IList<int> list2 = new GuardedList<int>(list1); IList<int> gv = new GuardedList<int>(list1.View(1,2)), vg = list2.View(1,2); IList<int> gvu = gv.Underlying, vgu = vg.Underlying; Console.WriteLine(gvu); // Legal Console.WriteLine(vgu); // Legal // gv.Slide(+1); // Illegal: guarded view cannot be slid vg.Slide(+1); // Legal: view of guarded can be slid // gvu[1] = 9; // Illegal: list is guarded // vgu[1] = 9; // Illegal: list is guarded }
private IDotStatement ParseEdgeStatement(String fromNodeId) { ArrayList<DotEdge> edges = new ArrayList<DotEdge> (); ArrayList<DotEdge> currentEdges = new ArrayList<DotEdge> (); DotEdge currentEdge; var noMoreEdges = false; while (noMoreEdges == false) { while ((currentEdge = ParseEdge (fromNodeId)) != null) { currentEdges.Push (currentEdge); fromNodeId = currentEdge.ToNodeId; } var attributes = ParseAttributeList (); if (attributes != null) { foreach (var edge in currentEdges) edge.SetAttributes (attributes); } else { noMoreEdges = true; } edges.AddAll (currentEdges); currentEdges.Clear (); } return new DotEdgeStatement (edges); }
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 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 TryViewOfGuardedListAsSCIList1() { B b1_ = new B(), b2_ = new B(); C c1_ = new C(), c2_ = new C(); ArrayList<B> mylist = new ArrayList<B>(); mylist.AddAll(new B[] { new B(), b1_, b2_, c1_, new B()}); System.Collections.IList list = new GuardedList<B>(mylist).View(1, 3); Object b1 = b1_, b2 = b2_, c1 = c1_, c2 = c2_; // Should be called with a three-element view of a GuardedList<B> Assert.AreEqual(3, list.Count); Assert.IsTrue(list.IsFixedSize); Assert.IsTrue(list.IsReadOnly); Assert.IsFalse(list.IsSynchronized); Assert.AreNotEqual(null, list.SyncRoot); Assert.AreEqual(list.SyncRoot, ((System.Collections.IList)mylist).SyncRoot); Assert.IsTrue(list.Contains(b1)); Assert.IsTrue(list.Contains(b2)); Assert.IsTrue(list.Contains(c1)); Assert.IsFalse(list.Contains(c2)); Array arrA = new A[3], arrB = new B[3]; list.CopyTo(arrA, 0); list.CopyTo(arrB, 0); Assert.AreEqual(b1, arrA.GetValue(0)); Assert.AreEqual(b1, arrB.GetValue(0)); Assert.AreEqual(b2, arrA.GetValue(1)); Assert.AreEqual(b2, arrB.GetValue(1)); Assert.AreEqual(0, list.IndexOf(b1)); Assert.AreEqual(-1, list.IndexOf(c2)); }
private void RandomChitLayout(SCG.IEnumerable<Tile> tiles, SCG.IEnumerable<ProductionChit> chits) { foreach (var t in AllTiles) t.Chits.Clear(); IList<ProductionChit> chitRandom = new ArrayList<ProductionChit>(); chitRandom.AddAll(from chit in chits orderby RNG.Next() select chit); foreach (Tile h in (from t in tiles where t.HexTile != null && t.HexTile.IsLand && t.HexTile.TileType != Core.TileType.Desert select t)) { h.Chits.Add(chitRandom.RemoveLast()); } }
public static ArrayList<Pose> Smooth(ArrayList<Pose> path, ObstacleGrid grid, HashSet<int> unsafeIndices) { UnsafeIndices = Anchoring ? unsafeIndices : null; if (path.Count < 5) { ArrayList<Pose> thepath = new ArrayList<Pose>(); thepath.AddAll(path); return thepath; } int num = currentCount = path.Count; currentPath = new Pose[num]; for (int i = 0; i < num; i++) currentPath[i] = path[i]; int count = 0; float change = Tolerance; while (/*change >= Tolerance && */count < MaxIterations) { float cdmax2 = CollisionDmax * CollisionDmax; change = 0f; for (int i = 2; i < num - 2; i++) { // Keep this point fixed if it is or is adjacent to a cusp point if (currentPath[i - 2].Gear != currentPath[i - 1].Gear) continue; if (currentPath[i - 1].Gear != currentPath[i].Gear) continue; if (currentPath[i].Gear != currentPath[i + 1].Gear) continue; if (currentPath[i + 1].Gear != currentPath[i + 2].Gear) continue; // Keep this point fixed if it is unsafe if (Anchoring && unsafeIndices != null && unsafeIndices.Contains(i)) continue; Vector2 curr = currentPath[i].Position; Vector2 correction = Vector2.Zero; // Original path term correction += PathWeight * (path[i].Position - curr); if (float.IsNaN(correction.X) || float.IsNaN(correction.Y)) { float noop; } if (grid.IsPointInGrid(curr)) { // Collision term Vector2 closestObstacleVec = curr - grid.CellPositionToPoint(grid.GVD.GetNearestObstacle(grid.PointToCellPosition(curr))); float obstDist = closestObstacleVec.Length(); if (obstDist < CollisionDmax) correction -= CollisionWeight * (obstDist - CollisionDmax) * closestObstacleVec / obstDist; if (float.IsNaN(correction.X) || float.IsNaN(correction.Y)) { float noop; } // Voronoi term if (obstDist < VoronoiDmax && VoronoiWeight > 0f) { Vector2 closestVoronoiVec = curr - grid.CellPositionToPoint(grid.GVD.GetNearestVoronoiEdge(grid.PointToCellPosition(curr))); float voroDist = closestVoronoiVec.Length(); if (voroDist > 0f) { float alphaplusdo = grid.GVD.AlphaActual + obstDist; float dominusdmax = obstDist - VoronoiDmax; float doplusdv = obstDist + voroDist; float dmaxsquared = VoronoiDmax * VoronoiDmax; float pvdv = (grid.GVD.AlphaActual / alphaplusdo) * (dominusdmax * dominusdmax / dmaxsquared) * (obstDist / (doplusdv * doplusdv)); float pvdo = (grid.GVD.AlphaActual / alphaplusdo) * (voroDist / doplusdv) * (dominusdmax / dmaxsquared) * (-dominusdmax / alphaplusdo - dominusdmax / doplusdv + 2); correction -= VoronoiWeight * (pvdo * closestObstacleVec / obstDist + pvdv * closestVoronoiVec / voroDist); if (float.IsNaN(correction.X) || float.IsNaN(correction.Y)) { float noop; } } } } // Smoothing term correction -= SmoothWeight * (currentPath[i - 2].Position - 4 * currentPath[i - 1].Position + 6 * curr - 4 * currentPath[i + 1].Position + currentPath[i + 2].Position); if (float.IsNaN(correction.X) || float.IsNaN(correction.Y)) { float noop; } // Curvature term correction -= CurvatureWeight * calcCurvatureTerm(currentPath[i - 1].Position, currentPath[i].Position, currentPath[i + 1].Position); if (float.IsNaN(correction.X) || float.IsNaN(correction.Y)) { calcCurvatureTerm(currentPath[i - 1].Position, currentPath[i].Position, currentPath[i + 1].Position); } correction /= CollisionWeight + SmoothWeight + VoronoiWeight + PathWeight + CurvatureWeight; currentPath[i].Position = curr + Alpha * correction; change += correction.Length(); } count++; if (Delay > 0) Thread.Sleep(Delay); } NumIterations = count; Change = change; ArrayList<Pose> thenewpath = new ArrayList<Pose>(); thenewpath.AddAll(currentPath); if (Anchoring && unsafeIndices == null) { HashSet<int> newUnsafes = checkPath(thenewpath, grid); if (newUnsafes.Count > 0) thenewpath = Smooth(path, grid, newUnsafes); } foreach (Pose p in thenewpath) { if (float.IsNaN(p.Position.X) || float.IsNaN(p.Position.Y)) { float noop; } } return thenewpath; }
private IList<Variable> v(params Variable[] variables) { var list = new ArrayList<Variable>(); list.AddAll(variables); return list; }
private IList<IList<Variable>> vv(params IList<Variable>[] arrayOflistOfVars) { var list = new ArrayList<IList<Variable>>(); list.AddAll(arrayOflistOfVars); return list; }
/// <summary> /// Adds the token to the chain. /// </summary> public void AddToChain(Token token) { try { // Check to see if there is only one and it is this // one. If it is, then reset the chain. if (chain.Count == 1 && chain.Contains(token)) { chain.Clear(); token.InChain = false; return; } // Check to see if there is anything in the chain already if (chain.Count > 0) { // Go backwards until we find one that is adjacent to // the current one bool addRest = false; bool containsToken = chain.Contains(token); ArrayList<Token> revChain = new ArrayList<Token>(); revChain.AddAll(chain); revChain.Reverse(); LinkedList<Token> newChain = new LinkedList<Token>(); foreach (Token test in revChain) { // Check for containing code if (containsToken && !addRest && test != token) { test.InChain = false; continue; } if (containsToken && test == token) { // Add the rest, but not this one because we // append at the end. addRest = true; continue; } // Check for adjacent if (!addRest && !test.IsAdjacent(token)) { // Pop off this one test.InChain = false; continue; } // Check for adjacent if (test.IsAdjacent(token)) { addRest = true; } // Add the chain test.InChain = true; newChain.Add(test); } // Reverse it again newChain.Reverse(); chain = newChain; } // At this point, we can append the token to the chain chain.Add(token); token.InChain = true; } finally { // Fire a change OnChainChanged(); } }
/// <summary> /// Calculates the top, non-grabStack position. /// </summary> /// <returns></returns> private float GetTopPosition() { float topPosition = 0; ArrayList<Block> blocks = new ArrayList<Block>(); blocks.AddAll(currentStack); blocks.Reverse(); foreach (Block block in blocks) { // See if we are moving or if we have no height if (block.IsMoving || block.Height == 0) continue; // Grab this one topPosition = block.TopPosition; break; } return topPosition; }
/// <summary> /// Updates the various speech bubbles for all prayers. /// </summary> private void UpdateSpeechBubbles(UpdateArgs args) { // Keep a list of keys, so we know which ones to remove ArrayList<Prayer> tmpPrayers = new ArrayList<Prayer>(); tmpPrayers.AddAll(speechSprites.Keys); // Loop through our list of speed sprites foreach (Prayer prayer in Game.State.Prayers) { // See if we have one PrayerSpeechSprite pss = null; if (!speechSprites.Contains(prayer)) { // We need to construct the speech sprite pss = new PrayerSpeechSprite(prayer); speeches.Add(pss); speechSprites[prayer] = pss; } else { // Pull out the speech sprite pss = speechSprites[prayer]; tmpPrayers.Remove(prayer); } // Update the sprite pss.Update(args); } // Remove everything left since we don't have it anymore foreach (Prayer prayer in tmpPrayers) { // Remove from our sprites speeches.Remove(speechSprites[prayer]); speechSprites.Remove(prayer); } }
/// <summary> /// Checks the board against all of the current prayers /// and initiates the construction phase. /// </summary> /// <param name="x"></param> /// <param name="y"></param> public void CheckLayout(int x, int y) { // Ignore empty prayers if (Game.State.Prayers.Count == 0) return; // We want to loop through the prayers ArrayList<Prayer> tmpPrayers = new ArrayList<Prayer>(); tmpPrayers.AddAll(Game.State.Prayers); foreach (Prayer prayer in tmpPrayers) { // Don't bother if we haven't been accepted if (!prayer.IsAccepted) continue; // Check the layout, if it returns true, we are done if (CheckLayouts(x, y, prayer)) return; } }
public IList<Operation> getOperations() { if (mainBlock == null) { return new ArrayList<Operation>(); } IList<Operation> operations = new ArrayList<Operation>(); operations.AddAll(new Stack2Turing(mainBlock).translate()); foreach (Block exceptionHandlerBlock in exceptionHandlerBlocks) { operations.AddAll(new Stack2Turing(exceptionHandlerBlock).translate()); } return operations; }