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; | |
} | |
} | |
} |
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