public void TestClear_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); Assert.AreEqual(3, list.Count, "The list had the wrong initial count."); list.Clear(); Assert.AreEqual(0, list.Count, "The count was not zero after clearing"); }
private Storage() { _students = new TypedList<Student>(); _groups = new TypedList<Group>(); _univers = new TypedList<University>(); _courses = new TypedList<Course>(); _teachers = new TypedList<Teacher>(); }
public void TestCopyTo_Copies_StartingAtArrayIndex() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3, 4, 5 }); int[] array = new int[9]; int arrayIndex = 2; list.CopyTo(array, arrayIndex); int[] expected = { 0, 0, 1, 2, 3, 4, 5, 0, 0, }; Assert.IsTrue(expected.ToSublist().IsEqualTo(array.ToSublist()), "The items were not copied as expected."); }
public void TestAdd_AddsToEnd() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.Add(4); Assert.AreEqual(4, list.Count, "The count wasn't increased."); int[] expected = { 1, 2, 3, 4 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item wa not added as expected."); }
public OperatorSignature(Operator operatorValue) { _operator = operatorValue; _signatures = new OperatorSignatures(this); #if USEVIRTUAL #if USETYPEDLIST FParentSignatures = new TypedList(typeof(OperatorSignature), false); #else FParentSignatures = new BaseList <OperatorSignature>(); #endif #endif }
public void NumberListColumn_TypeList_Basics() { // Set up column with sample values, roundtrip, re-verify NumberListColumn <int> column = BuildSampleColumn(); // Verify second value is in a shared array, not at index zero, not expandable (yet), not ReadOnly NumberList <int> row1List = column[1]; TypedList <int> row1Typed = new TypedList <int>(row1List, (index) => index, (index) => index); // Test second sample row slice IList members on NumberListConverter CollectionChangeVerifier.VerifyList(row1Typed, (index) => index % 20); // Verify values are re-merged and re-loaded properly string values = string.Join(", ", row1List); column = TreeSerializer.RoundTrip(column, TreeFormat.Binary); Assert.Equal(values, string.Join(", ", column[1])); // TypedList Equality TypedList <int> row1 = new TypedList <int>(column[1], (index) => index, (index) => index); TypedList <int> row0 = new TypedList <int>(column[0], (index) => index, (index) => index); Assert.True(row1.Equals(row1)); Assert.False(row1.Equals(row0)); Assert.False(row1 == row0); Assert.True(row1 != row0); Assert.False(null == row0); Assert.True(null != row0); Assert.Equal(row1.GetHashCode(), row1.GetHashCode()); // TypedList.Indices Assert.Equal(row1.Indices, column[1]); // SetTo(other) TypedList <int> firstRow = new TypedList <int>(column[0], (index) => index, (index) => index); row1Typed.SetTo(firstRow); Assert.Equal(string.Join(", ", firstRow), string.Join(", ", row1Typed)); // SetTo(null) row1Typed.SetTo(null); Assert.Empty(row1Typed); // SetTo(IList) row1Typed.SetTo(new int[] { 2, 3, 4, 5 }); Assert.Equal("2, 3, 4, 5", string.Join(", ", row1Typed)); // SetTo(empty) row1Typed.SetTo(Array.Empty <int>()); Assert.Empty(row1Typed); }
public void Add(object value) { if (value != null) { if (this.list == null) { this.list = (ITypedList)Activator.CreateInstance(typeof(TypedList <>).MakeGenericType(value.GetType())); } else if (!this.list.ItemType.IsAssignableFrom(value.GetType())) { var newList = new TypedList <object>(); foreach (var item in this.list) { newList.Add(item); } this.list = newList; } } else { if (this.list == null) { this.list = new TypedList <object>(); } else { if (this.list.ItemType.IsValueType && Nullable.GetUnderlyingType(this.list.ItemType) != null) { var nullableList = (ITypedList)Activator.CreateInstance(typeof(TypedList <>).MakeGenericType(typeof(Nullable <>).MakeGenericType(this.list.ItemType))); foreach (var item in this.list) { nullableList.Add(item); } this.list = nullableList; } } } this.list.Add(value); }
public static TypedList <Employee> GetData() { var tlist = new TypedList <Employee>(); tlist.Add(new Employee(1, -1, "John", "Doe", "Director of sales")); tlist.Add(new Employee(10, 1, "Alex", "Red", "Manager")); tlist.Add(new Employee(100, 10, "Alfred", "Bon", "Manager's assistant")); tlist.Add(new Employee(11, 1, "Elena", "White", "Manager")); tlist.Add(new Employee(12, 1, "Eric", "Green", "Manager")); tlist.Add(new Employee(13, 1, "Sara", "Blue", "Manager")); tlist.Add(new Employee(130, 12, "Mila", "Vong", "Manager's assistant")); tlist.Add(new Employee(131, 12, "Alex", "Li", "Manager's assistant")); tlist.Add(new Employee(14, 1, "Gloria", "Black", "Manager")); tlist.Add(new Employee(2, -1, "Mary", "Sue", "Marketing director")); tlist.Add(new Employee(20, 2, "Natalie", "Ming", "Manager")); tlist.Add(new Employee(201, 20, "Ivan", "Romanov", "Manager's assistant")); tlist.Add(new Employee(202, 20, "Stan", "Heck", "Manager's assistant")); tlist.Add(new Employee(203, 20, "Don", "Milman", "Manager's assistant")); tlist.Add(new Employee(21, 2, "Joseph", "Anderson", "Manager")); tlist.Add(new Employee(210, 21, "Jack", "Gun", "Manager's assistant")); tlist.Add(new Employee(22, 2, "Olivia", "Helt", "Manager")); tlist.Add(new Employee(220, 22, "Caleb", "Iron", "Manager's assistant")); tlist.Add(new Employee(221, 22, "Dylan", "Gold", "Manager's assistant")); tlist.Add(new Employee(23, 2, "Samantha", "Silver", "Manager")); tlist.Add(new Employee(24, 2, "Tyler", "Steel", "Manager")); tlist.Add(new Employee(3, -1, "Victor", "Smith", "Security director")); tlist.Add(new Employee(31, 3, "James", "Bond", "Guard")); tlist.Add(new Employee(32, 3, "Jason", "Bourne", "Guard")); tlist.Add(new Employee(33, 3, "John", "McClane", "Guard")); tlist.Add(new Employee(34, 3, "Peter", "Parker", "Guard")); tlist.Add(new Employee(35, 3, "Tony", "Stark", "Guard")); return(tlist); }
public void TestRemoveAt_IndexTooBig_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.RemoveAt(3); }
public void TestRemoveAt_NegativeIndex_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.RemoveAt(-1); }
public void TestIndexOf_FirstValue_ReturnsCountMinusOne() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); int index = list.IndexOf(1); Assert.AreEqual(0, index); }
public void TestRemoveAt_IndexInMiddle_RemovesFromMiddle() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3, 4 }); list.RemoveAt(2); int[] expected = { 1, 2, 4 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not removed as expected."); }
public void TestGetEnumerable_Implicit_StillEnumerates() { IEnumerable view = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); var list = new List<object>(); foreach (object item in view) { list.Add(item); } object[] expected = { 1, 2, 3 }; Assert.IsTrue(expected.ToSublist().IsEqualTo(list.ToSublist()), "The values were not enumerated."); }
public Start Parse() { Push(0, null); IList ign = null; while (true) { while (Index(lexer.Peek()) == -1) { if (ign == null) { ign = new TypedList(NodeCast.Instance); } ign.Add(lexer.Next()); } if (ign != null) { ignoredTokens.SetIn(lexer.Peek(), ign); ign = null; } last_pos = lexer.Peek().Pos; last_line = lexer.Peek().Line; last_token = lexer.Peek(); int index = Index(lexer.Peek()); action[0] = actionTable[State()][0][1]; action[1] = actionTable[State()][0][2]; int low = 1; int high = actionTable[State()].Length - 1; while (low <= high) { int middle = (low + high) / 2; if (index < actionTable[State()][middle][0]) { high = middle - 1; } else if (index > actionTable[State()][middle][0]) { low = middle + 1; } else { action[0] = actionTable[State()][middle][1]; action[1] = actionTable[State()][middle][2]; break; } } switch (action[0]) { case SHIFT: { ArrayList list = new ArrayList(); list.Add(lexer.Next()); Push(action[1], list); last_shift = action[1]; } break; case REDUCE: switch (action[1]) { case 0: { ArrayList list = New0(); Push(GoTo(0), list); } break; case 1: { ArrayList list = New1(); Push(GoTo(1), list); } break; case 2: { ArrayList list = New2(); Push(GoTo(1), list); } break; case 3: { ArrayList list = New3(); Push(GoTo(2), list); } break; case 4: { ArrayList list = New4(); Push(GoTo(2), list); } break; case 5: { ArrayList list = New5(); Push(GoTo(2), list); } break; case 6: { ArrayList list = New6(); Push(GoTo(3), list); } break; case 7: { ArrayList list = New7(); Push(GoTo(4), list); } break; case 8: { ArrayList list = New8(); Push(GoTo(5), list); } break; case 9: { ArrayList list = New9(); Push(GoTo(6), list); } break; case 10: { ArrayList list = New10(); Push(GoTo(6), list); } break; case 11: { ArrayList list = New11(); Push(GoTo(7), list); } break; case 12: { ArrayList list = New12(); Push(GoTo(8), list); } break; case 13: { ArrayList list = New13(); Push(GoTo(8), list); } break; case 14: { ArrayList list = New14(); Push(GoTo(9), list); } break; case 15: { ArrayList list = New15(); Push(GoTo(9), list); } break; case 16: { ArrayList list = New16(); Push(GoTo(10), list); } break; case 17: { ArrayList list = New17(); Push(GoTo(10), list); } break; case 18: { ArrayList list = New18(); Push(GoTo(10), list); } break; } break; case ACCEPT: { EOF node2 = (EOF)lexer.Next(); PProg node1 = (PProg)((ArrayList)Pop())[0]; Start node = new Start(node1, node2); return(node); } case ERROR: throw new ParserException(last_token, "[" + last_line + "," + last_pos + "] " + errorMessages[errors[action[1]]]); } } }
public void TestInsert_IndexInMiddle_InsertsInMiddle() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 4, 5 }); list.Insert(2, 3); int[] expected = { 1, 2, 3, 4, 5 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not inserted as expected."); }
public void TestRemove_ValueNotFound_ReturnsFalse() { var list = new TypedList<ArrayList, int>(new ArrayList() { 0, 1, 2 }); bool result = list.Remove(3); Assert.IsFalse(result); }
public void TestIndexOf_ValueNotFound_ReturnsNegativeOne() { var list = new TypedList<ArrayList, int>(new ArrayList() { 0, 1, 2 }); int index = list.IndexOf(3); Assert.AreEqual(-1, index); }
public void TestInsert_IndexAtBeginning_InsertsInBack() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.Insert(0, 0); int[] expected = { 0, 1, 2, 3 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not inserted as expected."); }
public void TestIndexOf_MultipleOccurrences_ReturnsLastIndex() { var list = new TypedList<ArrayList, int>(new ArrayList() { 0, 1, 2, 1, 3 }); int index = list.IndexOf(1); Assert.AreEqual(1, index); }
public void TestIndexOf_MiddleValue_ReturnsExpectedIndex() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); int index = list.IndexOf(2); Assert.AreEqual(1, index); }
public void TestIndexOf_LastValue_ReturnsZero() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); int index = list.IndexOf(3); Assert.AreEqual(list.Count - 1, index); }
public void TestRemove_FindsValue_ReturnsTrue() { var list = new TypedList<ArrayList, int>(new ArrayList() { 0, 1, 2 }); bool result = list.Remove(0); Assert.IsTrue(result, "The value was not found."); int[] expected = { 1, 2, }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not removed from the list."); }
/** * Returns a typed list backed by the given list. * <p> * Only objects of the specified type can be added to the list. * * @param list the list to limit to a specific type, must not be null * @param type the type of objects which may be added to the list * @return a typed list backed by the specified list */ public static java.util.List <Object> typedList(java.util.List <Object> list, java.lang.Class type) { return(TypedList.decorate(list, type)); }
public void TestRemove_MultipleOccurrences_RemovesFirstOccurrence() { var list = new TypedList<ArrayList, int>(new ArrayList() { 0, 1, 0, 1 }); bool result = list.Remove(1); Assert.IsTrue(result, "The value was not found."); int[] expected = { 0, 0, 1 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not removed from the list."); }
public void TestIndexer_Getter_ItemWrongType_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { "1" }); int value = list[0]; }
public void TestContains_ValueExists_ReturnsTrue() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3, 4, 5 }); bool result = list.Contains(3); Assert.IsTrue(result); }
public void TestGetEnumerable_GetsItems() { var view = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); var list = new List<int>(); foreach (int item in view) { list.Add(item); } int[] expected = { 1, 2, 3 }; Assert.IsTrue(expected.ToSublist().IsEqualTo(list.ToSublist()), "The values were not enumerated."); }
public void TestCopyTo_IncompatibleType_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, "3", 4, 5 }); int[] array = new int[5]; int arrayIndex = 0; list.CopyTo(array, arrayIndex); }
public void TestIndexer_Getter_ItemRightType() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1 }); Assert.AreEqual(1, list[0], "The wrong item was selected."); }
public void TypedList_Basics() { Community c = new Community(); List <Person> people = new List <Person> { new Person(c) { Name = "One" }, new Person(c) { Name = "Two" }, new Person(c) { Name = "Three" } }; // Null by default Assert.Null(c.People); // Settable to Empty c.People = Array.Empty <Person>(); TypedList <Person> list = (TypedList <Person>)c.People; Assert.Empty(list); list.Add(people[0]); Assert.Single(list); list.Add(people[1]); list.Add(people[2]); CollectionReadVerifier.VerifySame(people, list); // SetTo self works properly list.SetTo(list); CollectionReadVerifier.VerifySame(people, list); // SetTo null works list.SetTo(null); Assert.Empty(list); // SetTo other works list.SetTo(people); CollectionReadVerifier.VerifySame(people, list); // Test Equality members CollectionReadVerifier.VerifyEqualityMembers(list, list); // Test equality operators #pragma warning disable CS1718 // Comparison made to same variable Assert.True(list == list); Assert.False(list != list); #pragma warning restore CS1718 // Comparison made to same variable Assert.False(list == null); Assert.True(list != null); Assert.False(null == list); Assert.True(null != list); // SetTo empty works list.SetTo(new List <Person>()); Assert.Empty(list); CollectionChangeVerifier.VerifyList(c.People, (i) => new Person(c) { Age = (byte)i }); // Set null IList <Person> cachedPeople = c.People; c.People = null; Assert.Null(c.People); Assert.Equal(0, cachedPeople.Count); // SetTo TypedList from another DB/Table Community c2 = new Community(); c2.People = new List <Person>(); c2.People.Add(new Person(c2) { Name = "Other" }); list.SetTo(c2.People); Assert.Equal("Other", list[0].Name); }
public void TestIndexer_Setter_SetsValue() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1 }); list[0] = 0; int[] expected = { 0 }; Assert.AreEqual(0, list.List[0]); }
public void TestCtor_SetsUnderlyingList() { ArrayList arrayList = new ArrayList() { 1, 2, 3, }; TypedList<ArrayList, int> list = new TypedList<ArrayList, int>(arrayList); Assert.AreSame(arrayList, list.List, "The backing field was not set."); Assert.AreEqual(arrayList.Count, list.Count, "The counts did not match."); Assert.AreEqual(arrayList.IsReadOnly, ((ICollection<int>)list).IsReadOnly, "The read-only property didn't match."); }
public void TestGetEnumerable_IncompatibleItem_Throws() { var view = new TypedList<ArrayList, int>(new ArrayList() { 1, "2", 3 }); var list = new List<int>(); foreach (int item in view) { list.Add(item); } }
public static void Add <T>(this TypedList <T> list, T value) { list.Values.Add(value); }
public void TestInsert_IndexTooBig_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.Insert(4, 0); }
public void TestInsert_NegativeIndex_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.Insert(-1, 4); }
public void TestRemoveAt_IndexAtBeginning_RemovesFromBack() { var list = new TypedList<ArrayList, int>(new ArrayList() { 1, 2, 3 }); list.RemoveAt(0); int[] expected = { 2, 3 }; int[] actual = toTypedArray(list.List); Assert.IsTrue(expected.ToSublist().IsEqualTo(actual.ToSublist()), "The item was not removed as expected."); }
/// <summary> /// Constructor of the grammar node. /// </summary> /// <param name="p">Parent master grammar.</param> public TypedListC(MasterGrammar p) : base(p) { Rule = TypedList.ConstructTypedListRule(p, IdentifierType.CONSTANT); }
public void TestCopyTo_NullArray_Throws() { var list = new TypedList<ArrayList, int>(new ArrayList()); int[] array = null; int arrayIndex = 0; list.CopyTo(array, arrayIndex); }