/* Randomized tests */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSplitCorrectly() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSplitCorrectly() { // GIVEN using (GBPTree <KEY, VALUE> index = index()) { // WHEN int count = 1_000; IList <KEY> seen = new List <KEY>(count); using (Writer <KEY, VALUE> writer = index.Writer()) { for (int i = 0; i < count; i++) { KEY key; do { key = key(_random.Next(100_000)); } while (ListContains(seen, key)); VALUE value = value(i); writer.Put(key, value); seen.Add(key); } } // THEN using (RawCursor <Hit <KEY, VALUE>, IOException> cursor = index.Seek(Key(0), Key(long.MaxValue))) { long prev = -1; while (cursor.Next()) { KEY hit = cursor.get().key(); long hitSeed = _layout.keySeed(hit); if (hitSeed < prev) { fail(hit + " smaller than prev " + prev); } prev = hitSeed; assertTrue(RemoveFromList(seen, hit)); } if (seen.Count > 0) { fail("expected hits " + seen); } } } }
private long KeySeed(KEY key) { return(_layout.keySeed(key)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStayCorrectAfterRandomModifications() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStayCorrectAfterRandomModifications() { // GIVEN using (GBPTree <KEY, VALUE> index = CreateIndex()) { IComparer <KEY> keyComparator = _layout; IDictionary <KEY, VALUE> data = new SortedDictionary <KEY, VALUE>(keyComparator); int count = 100; int totalNumberOfRounds = 10; for (int i = 0; i < count; i++) { data[RandomKey(Random.random())] = RandomValue(Random.random()); } // WHEN using (Writer <KEY, VALUE> writer = CreateWriter(index)) { foreach (KeyValuePair <KEY, VALUE> entry in data.SetOfKeyValuePairs()) { writer.Put(entry.Key, entry.Value); } } for (int round = 0; round < totalNumberOfRounds; round++) { // THEN for (int i = 0; i < count; i++) { KEY first = RandomKey(Random.random()); KEY second = RandomKey(Random.random()); KEY from; KEY to; if (_layout.keySeed(first) < _layout.keySeed(second)) { from = first; to = second; } else { from = second; to = first; } IDictionary <KEY, VALUE> expectedHits = expectedHits(data, from, to, keyComparator); using (RawCursor <Hit <KEY, VALUE>, IOException> result = index.Seek(from, to)) { while (result.Next()) { KEY key = result.get().key(); if (expectedHits.Remove(key) == null) { fail("Unexpected hit " + key + " when searching for " + from + " - " + to); } assertTrue(keyComparator.Compare(key, from) >= 0); if (keyComparator.Compare(from, to) != 0) { assertTrue(keyComparator.Compare(key, to) < 0); } } if (expectedHits.Count > 0) { fail("There were results which were expected to be returned, but weren't:" + expectedHits + " when searching range " + from + " - " + to); } } } index.Checkpoint(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited); RandomlyModifyIndex(index, data, Random.random(), (double)round / totalNumberOfRounds); } // and finally index.ConsistencyCheck(); } }