-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace us.fatehi.palindrome | ||
{ | ||
public class Palindrome | ||
{ | ||
public bool IsPalindrome(string word) | ||
{ | ||
// Exit early for trivial cases, such as null, | ||
// empty string, and a word with a single letter | ||
if (word == null || word.Length < 2) | ||
{ | ||
return true; | ||
} | ||
|
||
var firstChar = word[0]; | ||
var lastChar = word[^1]; | ||
var center = word[1..^1]; | ||
return (firstChar == lastChar) && IsPalindrome(center); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using NUnit.Framework; | ||
using us.fatehi.palindrome; | ||
|
||
namespace us.fatehi.palindrome.test | ||
{ | ||
|
||
[TestFixture] | ||
public class BetterPalindromeTest | ||
{ | ||
private readonly Palindrome _p = new Palindrome(); | ||
|
||
[Test] | ||
public void BoundaryConditionHappy() | ||
{ | ||
Assert.That(_p.IsPalindrome("oo")); | ||
} | ||
|
||
[Test] | ||
public void BoundaryConditionNegative() | ||
{ | ||
Assert.That(_p.IsPalindrome("ah"), Is.False); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using NUnit.Framework; | ||
using us.fatehi.palindrome; | ||
|
||
namespace us.fatehi.palindrome.test | ||
{ | ||
|
||
[TestFixture] | ||
public class MorePalindromeTest | ||
{ | ||
private readonly Palindrome _p = new Palindrome(); | ||
|
||
[Test] | ||
public void AlmostPalindrome() | ||
{ | ||
Assert.That(_p.IsPalindrome("polyp"), Is.False); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using NUnit.Framework; | ||
using us.fatehi.palindrome; | ||
|
||
namespace us.fatehi.palindrome.test | ||
{ | ||
|
||
[TestFixture] | ||
public class PalindromeTest | ||
{ | ||
private readonly Palindrome _p = new Palindrome(); | ||
|
||
[Test] | ||
public void EdgeCaseNull() | ||
{ | ||
Assert.That(_p.IsPalindrome(null)); | ||
} | ||
|
||
[Test] | ||
public void EdgeCaseEmptyString() | ||
{ | ||
Assert.That(_p.IsPalindrome("")); | ||
} | ||
|
||
[Test] | ||
public void HappyPathSingleLetter() | ||
{ | ||
Assert.That(_p.IsPalindrome("a")); | ||
} | ||
|
||
[Test] | ||
public void HappyPathEvenLetters() | ||
{ | ||
Assert.That(_p.IsPalindrome("noon")); | ||
} | ||
|
||
[Test] | ||
public void HappyPathOddLetters() | ||
{ | ||
Assert.That(_p.IsPalindrome("racecar")); | ||
} | ||
|
||
[Test] | ||
public void NegativeCase() | ||
{ | ||
Assert.That(_p.IsPalindrome("burning"), Is.False); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageReference Include="NUnit" Version="4.1.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Palindrome\Palindrome.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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