public void SortedColumn_GrowAndShrink() { SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0); c.SetSize(5); CommitIfRequired(c); ColumnTests.AssertConsistent(c); c[0] = 10; c[1] = -10; c[2] = 5; c[3] = -2; c[4] = 20; CommitIfRequired(c); ColumnTests.AssertConsistent(c); Assert.AreEqual("1, 3, 2, 0, 4", ColumnTests.GetSortedIndexes(c)); // Grow - verify IDs inserted for -1 default c.SetSize(8); CommitIfRequired(c); ColumnTests.AssertConsistent(c); Assert.AreEqual("1, 3, 5, 6, 7, 2, 0, 4", ColumnTests.GetSortedIndexes(c)); // Shrink (unset values) - verify IDs removed properly c.SetSize(5); ColumnTests.AssertConsistent(c); Assert.AreEqual("1, 3, 2, 0, 4", ColumnTests.GetSortedIndexes(c)); // Shrink (set values) - verify IDs removed properly c.SetSize(3); ColumnTests.AssertConsistent(c); Assert.AreEqual("1, 2, 0", ColumnTests.GetSortedIndexes(c)); // Shrink (everything) c.SetSize(0); ColumnTests.AssertConsistent(c); Assert.AreEqual("", ColumnTests.GetSortedIndexes(c)); Assert.AreEqual(0, (int)c.Count); // Grow enough to require underlying array resize IList <ushort> actualArray; int actualArrayCount; c.SetSize(ArrayExtensions.MinimumSize * 2); CommitIfRequired(c); ColumnTests.AssertConsistent(c); Assert.IsTrue(c.TryGetSortedIndexes(out actualArray, out actualArrayCount)); Assert.AreEqual(ArrayExtensions.MinimumSize * 2, (int)c.Count); Assert.AreEqual(ArrayExtensions.MinimumSize * 2, (int)actualArray.Count); Assert.AreEqual(ArrayExtensions.MinimumSize * 2, actualArrayCount); // Shrink enough to require underlying array resize c.SetSize(ArrayExtensions.MinimumSize); ColumnTests.AssertConsistent(c); Assert.IsTrue(c.TryGetSortedIndexes(out actualArray, out actualArrayCount)); Assert.AreEqual(ArrayExtensions.MinimumSize, (int)c.Count); Assert.AreEqual(ArrayExtensions.MinimumSize, (int)actualArray.Count); Assert.AreEqual(ArrayExtensions.MinimumSize, actualArrayCount); }
public void SortedColumn_InsertionOrders() { SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0); c.SetSize(8); // Value greater than default c[0] = 10; // Value less than default c[1] = -10; // Insert between existing value and end of defaults c[2] = 5; // Insert between existing value and beginning of defaults c[3] = -2; // Insert at end c[4] = 20; // Insert at beginning c[5] = -20; // Insert in middle c[6] = 8; // Leave with default //c[7] = -1; ColumnTests.AssertConsistent(c); Assert.AreEqual("5, 1, 3, 7, 2, 6, 0, 4", ColumnTests.GetSortedIndexes(c)); }
public void SortedColumn_Strings() { SortedColumn <ByteBlock> c = ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0); // Set all three to default (empty) c.SetSize(3); CommitIfRequired(c); // Reset a value to empty (SortedIDs need to stay in order to find insertion positions properly) c[2] = ""; Assert.AreEqual("0, 1, 2", ColumnTests.GetSortedIndexes(c)); // Reset a value to something (needs to be after all other values; in this case, it'll stay in place in SortedIDs) c[2] = "TaoSuiteSrc"; Assert.AreEqual("0, 1, 2", ColumnTests.GetSortedIndexes(c)); // Add two more values (empty); empty values should insert after other empty values c.SetSize(5); CommitIfRequired(c); Assert.AreEqual("0, 1, 3, 4, 2", ColumnTests.GetSortedIndexes(c)); // Set a larger ID to an existing value; needs SortedID after other copy of value c[3] = "TaoSuiteSrc"; Assert.AreEqual("0, 1, 4, 2, 3", ColumnTests.GetSortedIndexes(c)); // Set another value before existing ones; needs SortedID in value order c[0] = "MauiRemoval"; Assert.AreEqual("1, 4, 0, 2, 3", ColumnTests.GetSortedIndexes(c)); // Set a smaller ID to an existing value; needs SortedID before other copies of value c[1] = "TaoSuiteSrc"; Assert.AreEqual("4, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c)); // Add two more values; should appear after other empties c.SetSize(7); CommitIfRequired(c); Assert.AreEqual("4, 5, 6, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c)); // Set two more empty duplicates - they need to be reinserted among empties in original sequence c[5] = ""; c[6] = ""; Assert.AreEqual("4, 5, 6, 0, 1, 2, 3", ColumnTests.GetSortedIndexes(c)); ColumnTests.AssertConsistent(c); }