Beispiel #1
0
        public void GivenNeedleInHaystack_WhenSimpleSearchIsInvoked_ThenIndexOfNeedleIsReturned(int needle)
        {
            // Arrange
            var haystack = Enumerable.Range(1, 100).ToArray();

            // Act
            var result = NumberSearcher.SimpleSearch(haystack, needle);

            // Assert
            Assert.Equal(needle - 1, result); // Index is 0 based, so e.g. number 99 is at position 98.
        }
Beispiel #2
0
        public void GivenNeedleNotInHaystack_WhenSimpleSearchIsInvoked_ThenNotFoundValueIsReturned()
        {
            // Arrange
            var haystack = Enumerable.Range(1, 100).ToArray();
            var needle   = 101;

            // Act
            var result = NumberSearcher.SimpleSearch(haystack, needle);

            // Assert
            Assert.Equal(-1, result);
        }