public void LongN_AddGet_BitsMinMax_Sequence_Loopback() { int maxBits = 64; List <long?> values = new List <long?>(); BVector d = new BVector(); long? positiveValue; long? negativeValue; long? actualValue; long? nullValue = null; int index; long? expected; long? maxVal = long.MaxValue; byte bits; // add min and max values for 2-64 bits for (int i = 0; i < (maxBits - 1); i++) { bits = (byte)(maxBits - i); positiveValue = maxVal >> i; negativeValue = -positiveValue - 1; // add positive d.Add(positiveValue, bits); values.Add(positiveValue); // add null d.Add(nullValue, bits); values.Add(nullValue); // add negative d.Add(negativeValue, bits); values.Add(negativeValue); } // get min and max values for 2-64 bits index = 0; for (int i = 0; i < (maxBits - 1); i++) { bits = (byte)(maxBits - i); // get positive expected = values[index++]; actualValue = d.GetLongN(bits); Assert.AreEqual(expected, actualValue); // get null expected = values[index++]; actualValue = d.GetLongN(bits); Assert.AreEqual(expected, actualValue); // get negative expected = values[index++]; actualValue = d.GetLongN(bits); Assert.AreEqual(expected, actualValue); } }
public void LongN_Get_Exc_MoreThan64Bits_Loopback() { BVector d = new BVector(); d.Add((long?)0, 32); d.GetLongN(65); }
public void LongN_Get_Exc_LessThan2Bits_Loopback() { BVector d = new BVector(); d.Add((long?)0, 32); d.GetLongN(1); }
public void LongN_AddGet_Rnd_Sequence_Loopback() { int maxBits = 64; List <long?> values = new List <long?>(); BVector d = new BVector(); long? actualValue; int index; long? expected; long? maxVal = long.MaxValue; byte bits; var rnd = new CryptoRandom(); int itemsPerBit = 10000; long? value; long tmp; // add random values for 2-64 bits for (int j = 0; j < itemsPerBit; j++) { for (int i = 0; i < (maxBits - 2); i++) { bits = (byte)(maxBits - i); tmp = maxVal.Value >> (i + 1); // add random value value = rnd.NextLong(-tmp - 1, tmp); values.Add(value); d.Add(value, bits); } } // get values for 2-64 bits index = 0; for (int j = 0; j < itemsPerBit; j++) { for (int i = 0; i < (maxBits - 2); i++) { bits = (byte)(maxBits - i); // get value expected = values[index]; actualValue = d.GetLongN(bits); Assert.AreEqual(expected, actualValue); index++; } } }
/// <summary> /// Reads the next random value added by <see cref="WriteRandomValue(BVector)"/> /// </summary> /// <param name="d"></param> /// <returns></returns> public static object ReadNextRandomValue(BVector d) { bool nullable = d.Get1(); byte valueType = d.Get8(); switch (valueType) { case 0: if (nullable) { return(d.GetIntN()); } return(d.GetInt()); case 1: if (nullable) { return(d.GetLongN()); } return(d.GetLong()); case 2: if (nullable) { return(d.GetShortN()); } return(d.GetShort()); case 3: if (nullable) { return(d.GetByteN()); } return(d.GetByte()); case 4: return(d.GetString()); case 5: return(d.GetAscii()); case 6: if (nullable) { return(d.GetDateTimeN()); } return(d.GetDateTime()); case 7: if (nullable) { return(d.GetDecimalN()); } return(d.GetDecimal()); case 8: if (nullable) { return(d.GetDoubleN()); } return(d.GetDouble()); case 9: return(d.Get1()); case 10: return(d.GetTimeSpan()); case 11: return(d.GetByteArray()); } return(null); }