-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummyRandom.cs
More file actions
60 lines (48 loc) · 1.53 KB
/
Copy pathDummyRandom.cs
File metadata and controls
60 lines (48 loc) · 1.53 KB
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
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
namespace CodingRange
{
public class DummyRandom
{
private readonly Random _random;
private readonly (int, int, int)[] _outputs;
private readonly Queue<(int, int, int)> _queue;
private readonly bool _interactive = false;
public DummyRandom()
{
_interactive = true;
_random = new();
}
public DummyRandom(params (int, int, int)[] outputs)
{
_queue = new();
_outputs = outputs;
foreach (var x in outputs)
{
_queue.Enqueue(x);
}
}
public int Next(int max) => Next(0, max);
public int Next(int min, int max)
{
if (_interactive)
{
return _random.Next(min, max);
}
if (_queue.Count == 0)
{
throw new Exception("Error! No more random values are available for this test case!");
}
(var fMin, var fMax, var x) = _queue.Dequeue();
if (fMin != min || fMax != max)
{
throw new ArgumentException($"You called Next({min}, {max}) but backend expected Next({fMin}, {fMax})!");
}
return x;
}
#pragma warning disable IDE0051
private int[] Outputs => _outputs.Select(x => x.Item3).ToArray(); // called by reflection for grading.
#pragma warning restore IDE0051
}
}