-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestArrayGenerator.cs
75 lines (63 loc) · 2.07 KB
/
TestArrayGenerator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
namespace Common.TestData;
public static class TestArrayGenerator
{
public static int[] GetAscendingArray(int itemsCount, int start = 0, int maxIncrement = 1)
{
int[] nums = new int[itemsCount];
for (int i = 0; i < itemsCount; i++)
{
nums[i] = start;
start += Random.Shared.Next(1, maxIncrement + 1);
}
return nums;
}
public static int[] GetDescendingArray(int itemsCount, int start = 0, int maxIncrement = 1)
{
int[] nums = new int[itemsCount];
for (int i = 0; i < itemsCount; i++)
{
nums[i] = start;
start -= Random.Shared.Next(1, maxIncrement + 1);
}
return nums;
}
public static int[] RotateArray(int[] nums, int rotateTimes)
{
var rotatedNums = new int[nums.Length];
for (int i = 0; i < rotatedNums.Length; i++)
{
rotatedNums[i] = nums[(i + rotateTimes) % nums.Length];
}
return rotatedNums;
}
public static int[] GetAscendingRotatedArray(int itemsCount, int minValue, int rotateTimes)
{
var nums = GetAscendingArray(itemsCount, minValue);
var rotatedNums = RotateArray(nums, rotateTimes);
return rotatedNums;
}
public static int[] GetDescendingRotatedArray(int itemsCount, int minValue, int rotateTimes)
{
var nums = GetDescendingArray(itemsCount, minValue);
var rotatedNums = RotateArray(nums, rotateTimes);
return rotatedNums;
}
public static int[] GetRandomArray(int itemsCount = 10000,
int elementsMinValue = int.MinValue,
int elementsMaxValue = int.MaxValue, bool exceptZeros = false)
{
var testArray = new int[itemsCount];
for (int i = 0; i < testArray.Length; i++)
{
var value = Random.Shared.Next(elementsMinValue, elementsMaxValue + 1);
if (exceptZeros && value == 0)
{
i--;
continue;
}
testArray[i] = value;
}
return testArray;
}
}