public void IndexedColumn_Churn() { IColumn <ByteBlock> c = new IndexedColumn(ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0), new DefaultWordSplitter()); c.SetSize(4); c[0] = "First Value"; c[1] = "Second Value"; c[2] = "this value is yet another one"; ColumnTests.AssertConsistent(c); // Remove the last word added and ensure no problems (unique case, no swap and remove) Assert.AreEqual("2", ColumnTests.GetMatches(c, Operator.MatchesExact, "one")); c[2] = "this value is yet another"; ColumnTests.AssertConsistent(c); Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.MatchesExact, "one")); Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value")); // Reset a value to itself (reusing the read ByteBlock); ensure no problems c[1] = c[1]; ColumnTests.AssertConsistent(c); Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value")); // Set a value to null; ensure no problems c[0] = (ByteBlock)(string)null; ColumnTests.AssertConsistent(c); Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.MatchesExact, "first")); Assert.AreEqual("1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value")); }
public void IndexedColumn_Where() { IColumn <ByteBlock> c = new IndexedColumn(ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0), new DefaultWordSplitter()); // Verify no error searching empty column Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "missing")); c.SetSize(4); c[0] = "First Value"; c[1] = "Second Value"; c[2] = "this is a different value"; ColumnTests.AssertConsistent(c); // Verify passthrough to base column Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Equals, "First Value")); // Verify unknown words don't match (no error) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "missing")); // Verify all match for shared words Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "value")); Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value")); // Verify prefixes match for 'Matches' and not 'MatchesExact' Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "val")); Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.MatchesExact, "val")); // Verify unique words return only those matches Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "first")); Assert.AreEqual("2", ColumnTests.GetMatches(c, Operator.Matches, "diff")); // Verify matches fallthrough to equals Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "First Value")); c[0] = "Updated Value Here"; ColumnTests.AssertConsistent(c); // Verify items no longer match for removed words Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "first")); // Verify items continue to match for kept words Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.MatchesExact, "value")); // Verify items match for new words Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.MatchesExact, "updated")); }
public void IndexedColumn_HtmlSplitter() { IColumn <object> c = ColumnFactory.Build(new ColumnDetails("Description", "indexed[html]:sorted:string", null), 0); c.SetSize(4); c[0] = "<span title='nice'>First Value</span>"; c[1] = "<div>Second <b>Value</b> </div>"; c[2] = "this is a <b>different</b> value"; ColumnTests.AssertConsistent(c); // Verify words in html don't match (Splitter Should exclude) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "span")); Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "nice")); Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Matches, "nbsp")); // Verify text within html does match Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.Matches, "value")); Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Matches, "first")); Assert.AreEqual("2", ColumnTests.GetMatches(c, Operator.Matches, "different")); }
public void FastAddSortedColumn_InsertMax2() { SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), ushort.MaxValue); ushort seedLimit = ushort.MaxValue - 1; int lastValue = 0; c.SetSize(seedLimit); for (ushort i = 0; i < seedLimit; ++i) { lastValue = ushort.MaxValue + (int)i * 10; c[i] = lastValue; } ColumnTests.AssertConsistent(c); int firstValue = -1; c.SetSize(ushort.MaxValue); for (ushort i = seedLimit; i < ushort.MaxValue; ++i) { if (firstValue == -1) { firstValue = (int)i; } c[i] = (int)i; } ColumnTests.AssertConsistent(c); Assert.AreEqual("65534", ColumnTests.GetMatches(c, Operator.Equals, firstValue)); Assert.AreEqual("65533", ColumnTests.GetMatches(c, Operator.Equals, lastValue)); IList <ushort> sortedIndexes; int sortedIndexesCount; Assert.IsTrue(c.TryGetSortedIndexes(out sortedIndexes, out sortedIndexesCount)); // Check sort order - lowest one was the last value added Assert.AreEqual("65534", sortedIndexes.First().ToString()); Assert.AreEqual("65533", sortedIndexes.Last().ToString()); }
public void SortedColumn_StartsWith() { SortedColumn <ByteBlock> column = ColumnFactory.CreateSortedColumn <ByteBlock>(new ByteBlockColumn(ByteBlock.Zero), 0); column.SetSize(6); column[0] = "Active"; column[1] = "Activate"; column[2] = "Activity"; column[3] = "Resolved"; column[4] = "Resolution"; column[5] = "State"; CommitIfRequired(column); Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(column, Operator.StartsWith, "Activ")); Assert.AreEqual("1", ColumnTests.GetMatches(column, Operator.StartsWith, "Activa")); Assert.AreEqual("", ColumnTests.GetMatches(column, Operator.StartsWith, "Balmy")); Assert.AreEqual("3, 4", ColumnTests.GetMatches(column, Operator.StartsWith, "Reso")); Assert.AreEqual("3", ColumnTests.GetMatches(column, Operator.StartsWith, "Resolv")); Assert.AreEqual("5", ColumnTests.GetMatches(column, Operator.StartsWith, "St")); }
public void SortedColumn_Where() { SortedColumn <int> c = ColumnFactory.CreateSortedColumn <int>(new ValueTypeColumn <int>(-1), 0); c.SetSize(8); c[0] = 0; c[1] = 1; c[2] = 1; c[3] = 2; c[4] = 2; c[5] = 8; c[6] = 8; c[7] = 9; ColumnTests.AssertConsistent(c); // Find a middle value Assert.AreEqual("3, 4", ColumnTests.GetMatches(c, Operator.Equals, 2)); // Find the minimum value Assert.AreEqual("0", ColumnTests.GetMatches(c, Operator.Equals, 0)); // Find the maximum value Assert.AreEqual("7", ColumnTests.GetMatches(c, Operator.Equals, 9)); // Find a value not in set (too small) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Equals, -1)); // Find a value not in set (too big) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.Equals, 10)); // Find not of a value Assert.AreEqual("0, 1, 2, 5, 6, 7", ColumnTests.GetMatches(c, Operator.NotEquals, 2)); // Find not of a value not in set Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.NotEquals, -1)); // Find less than not in set (too small) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.LessThan, -1)); // Find less than an existing value Assert.AreEqual("0, 1, 2", ColumnTests.GetMatches(c, Operator.LessThan, 2)); // Find less than a gap between values Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThan, 4)); // Find less than more than set (too big) Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.LessThan, 99)); // Find less than or equal not in set (too small) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, -1)); // Find less than or equal an existing value Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 2)); // Find less than or equal a gap between values Assert.AreEqual("0, 1, 2, 3, 4", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 4)); // Find less than or equal more than set (too big) Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.LessThanOrEqual, 99)); // Find greater than not in set (too small) Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, -1)); // Find greater than an existing value Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, 2)); // Find greater than a gap between values Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThan, 4)); // Find greater than more than set (too big) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.GreaterThan, 99)); // Find greater than or equal not in set (too small) Assert.AreEqual("0, 1, 2, 3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, -1)); // Find greater than or equal an existing value Assert.AreEqual("3, 4, 5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 2)); // Find greater than or equal a gap between values Assert.AreEqual("5, 6, 7", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 4)); // Find greater than or equal more than set (too big) Assert.AreEqual("", ColumnTests.GetMatches(c, Operator.GreaterThanOrEqual, 99)); // Verify sorting consistency problems are detected ((IColumn <int>)c.InnerColumn)[0] = 8; ExecutionDetails d = new ExecutionDetails(); c.VerifyConsistency(VerificationLevel.Full, d); Assert.IsFalse(d.Succeeded); }