public void SetReturnsCorrectReferencesWhenPeopleAreRemoved() { ArraySet set = new ArraySet(); var alice = new Person { Name = "Alice" }; var bob = new Person { Name = "Bob" }; var charlie = new Person { Name = "Charlie" }; set.Add(alice); set.Add(bob); set.Add(charlie); Person[] people = set.GetAllPeople(); Assert.AreEqual(3, people.Length); Assert.IsTrue(people.Contains(alice)); Assert.IsTrue(people.Contains(bob)); Assert.IsTrue(people.Contains(charlie)); set.Remove(bob); people = set.GetAllPeople(); Assert.AreEqual(2, people.Length); Assert.IsTrue(people.Contains(alice)); Assert.IsTrue(people.Contains(charlie)); }
protected virtual void SetUp() { set = new ArraySet <int>(); set.Add(5); set.Add(10); set.Add(8); }
public void AddingAndRemovingPeopleMaintainsCorrectCount() { ArraySet set = new ArraySet(); var alice = new Person { Name = "Alice" }; var bob = new Person { Name = "Bob" }; var charlie = new Person { Name = "Charlie" }; Assert.AreEqual(0, set.Count()); set.Add(alice); Assert.AreEqual(1, set.Count()); set.Add(bob); Assert.AreEqual(2, set.Count()); set.Add(charlie); Assert.AreEqual(3, set.Count()); set.Remove(bob); Assert.AreEqual(2, set.Count()); set.Remove(charlie); Assert.AreEqual(1, set.Count()); set.Remove(alice); Assert.AreEqual(0, set.Count()); }
public void Initialize(ArraySet arraySet, int baseRows, int maximumColumns, Solver solver, int segments) { this.arraySet = arraySet; if (baseRows > arraySet.maxSolverRows || maximumColumns > arraySet.maxSolverCols) { arraySet.maxSolverRows = Math.Max(baseRows, arraySet.maxSolverRows); arraySet.maxSolverCols = Math.Max(maximumColumns, arraySet.maxSolverCols); arraySet.RecreateSolverArrays(); } this.solver = solver; this.segments = segments; cRows = baseRows; cCols = 0; for (int i = 0; i <= cRows; i++) { arraySet.rowScale[i] = 1.0; } if (lp == null) { lp = new LP(cRows, maximumColumns, arraySet, solver.CalculationOptions.MaxRedecompose); } else { lp.Initialize(cRows, maximumColumns, arraySet, solver.CalculationOptions.MaxRedecompose); } compactSolution = null; sort = null; needsDual = false; needsQuadratic = false; maximizeColumn = -1; }
public ICursor FetchAllNotes() { var repo = new RemoteRepository(); var result = repo.GetAllEntries(); string[] columns = new string[] { "_id", "title", "body" }; MatrixCursor matrixCursor = new MatrixCursor(columns); foreach (var r in result) { var set = new ArraySet(); set.Add(r.id); set.Add(r.title.ToString()); set.Add(r.body.ToString()); matrixCursor.AddRow(set); } /*var set = new ArraySet(); * set.Add("1"); * set.Add("ZXC"); * set.Add("QWE"); * * matrixCursor.AddRow(set); * matrixCursor.AddRow(set);*/ return(matrixCursor); //return this.db.Query(DatabaseTable, new[] { KeyRowId, KeyTitle, KeyBody }, null, null, null, null, null); }
private ArraySet UnionAndIntersResult(String posfix) { Stack <ArraySet> stack = new Stack <ArraySet>(); foreach (char c in posfix.ToCharArray()) { if (c == 'U' || c == 'u') { ArraySet resultTemp = stack.Pop().Union(stack.Pop()); stack.Push(resultTemp); } else if (c == 'n') { ArraySet resultTemp = stack.Pop().intersection(stack.Pop()); stack.Push(resultTemp); } else if (c == '-') { ArraySet resultTempB = stack.Pop(); ArraySet resultTempA = stack.Pop(); stack.Push(resultTempA.difference(resultTempB)); } else { ArraySet temp1 = setList[getIndexFromChar(c)]; stack.Push(temp1); } } return(stack.Pop()); }
/// <summary> /// Given a /// <c>Tree</c> /// node /// <paramref name="t"/> /// , attempts to /// return a list of nodes to which node /// <paramref name="t"/> /// has this /// grammatical relation, with /// <paramref name="t"/> /// as the governor. /// </summary> /// <param name="t">Target for finding dependents of t related by this GR</param> /// <param name="root">The root of the Tree</param> /// <returns>A Collection of dependent nodes to which t bears this GR</returns> public virtual ICollection <TreeGraphNode> GetRelatedNodes(TreeGraphNode t, TreeGraphNode root, IHeadFinder headFinder) { ICollection <TreeGraphNode> nodeList = new ArraySet <TreeGraphNode>(); foreach (TregexPattern p in targetPatterns) { // cdm: I deleted: && nodeList.isEmpty() // Initialize the TregexMatcher with the HeadFinder so that we // can use the same HeadFinder through the entire process of // building the dependencies TregexMatcher m = p.Matcher(root, headFinder); while (m.FindAt(t)) { TreeGraphNode target = (TreeGraphNode)m.GetNode("target"); if (target == null) { throw new AssertionError("Expression has no target: " + p); } nodeList.Add(target); if (Debug) { log.Info("found " + this + "(" + t + "-" + t.HeadWordNode() + ", " + m.GetNode("target") + "-" + ((TreeGraphNode)m.GetNode("target")).HeadWordNode() + ") using pattern " + p); foreach (string nodeName in m.GetNodeNames()) { if (nodeName.Equals("target")) { continue; } log.Info(" node " + nodeName + ": " + m.GetNode(nodeName)); } } } } return(nodeList); }
public void CountMustReturnCorrectValue() { Assert.AreEqual(setLength, mySet100.Count); ArraySet <int> arrSet = new ArraySet <int>(); UnmutableSet <int> mySet = new UnmutableSet <int>(arrSet); Assert.AreEqual(0, mySet.Count); }
public void CountIsCorrect_1() { ArraySet set = new ArraySet(); set.Add(new Person { Name = "Alice" }); Assert.AreEqual(1, set.Count()); }
private void PrepareForScheduling() { _unfinishedThreadIds = new ArraySet(_numThreads); _waitingThreadIds = new ArraySet(_numThreads); _threadIdsSeenWhileAllWaiting = new ArraySet(_numThreads); for (int i = 0; i < _numThreads; ++i) { _unfinishedThreadIds.Add(i); } }
public void ConvertAllReturnCorrectValue() { ArraySet <int> arrSet = new ArraySet <int>(); arrSet.Add(10); Assert.IsInstanceOfType(SetUtils.ConvertAll <int, MySet.HashSet <int> >(arrSet), typeof(MySet.HashSet <int>)); Assert.IsInstanceOfType(SetUtils.ConvertAll <int, ArraySet <int> >(arrSet), typeof(ArraySet <int>)); Assert.IsInstanceOfType(SetUtils.ConvertAll <int, LinkedSet <int> >(arrSet), typeof(LinkedSet <int>)); }
public void Setup()//Подставляет UnmutableSet в mySet перед каждым тестом { ArraySet <int> arrSet = new ArraySet <int>(); for (int i = 0; i < setLength; i++) { arrSet.Add(i); } mySet100 = new UnmutableSet <int>(arrSet); }
public void Initialize(int size, ArraySet arraySet) { this.size = size; this.arraySet = arraySet; etaSize = 0; if (size > arraySet.LUsizeMax) { arraySet.LUsizeMax = size; arraySet.RecreateLUArrays(); } }
public void ExistMustReturnTrueIfItemsExist() { ArraySet <int> arrSet = new ArraySet <int>(); arrSet.Add(1); arrSet.Add(3); Assert.IsTrue(SetUtils.Exists(arrSet, (item) => { return(item == 1); })); }
// data will be modified, if you need to retain it clean pass a clone public LU(int size, ArraySet arraySet) { this.size = size; this.arraySet = arraySet; etaSize = 0; if (size > arraySet.LUsizeMax) { arraySet.LUsizeMax = size; arraySet.RecreateArrays(); } }
public void ExistMustReturnFalseIfItemsNonExist() { ArraySet <int> arrSet = new ArraySet <int>(); arrSet.Add(1); arrSet.Add(3); Assert.IsFalse(SetUtils.Exists(arrSet, (item) => { return(item == 2); })); }
public void AddingPersonMultipleTimesDoesNotChangeCount() { ArraySet set = new ArraySet(); var alice = new Person { Name = "Alice" }; set.Add(alice); set.Add(alice); Assert.AreEqual(1, set.Count()); }
public void CountIsCorrect_10K() { ArraySet set = new ArraySet(); for (int i = 0; i < 10000; i++) { set.Add(new Person { Name = $"Alice_{i}" }); } Assert.AreEqual(10000, set.Count()); }
private void InsertSetButt_Click(object sender, EventArgs e) { if (setCount < 10 && SetName.Text != "") { try { int index = getIndexFromChar(char.Parse(SetName.Text)); if (index == -1) { NotifLabel.Text = "Set Name is Incorrect. try to insert A-J"; return; } ArraySet set = new ArraySet(); if (setList[index] == null && isCorrectFormat(SetValue.Text)) { setList[index] = set; //add setCount++; if (!SetValue.Text.Equals("")) { setList[index].addString(SetValue.Text); } NotifLabel.Text = "Insert set " + SetName.Text + " successfully"; listBox1.Items.Add(SetName.Text + " : " + set.toString()); NotifLabel.ForeColor = Color.Green; } else if (setList[index] != null) { NotifLabel.Text = "Set " + SetName.Text + " is already exist"; NotifLabel.ForeColor = Color.Red; } else if (!isCorrectFormat(SetValue.Text)) { NotifLabel.Text = "Set Element is not in a correct format"; NotifLabel.ForeColor = Color.Red; } } catch (Exception) { NotifLabel.Text = "Incorrect Input"; } } else if (setCount >= 10) { NotifLabel.Text = "Set is Full"; NotifLabel.ForeColor = Color.Purple; } else { NotifLabel.Text = "Error"; } }
public static void ToList(ArraySet arrset) { Person[] order = arrset.toSorted(); Console.Clear(); foreach (var item in order) { if (item != null) { Console.WriteLine(item); } } }
public void UnionTest() { for (int i = 0; i < 4; i++) { set.Add(i); } ArraySet set1 = new ArraySet(); for (int i = 2; i < 6; i++) { set1.Add(i); } Assert.AreEqual("{2, 3, 4, 5, 0, 1}", set.Union(set1).ToString()); }
public void DifferenceTest() { for (int i = 0; i < 4; i++) { set.Add(i); } ArraySet set1 = new ArraySet(); for (int i = 2; i < 6; i++) { set1.Add(i); } Assert.AreEqual("{0, 1}", set.Difference(set1).ToString()); }
public void CheckForAllReturnTrue() { ArraySet <int> arrSet = new ArraySet <int>(); int numOfElements = 50; for (int i = 0; i < numOfElements; i++) { arrSet.Add(i); } Assert.IsTrue(SetUtils.CheckForAll <int>(arrSet, (item) => { return(item >= 0 && item <= numOfElements); })); }
public void IntersectionTest() { for (int i = 0; i < 4; i++) { set.Add(i); } ArraySet set1 = new ArraySet(); for (int i = 2; i < 6; i++) { set1.Add(i); } Assert.AreEqual("{2, 3}", set.Intersection(set1).ToString()); }
public void ConvertAllReturnCorrectNumberOfElements() { ArraySet <int> arrSet = new ArraySet <int>(); int numOfElements = 50; for (int i = 0; i < numOfElements; i++) { arrSet.Add(i); } Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, MySet.HashSet <int> >(arrSet).Count); Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, ArraySet <int> >(arrSet).Count); Assert.AreEqual(numOfElements, SetUtils.ConvertAll <int, LinkedSet <int> >(arrSet).Count); }
public ArraySet <Pair <T, U> > Cross <U>(ArraySet <U> that) { ArraySet <Pair <T, U> > result = new ArraySet <Pair <T, U> >(); int m = this.size; int n = that.size; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { result.Add(new Pair <T, U>(this.items[i], that.items[j])); } } return(result); }
static Person Finder(ArraySet arrset, string id = null) { if (id == null) { id = numInput("\nEnter the ID of the record you want:"); } Person person = new Person(id, "", "", 0, "", 0); if (arrset.Contains(person)) { int bucket = Math.Abs(person.GetHashCode()) % arrset.Buckets; int pos = arrset.BinarySearch(person); if (arrset.ArrSet[bucket][pos] != null) { person = arrset.ArrSet[bucket][pos]; Console.WriteLine(person); } } else { person.Id = ""; Console.WriteLine("That record doesn't exist."); } return(person); /* foreach (var item in Person) * { * * if (item.Id == id) * { * * person = item; * Console.WriteLine(person); * * } * * } * * if (person.Id == "") Console.WriteLine("That record doesn't exist."); * * return person; */ }
public static ArraySet RequestArraySet(bool largeArraysHint) { lock (pool) { if (pool.Count == 0) { if (createdArraySets < maximumPoolSize) { pool.Add(new ArraySet()); createdArraySets++; } else { do { waiters++; Monitor.Wait(pool); waiters--; } while (pool.Count == 0); } } // find desirable size int bestIndex; if (largeArraysHint) { bestIndex = 0; for (int i = 1; i < pool.Count; i++) { if (pool[i].MaxSize > pool[bestIndex].MaxSize) { bestIndex = i; } } } else { bestIndex = pool.Count - 1; } ArraySet result = pool[bestIndex]; result.spellIndex = 0; result.cycleIndex = 0; result.stateIndex = 0; result.effectIndex = 0; pool.RemoveAt(bestIndex); return(result); } }
public void Initialize(int rows, int maxCols, ArraySet arraySet) { this.arraySet = arraySet; if (rows > arraySet.SparseMatrixMaxRows || maxCols + 20 > arraySet.SparseMatrixMaxCols) { arraySet.SparseMatrixMaxRows = Math.Max(rows, arraySet.SparseMatrixMaxRows); arraySet.SparseMatrixMaxCols = Math.Max(maxCols + 20, arraySet.SparseMatrixMaxCols); // give some room for AddColumn arraySet.RecreateSparseMatrixArrays(); } this.rows = rows; this.cols = 0; //Array.Clear(data, 0, rows * cols); // only need to clear what will be used sparseIndex = 0; lastCol = 0; finalized = false; }
public static void ReleaseArraySet(ArraySet arraySet) { lock (pool) { if (pool.Count >= maximumPoolSize) { createdArraySets--; } else { pool.Add(arraySet); if (waiters > 0) { Monitor.Pulse(pool); } } } }
public ExSet() { s = new ArraySet(); }
/* hacer un select distinct de un columna pero con DataTable*/ public System.Collections.ArrayList sacar_val_posibles(System.Data.DataTable dt, string svariable) { System.Collections.ArrayList alval_pos = new ArrayList(); if (svariable != null) { ArraySet asval_pos = new ArraySet(); int i = 0; while (i < dt.Rows.Count) { if (dt.Rows[i].RowState != DataRowState.Deleted) { asval_pos.add(dt.Rows[i][svariable].ToString()); } i++; } alval_pos = asval_pos.Source; } return alval_pos; }