public override void AddRange(int min, int max, int shift) { Assert.IsTrue(min >= lower && min <= upper && max >= lower && max <= upper, "min, max should be inside bounds"); if (useBitSet) { for (int i = min; i <= max; i++) { Assert.IsFalse(bits.GetAndSet(i - lower), "ranges should not overlap"); // extra exit condition to prevent overflow on MAX_VALUE if (i == max) { break; } } } if (neededBounds is null) { return; } // make unsigned ints for easier display and understanding min ^= unchecked ((int)0x80000000); max ^= unchecked ((int)0x80000000); //System.out.println("0x"+Integer.toHexString(min>>>shift)+",0x"+Integer.toHexString(max>>>shift)+")/*shift="+shift+"*/,"); neededShifts.MoveNext(); Assert.AreEqual(neededShifts.Current, shift, "shift"); neededBounds.MoveNext(); Assert.AreEqual(neededBounds.Current, min.TripleShift(shift), "inner min bound"); neededBounds.MoveNext(); Assert.AreEqual(neededBounds.Current, max.TripleShift(shift), "inner max bound"); }
public virtual void Test() { RollingBuffer <Position> buffer = new RollingBufferAnonymousInnerClassHelper(this); for (int iter = 0; iter < 100 * RANDOM_MULTIPLIER; iter++) { int freeBeforePos = 0; int maxPos = AtLeast(10000); FixedBitSet posSet = new FixedBitSet(maxPos + 1000); int posUpto = 0; Random random = Random(); while (freeBeforePos < maxPos) { if (random.Next(4) == 1) { int limit = Rarely() ? 1000 : 20; int inc = random.Next(limit); int pos = freeBeforePos + inc; posUpto = Math.Max(posUpto, pos); if (VERBOSE) { Console.WriteLine(" check pos=" + pos + " posUpto=" + posUpto); } Position posData = buffer.Get(pos); if (!posSet.GetAndSet(pos)) { Assert.AreEqual(-1, posData.Pos); posData.Pos = pos; } else { Assert.AreEqual(pos, posData.Pos); } } else { if (posUpto > freeBeforePos) { freeBeforePos += random.Next(posUpto - freeBeforePos); } if (VERBOSE) { Console.WriteLine(" freeBeforePos=" + freeBeforePos); } buffer.FreeBefore(freeBeforePos); } } buffer.Reset(); } }