When you create test cases you normally want to check all transitions between states or values. So how do you get a list of values to cover all transitions?
Well I started to Google, could not find any good example, probably because I didn’t use the correct word.
Then I asked Gemini and got some code, that didn’t work. And then some updated code, that didn’t work, and then….
Back to paper and pen and found a quite simple soulution.
public static int[] GenerateAllTransitionSeries(int[] numbers)
{
if (numbers.Length < 2) throw new ArgumentException("Invalid array size, must be at least 2", nameof(numbers));
int size = numbers.Length;
List<int> series = new List<int>();
int top = size - 1;
int back = top - 1;
for (int i = 0; i < size; i++)
{
series.Add(numbers[i]);
}
series.Add(numbers[back]);
if (back > 0)
{
back--;
series.Add(numbers[back]);
int index = top;
while (true)
{
series.Add(numbers[index]);
if (index == top)
{
series.Add(numbers[back]);
if (back == 0)
{
break;
}
back--;
index = back + 1;
}
index++;
series.Add(numbers[back]);
}
}
return series.ToArray();
}