Skip to content

Instantly share code, notes, and snippets.

@andersivner
Created November 6, 2012 13:15
Show Gist options
  • Save andersivner/4024659 to your computer and use it in GitHub Desktop.
Save andersivner/4024659 to your computer and use it in GitHub Desktop.
Test cases for the Soundex TDD exercise. To be added (uncommented) one-by-one from the top. This is the c# version, adapted from https://github.com/jlangr/soundex.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Soundex.Tests
{
[TestClass]
public class SoundexTests
{
[TestMethod]
public void RetainsSoleLetterOfOneLetterWord()
{
Assert.AreEqual("A000", Soundex.Encode("A"));
}
[TestMethod]
public void PadsWithZeroesToEnsureThreeDigits()
{
Assert.AreEqual("I000", Soundex.Encode("I"));
}
[TestMethod]
public void ReplacesConsonantBWithDigit1()
{
Assert.AreEqual("A100", Soundex.Encode("Ab"));
}
[TestMethod]
public void ReplacesConsonantCWithDigit2()
{
Assert.AreEqual("A200", Soundex.Encode("Ac"));
}
[TestMethod]
public void ReplacesTwoConsonantsWithAppropriateDigits()
{
Assert.AreEqual("A340", Soundex.Encode("Adl"));
}
[TestMethod]
public void ReplacesThreeConsonantsWithAppropriateDigits()
{
Assert.AreEqual("A256", Soundex.Encode("Ajmr"));
}
[TestMethod]
public void LimitsLengthToFourCharacters()
{
Assert.AreEqual("D123", Soundex.Encode("Dbcdlmr"));
}
[TestMethod]
public void IgnoresVowelLikeLetters()
{
Assert.AreEqual("C123", Soundex.Encode("CAaEeIiOoUuHhYybcd"));
}
[TestMethod]
public void CombinesDuplicateEncodings()
{
Assert.AreEqual("G123", Soundex.Encode("Gbfcgdt"));
}
[TestMethod]
public void UppercasesFirst()
{
Assert.AreEqual("A123", Soundex.Encode("abcd"));
}
[TestMethod]
public void ReplacesConsonantsWithAppropriateDigitsIgnoresCase()
{
Assert.AreEqual("B234", Soundex.Encode("BCDL"));
}
[TestMethod]
public void DoesNotCombineDuplicateEncodingsSeparatedByVowels()
{
Assert.AreEqual("J110", Soundex.Encode("Jbob"));
}
[TestMethod]
public void CombinesDuplicateCodesWhen2ndLetterDuplicates1st()
{
Assert.AreEqual("B230", Soundex.Encode("Bbcd"));
}
[TestMethod]
public void CombinesDuplicateEncodingsSeparatedByHOrW()
{
Assert.AreEqual("J100", Soundex.Encode("Jbwb"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment