|
| 1 | +using System; |
| 2 | +using Algorithms.Stack; |
| 3 | +using NUnit.Framework; |
| 4 | + |
| 5 | +namespace Algorithms.Tests.Stack |
| 6 | +{ |
| 7 | + [TestFixture] |
| 8 | + public class NextGreaterElementTests |
| 9 | + { |
| 10 | + private static int[] FindNextGreaterElement(int[] input) |
| 11 | + { |
| 12 | + var obj = new NextGreaterElement(); |
| 13 | + return obj.FindNextGreaterElement(input); |
| 14 | + } |
| 15 | + |
| 16 | + [Test] |
| 17 | + public void FindNextGreaterElement_InputIsEmpty_ReturnsEmptyArray() |
| 18 | + { |
| 19 | + // Arrange |
| 20 | + int[] input = Array.Empty<int>(); |
| 21 | + int[] expected = Array.Empty<int>(); |
| 22 | + |
| 23 | + // Act |
| 24 | + var result = FindNextGreaterElement(input); |
| 25 | + |
| 26 | + // Assert |
| 27 | + Assert.That(result, Is.EqualTo(expected)); |
| 28 | + } |
| 29 | + |
| 30 | + [Test] |
| 31 | + public void FindNextGreaterElement_BasicScenario_ReturnsCorrectResult() |
| 32 | + { |
| 33 | + // Arrange |
| 34 | + int[] input = { 4, 5, 2, 25 }; |
| 35 | + int[] expected = { 5, 25, 25, -1 }; |
| 36 | + |
| 37 | + // Act |
| 38 | + var result = FindNextGreaterElement(input); |
| 39 | + |
| 40 | + // Assert |
| 41 | + Assert.That(result, Is.EqualTo(expected)); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void FindNextGreaterElement_NoNextGreaterElement_ReturnsCorrectResult() |
| 46 | + { |
| 47 | + // Arrange |
| 48 | + int[] input = { 13, 7, 6, 12 }; |
| 49 | + int[] expected = { -1, 12, 12, -1 }; |
| 50 | + |
| 51 | + // Act |
| 52 | + var result = FindNextGreaterElement(input); |
| 53 | + |
| 54 | + // Assert |
| 55 | + Assert.That(result, Is.EqualTo(expected)); |
| 56 | + } |
| 57 | + |
| 58 | + [Test] |
| 59 | + public void FindNextGreaterElement_AllElementsHaveNoGreaterElement_ReturnsAllNegativeOnes() |
| 60 | + { |
| 61 | + // Arrange |
| 62 | + int[] input = { 5, 4, 3, 2, 1 }; |
| 63 | + int[] expected = { -1, -1, -1, -1, -1 }; |
| 64 | + |
| 65 | + // Act |
| 66 | + var result = FindNextGreaterElement(input); |
| 67 | + |
| 68 | + // Assert |
| 69 | + Assert.That(result, Is.EqualTo(expected)); |
| 70 | + } |
| 71 | + |
| 72 | + [Test] |
| 73 | + public void FindNextGreaterElement_InputWithDuplicates_ReturnsCorrectResult() |
| 74 | + { |
| 75 | + // Arrange |
| 76 | + int[] input = { 4, 4, 3, 2, 4 }; |
| 77 | + int[] expected = { -1, -1, 4, 4, -1 }; |
| 78 | + |
| 79 | + // Act |
| 80 | + var result = FindNextGreaterElement(input); |
| 81 | + |
| 82 | + // Assert |
| 83 | + Assert.That(result, Is.EqualTo(expected)); |
| 84 | + } |
| 85 | + |
| 86 | + [Test] |
| 87 | + public void FindNextGreaterElement_SingleElementArray_ReturnsNegativeOne() |
| 88 | + { |
| 89 | + // Arrange |
| 90 | + int[] input = { 10 }; |
| 91 | + int[] expected = { -1 }; |
| 92 | + |
| 93 | + // Act |
| 94 | + var result = FindNextGreaterElement(input); |
| 95 | + |
| 96 | + // Assert |
| 97 | + Assert.That(result, Is.EqualTo(expected)); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments