- Improve performance
- Refactor tests
- Refactor method signature
- Add documentation
using System.Linq; public static class Palindrome { public static bool IsPalindrome(this string word) { // Normalize the input var upper = word.ToUpperInvariant(); // For every chatacter in the first half.. for (var i = 0; i < upper.Length / 2; ++i) // if the char doesn't match the one in the second half.. if (upper[i] != upper[upper.Length - i - 1]) // the word is not a palindrome return false; // The word is not a palindrome return true; } }
- using System.Linq;
class Palindrome- public static class Palindrome
- {
public static bool Check(string word) {- public static bool IsPalindrome(this string word)
- {
- // Normalize the input
- var upper = word.ToUpperInvariant();
return upper.SequenceEqual(upper.Reverse());- // For every chatacter in the first half..
- for (var i = 0; i < upper.Length / 2; ++i)
- // if the char doesn't match the one in the second half..
- if (upper[i] != upper[upper.Length - i - 1])
- // the word is not a palindrome
- return false;
- // The word is not a palindrome
- return true;
- }
- }
namespace Solution { using NUnit.Framework; using System; // TODO: Replace examples and use TDD development by writing your own tests [TestFixture] public class SolutionTest { [TestCase(true, "MOM")] [TestCase(true, "kAyaK")] [TestCase(true, "123454321")] [TestCase(true, "n1oo1n")] [TestCase(true, "X")] [TestCase(true, "")] [TestCase(false, "rotlor")] [TestCase(false, "506050")] [TestCase(false, "idEddEddi")] public void AsExtension(bool expected, string toCheck) => Assert.AreEqual(expected, toCheck.IsPalindrome()); [TestCase(true, "MOM")] [TestCase(true, "kAyaK")] [TestCase(true, "123454321")] [TestCase(true, "n1oo1n")] [TestCase(true, "X")] [TestCase(true, "")] [TestCase(false, "rotlor")] [TestCase(false, "506050")] [TestCase(false, "idEddEddi")] public void AsMethod(bool expected, string toCheck) => Assert.AreEqual(expected, Palindrome.IsPalindrome(toCheck)); } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- // TODO: Replace examples and use TDD development by writing your own tests
- [TestFixture]
- public class SolutionTest
- {
[Test]public void MyTest(){Assert.AreEqual(true, Palindrome.Check("MOM"));Assert.AreEqual(true, Palindrome.Check("kAyaK"));Assert.AreEqual(true, Palindrome.Check("123454321"));Assert.AreEqual(true, Palindrome.Check("n1oo1n"));Assert.AreEqual(true, Palindrome.Check("X"));Assert.AreEqual(true, Palindrome.Check(""));Assert.AreEqual(false, Palindrome.Check("rotlor"));Assert.AreEqual(false, Palindrome.Check("506050"));Assert.AreEqual(false, Palindrome.Check("idEddEddi"));}- [TestCase(true, "MOM")]
- [TestCase(true, "kAyaK")]
- [TestCase(true, "123454321")]
- [TestCase(true, "n1oo1n")]
- [TestCase(true, "X")]
- [TestCase(true, "")]
- [TestCase(false, "rotlor")]
- [TestCase(false, "506050")]
- [TestCase(false, "idEddEddi")]
- public void AsExtension(bool expected, string toCheck)
- => Assert.AreEqual(expected, toCheck.IsPalindrome());
- [TestCase(true, "MOM")]
- [TestCase(true, "kAyaK")]
- [TestCase(true, "123454321")]
- [TestCase(true, "n1oo1n")]
- [TestCase(true, "X")]
- [TestCase(true, "")]
- [TestCase(false, "rotlor")]
- [TestCase(false, "506050")]
- [TestCase(false, "idEddEddi")]
- public void AsMethod(bool expected, string toCheck)
- => Assert.AreEqual(expected, Palindrome.IsPalindrome(toCheck));
- }
- }
Fundamentals
Numbers
Data Types
Integers
- Refactor to expression and extension method
- Add documentation
- Refactor tests
public static class Kata { /// <summary> /// Validates if the given <paramref name="input"/> is an odd number /// </summary> /// <param name="input">Number to validate</param> /// <returns>True if the <paramref name="input"/> is an odd number</returns> public static bool IsOdd(this int input) => (input & 1) == 1; }
- public static class Kata
- {
public static bool IsOdd(int input){return (input & 1) == 1;}- /// <summary>
- /// Validates if the given <paramref name="input"/> is an odd number
- /// </summary>
- /// <param name="input">Number to validate</param>
- /// <returns>True if the <paramref name="input"/> is an odd number</returns>
- public static bool IsOdd(this int input)
- => (input & 1) == 1;
- }
namespace Solution { using NUnit.Framework; using System; // TODO: Replace examples and use TDD by writing your own tests [TestFixture] public class SolutionTest { [TestCase(true, 1)] [TestCase(false, 2)] [TestCase(true, 13)] [TestCase(false, 18284)] [TestCase(true, -1)] public void AsMethod(bool expected, int val) => Assert.AreEqual(expected, Kata.IsOdd(val)); [TestCase(true, 1)] [TestCase(false, 2)] [TestCase(true, 13)] [TestCase(false, 18284)] [TestCase(true, -1)] public void AsExtension(bool expected, int val) => Assert.AreEqual(expected, val.IsOdd()); } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- // TODO: Replace examples and use TDD by writing your own tests
- [TestFixture]
- public class SolutionTest
- {
[Test]public void MyTest(){Assert.AreEqual(true, Kata.IsOdd(1));Assert.AreEqual(false, Kata.IsOdd(2));Assert.AreEqual(true, Kata.IsOdd(13));Assert.AreEqual(false, Kata.IsOdd(18284));Assert.AreEqual(true, Kata.IsOdd(-1));}- [TestCase(true, 1)]
- [TestCase(false, 2)]
- [TestCase(true, 13)]
- [TestCase(false, 18284)]
- [TestCase(true, -1)]
- public void AsMethod(bool expected, int val)
- => Assert.AreEqual(expected, Kata.IsOdd(val));
- [TestCase(true, 1)]
- [TestCase(false, 2)]
- [TestCase(true, 13)]
- [TestCase(false, 18284)]
- [TestCase(true, -1)]
- public void AsExtension(bool expected, int val)
- => Assert.AreEqual(expected, val.IsOdd());
- }
- }