-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDataGenerator.cs
51 lines (46 loc) · 1.36 KB
/
DataGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace StackOnlyJsonParser.PerformanceTests
{
internal class DataGenerator
{
private static readonly string[] Colors = new[] { "red", "green", "blue", "orange", "black" };
private static readonly Dictionary<string, string> Regions = new Dictionary<string, string> { ["PL"] = "PLN", ["NL"] = "EUR", ["GER"] = "EUR", ["US"] = "USD", ["CZ"] = "CZK" };
private readonly Random _random = new Random(0);
public byte[] Generate(int elements)
{
var data = Enumerable
.Repeat(0, elements)
.Select(_ => new
{
Name = NextName(),
BoxSize = new
{
Width = _random.Next(10000) * 0.01,
Height = _random.Next(10000) * 0.01,
Depth = _random.Next(10000) * 0.01,
},
AvailableItems = _random.Next(0, 10),
Colors = Colors.Where(_ => _random.Next(2) > 0),
Regions = Regions.Where(_ => _random.Next(3) > 0).ToDictionary(
e => e.Key,
e => new {
Currency = e.Value,
Value = _random.Next(100, 10000) / 100m
})
});
return JsonSerializer.SerializeToUtf8Bytes(data);
}
private string NextName()
{
return new string(Enumerable
.Repeat('A', _random.Next(5, 10))
.Select(l => (char)(l + _random.Next(0, 23)))
.ToArray());
}
}
}