public void Ext_UInt_AddGet_BitsMax_InOut() { BVector d = new BVector(); uint value; uint val; uint expected; uint maxVal = uint.MaxValue; byte bits; // add max values for 2-32 bits for (int i = 0; i < 31; i++) { bits = (byte)(32 - i); value = maxVal >> i; // add max d.Add(value, bits); } // add max values for 2-32 bits seperated by 1 bit d.Add1(false); for (int i = 0; i < 31; i++) { bits = (byte)(32 - i); value = maxVal >> i; // add max d.Add(value, bits); d.Add1(false); } BVector d2 = new BVector(d.ToBytes()); // get max values for 2-32 bits for (int i = 0; i < 31; i++) { bits = (byte)(32 - i); // get max expected = maxVal >> i; val = d2.GetUInt(bits); Assert.AreEqual(expected, val); } // get max values for 2-32 bits seperated by 1 bit Assert.AreEqual(false, d2.Get1()); for (int i = 0; i < 31; i++) { bits = (byte)(32 - i); // get max expected = maxVal >> i; val = d2.GetUInt(bits); Assert.AreEqual(expected, val); Assert.AreEqual(false, d2.Get1()); } }
public void Ext_UInt_Get_Exc_LessThan2Bits_Loopback() { BVector d = new BVector(); d.Add(0, 32); d.GetUInt(1); }
public void Ext_UInt_Get_Exc_MoreThan32Bits_Loopback() { BVector d = new BVector(); d.Add(0, 32); d.GetUInt(33); }
public void Ext_UInt_AddGet_Rnd_InOut() { int maxBits = 32; int index = 0; byte bits; uint value; uint expected; const uint maxValue = uint.MaxValue; uint rngMax; var rnd = new CryptoRandom(); List <uint> values = new List <uint>(); // number of items to add per bit int itemsCount = 1_000; BVector d = new BVector(); for (int j = 2; j <= maxBits; j++) { rngMax = maxValue >> (maxBits - j); bits = (byte)j; for (int i = 0; i < itemsCount; i++) { // add positive value = (uint)rnd.NextLong(rngMax); d.Add(value, bits); values.Add(value); d.Add1(false); } } BVector d2 = d; for (int j = 2; j < maxBits; j++) { bits = (byte)j; for (int i = 0; i < itemsCount; i++) { // read positive value = d2.GetUInt(bits); expected = values[index]; Assert.AreEqual(expected, value); Assert.AreEqual(false, d2.Get1()); index++; } } }