public void NumberListColumn_NumberList_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> slice = column[1]; Assert.Equal(4, slice.Count); Assert.True(slice.Slice.Index > 0); Assert.False(slice.Slice.IsExpandable); // Test second sample row slice IList members CollectionChangeVerifier.VerifyList(slice, (index) => index % 20); // Verify expandable after test Assert.Equal(0, slice.Slice.Index); Assert.True(slice.Slice.IsExpandable); // Verify values are re-merged and re-loaded properly string values = string.Join(", ", slice); column = TreeSerializer.RoundTrip(column, TreeFormat.Binary); Assert.Equal(values, string.Join(", ", column[1])); // Column range check Assert.Throws <IndexOutOfRangeException>(() => column[-1]); }
public void ListColumn_Basics() { ListColumn <int> column = new ListColumn <int>(new NumberColumn <int>(-1)); column[0].Add(1); column[0].Add(2); column[0].Add(3); // Test the outer column Column.Basics(() => new ListColumn <int>(new NumberColumn <int>(-1)), ColumnList <int> .Empty, column[0], (index) => { IList <int> other = column[column.Count]; other.Add(index); other.Add(index + 1); other.Add(index + 2); return(other); }); // Test the ColumnList item members CollectionChangeVerifier.VerifyList(column[1], (index) => index % 20); // ColumnList.Empty handling ColumnList <int> empty = ColumnList <int> .Empty; Assert.Empty(empty); Assert.True(empty.Count == 0); Assert.True(empty.Contains(7) == false); Assert.Equal(-1, empty.IndexOf(3)); Assert.True(empty == ColumnList <int> .Empty); Assert.False(empty != ColumnList <int> .Empty); // ColumnList.GetHashCode and Equals w/nulls ListColumn <string> stringColumn = new ListColumn <string>(new StringColumn()); ColumnList <string> first = (ColumnList <string>)stringColumn[0]; first.Add("One"); first.Add(null); first.Add("Two"); ColumnList <string> second = (ColumnList <string>)stringColumn[1]; second.Add("One"); second.Add(null); second.Add("Two"); Assert.True(second == first); second[1] = "NotNull"; Assert.NotEqual(second.GetHashCode(), first.GetHashCode()); Assert.False(second == first); }
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); }