Created
August 11, 2014 20:00
-
-
Save rlbisbe/9020982ddc30a39585e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Sample.WithLimits | |
{ | |
class UppercaseSearcher | |
{ | |
internal static int[] Search(string source) | |
{ | |
return Search(source, 0); | |
} | |
internal static int[] Search(string source, int index) | |
{ | |
if (IsOutOfBounds(source, index)) | |
{ | |
return new int[0]; | |
} | |
if (char.IsUpper(source, index)) | |
{ | |
return new int[] { index } | |
.Concat(Search(source, index + 1)) | |
.ToArray(); | |
} | |
else | |
{ | |
return Search(source, index + 1) | |
.ToArray(); | |
} | |
} | |
private static bool IsOutOfBounds(string source, int index) | |
{ | |
return source.Length == 0 || index >= source.Length; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Xunit; | |
namespace Sample.WithLimits | |
{ | |
public class TestClass | |
{ | |
[Fact] | |
public void ShouldReturnEmptyArray() | |
{ | |
//Arrange, act, assert | |
Assert.Equal(new int[0], UppercaseSearcher.Search("")); | |
} | |
[Fact] | |
public void ShouldReturn0IfOneLetterIsUppercase() | |
{ | |
//Arrange, act, assert | |
Assert.Equal(new int[] {0}, UppercaseSearcher.Search("A")); | |
} | |
[Fact] | |
public void ShouldReturn1IfSecondLetterIsUppercase() | |
{ | |
//Arrange, act, assert | |
Assert.Equal(new int[] { 1 }, UppercaseSearcher.Search("bA")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment