31 lines
739 B
C#
31 lines
739 B
C#
var sol = new Solution();
|
|
|
|
var cases = new (int[] input, int[] expected)[]
|
|
{
|
|
(new[] { 1, 2, 3 }, new[] { 1, 3, 2 }),
|
|
(new[] { 3, 2, 1 }, new[] { 1, 2, 3 }),
|
|
(new[] { 1, 1, 5 }, new[] { 1, 5, 1 })
|
|
};
|
|
|
|
foreach (var (input, expected) in cases)
|
|
{
|
|
var nums = (int[])input.Clone();
|
|
sol.NextPermutation(nums);
|
|
var status = AreEqual(nums, expected) ? "ok" : "fail";
|
|
Console.WriteLine($"{Format(input)} -> {Format(nums)} (expected: {Format(expected)}) {status}");
|
|
}
|
|
|
|
static string Format(int[] nums) => $"[{string.Join(",", nums)}]";
|
|
|
|
static bool AreEqual(int[] left, int[] right)
|
|
{
|
|
if (left.Length != right.Length)
|
|
return false;
|
|
for (var i = 0; i < left.Length; i++)
|
|
{
|
|
if (left[i] != right[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|