private POCOMultiTypeObject CreateRandomPoco(bool nullableSetNull = false) { var randomizer = new Bogus.Randomizer(); var poco = new POCOMultiTypeObject() { BoolField = randomizer.Bool(), DateTimeField = DateTime.Now, NDateTimeField = (nullableSetNull) ? (DateTime?)null : DateTime.Now, StrDateTime = (nullableSetNull) ? (string)null : DateTime.Now.ToShortTimeString(), DoubleField = randomizer.Double(), FloatField = randomizer.Float(), GuidField = randomizer.Guid(), NGuidField = (nullableSetNull) ? (Guid?)null : randomizer.Guid(), ID = randomizer.Int(), IntField = randomizer.Int(), LongField = randomizer.Long(), NBoolField = (nullableSetNull) ? (bool?)null : randomizer.Bool(), NDoubleField = (nullableSetNull) ? (double?)null : randomizer.Double(), NFloatField = (nullableSetNull) ? (float?)null : randomizer.Float(), NIntField = (nullableSetNull) ? (int?)null : randomizer.Int(), NLongField = (nullableSetNull) ? (long?)null : randomizer.Long(), //RowID = randomizer.Int(), StringField = randomizer.String2(16), }; return(poco); }
public void Setup() { List <byte[]> bytesList = new List <byte[]>(Size); List <byte[]> bytesList2 = new List <byte[]>(Size); List <byte[]> bytesList3 = new List <byte[]>(Size); List <MyTestClass> testClasses = new List <MyTestClass>(Size); var bogus = new Bogus.Randomizer(); for (int i = 0; i < Size; i++) { MyTestClass myTestClass = new MyTestClass(); myTestClass.BoolProp = bogus.Bool(); myTestClass.IntList = new List <int>(100); for (int j = 0; j < 100; j++) { myTestClass.IntList.Add(bogus.Int()); } myTestClass.StringProp = bogus.String(10, 100); myTestClass.StringProp2 = bogus.String(10, 100); bytesList.Add(JsonSerializer.Serialize(myTestClass)); bytesList3.Add(System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(myTestClass)); bytesList2.Add(MessagePack.MessagePackSerializer.Typeless.Serialize(myTestClass, ContractlessStandardResolver.Options)); testClasses.Add(myTestClass); } _serializedObjectsUtf8Json = bytesList.ToArray(); _serializedObjectsMessagePack = bytesList2.ToArray(); _serializedObjectsTextJson = bytesList3.ToArray(); _testClasses = testClasses.ToArray(); }
public void Setup() { var rand = new Bogus.Randomizer(); // generate input data, e.g.: [ t, f, f, t, t, t, f ] bool[] data = Enumerable .Range(0, Length) .Select(_ => rand.Bool()) .ToArray(); // generate indexes to check, e.g.: [ 5, 2, 0, 6, 9, 1, 8, 3 ] // (we don't really care whether bit is set or not; we need same indexes for all benchmarks) _idx = Enumerable .Range(0, Length) .Select(_ => rand.Int(0, Length - 1)) .ToArray(); // only `true` values are stored, missing value means bit is not set _bitArray = new System.Collections.BitArray(data); _map = new Dictionary <int, bool>( data.Select((v, i) => KeyValuePair.Create(i, v)) .Where(kv => kv.Value)); _set = new HashSet <int>( data.Select((v, i) => (v, i)) .Where(t => t.v) .Select(t => t.i)); }
public static string BuildTestString(string pattern) { if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(pattern)); } var randomizer = new Bogus.Randomizer(); const int noMatchPercentage = 50; if (WeightedMatch(noMatchPercentage)) { return(randomizer.String()); } const int charMatchPercentage = 95; var strBuilder = new StringBuilder(pattern.Length * 2); foreach (var patternCh in pattern) { if (patternCh == '?') { strBuilder.Append(randomizer.AlphaNumeric(1)); } else if (patternCh == '*') { strBuilder.Append(randomizer.Words()); } else { if (WeightedMatch(charMatchPercentage)) { strBuilder.Append(patternCh); } } } var str = strBuilder.ToString(); return(str); bool WeightedMatch(int percentage) { return(randomizer.Bool(percentage / 100f)); } }