Created
October 8, 2014 23:12
-
-
Save jamesfoster/be9dc2013ff9bf3f3c2f 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 NUnit.Framework; | |
namespace Interview | |
{ | |
public class AnagramChecker | |
{ | |
public bool IsAnagram(string first, string second) | |
{ | |
return false; | |
} | |
} | |
[TestFixture] | |
public class AnagramCheckerTests | |
{ | |
private AnagramChecker anagramChecker; | |
[SetUp] | |
public void SetUp() | |
{ | |
anagramChecker = new AnagramChecker(); | |
} | |
[Test] | |
public void AnagramTests() | |
{ | |
AssertNotAnagram(null, null); | |
AssertNotAnagram(null, ""); | |
AssertNotAnagram("", null); | |
AssertAnagram("", ""); | |
AssertNotAnagram("a", ""); | |
AssertAnagram("a", "a"); | |
AssertNotAnagram("a", "b"); | |
AssertAnagram("ab", "ba"); | |
AssertAnagram("abc", "acb"); | |
AssertAnagram("abc", "bca"); | |
AssertAnagram("abc", "cab"); | |
AssertAnagram("technically", "lnicelyacht"); | |
} | |
[Test, Ignore("Advanced")] | |
public void AdvancedAnagramTests() | |
{ | |
AssertAnagram("The eyes", "They see"); | |
AssertAnagram("Mother-in-law", "Woman Hitler"); | |
} | |
private void AssertAnagram(string first, string second) | |
{ | |
Assert.IsTrue( | |
anagramChecker.IsAnagram(first, second), | |
string.Format("Expected \"{0}\" to be an anagram of \"{1}\"", first, second)); | |
} | |
private void AssertNotAnagram(string first, string second) | |
{ | |
Assert.IsFalse( | |
anagramChecker.IsAnagram(first, second), | |
string.Format("Expected \"{0}\" not to be an anagram of \"{1}\"", first, second)); | |
} | |
} | |
} |
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 NUnit.Framework; | |
namespace Interview | |
{ | |
public class FizzBuzz | |
{ | |
public string ToFizzBuzz(int number) | |
{ | |
return null; | |
} | |
} | |
[TestFixture] | |
public class FizzBuzzTests | |
{ | |
private FizzBuzz fizzBuzz; | |
[SetUp] | |
public void SetUp() | |
{ | |
fizzBuzz = new FizzBuzz(); | |
} | |
[Test] | |
public void Outputs_FizzBuzz_Numbers() | |
{ | |
AssertFizzBuzz(1, "1"); | |
AssertFizzBuzz(2, "2"); | |
AssertFizzBuzz(3, "Fizz"); | |
AssertFizzBuzz(4, "4"); | |
AssertFizzBuzz(5, "Buzz"); | |
AssertFizzBuzz(6, "Fizz"); | |
AssertFizzBuzz(7, "7"); | |
AssertFizzBuzz(8, "8"); | |
AssertFizzBuzz(9, "Fizz"); | |
AssertFizzBuzz(10, "Buzz"); | |
AssertFizzBuzz(11, "11"); | |
AssertFizzBuzz(12, "Fizz"); | |
AssertFizzBuzz(13, "13"); | |
AssertFizzBuzz(14, "14"); | |
AssertFizzBuzz(15, "FizzBuzz"); | |
AssertFizzBuzz(16, "16"); | |
AssertFizzBuzz(17, "17"); | |
AssertFizzBuzz(18, "Fizz"); | |
AssertFizzBuzz(19, "19"); | |
AssertFizzBuzz(20, "Buzz"); | |
AssertFizzBuzz(21, "Fizz"); | |
} | |
private void AssertFizzBuzz(int number, string expected) | |
{ | |
Assert.AreEqual( | |
expected, | |
fizzBuzz.ToFizzBuzz(number)); | |
} | |
} | |
} |
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 NUnit.Framework; | |
namespace Interview | |
{ | |
public class PalindromeChecker | |
{ | |
public bool IsPalindrome(string value) | |
{ | |
return false;n | |
} | |
} | |
[TestFixture] | |
public class PalindromeCheckerTests | |
{ | |
private PalindromeChecker palindromeChecker; | |
[SetUp] | |
public void SetUp() | |
{ | |
palindromeChecker = new PalindromeChecker(); | |
} | |
[Test] | |
public void PalindromeTests() | |
{ | |
AssertNotPalindrome(null); | |
AssertPalindrome(""); | |
AssertPalindrome("a"); | |
AssertNotPalindrome("ab"); | |
AssertPalindrome("aa"); | |
AssertNotPalindrome("abc"); | |
AssertPalindrome("aba"); | |
AssertPalindrome("technicallyllacinhcet"); | |
} | |
[Test]//, Ignore("Advanced")] | |
public void AdvancedPalindromeTests() | |
{ | |
AssertPalindrome("No X in Nixon"); | |
} | |
private void AssertPalindrome(string value) | |
{ | |
Assert.IsTrue( | |
palindromeChecker.IsPalindrome(value), | |
string.Format("Expected \"{0}\" to be a palindrome", value)); | |
} | |
private void AssertNotPalindrome(string value) | |
{ | |
Assert.IsFalse( | |
palindromeChecker.IsPalindrome(value), | |
string.Format("Expected \"{0}\" not to be a palindrome", value)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment