using System.Collections.Generic; using UnitTestSharp; namespace Vellum.UnitTests { public class FamilyChoiceTests : TestFixture { // Each name extends the names listed after it, and nothing else. private static readonly Dictionary Extending = new Dictionary { { "Animal", new string[0] }, { "Predator", new[] { "Animal" } }, { "Cat", new[] { "Predator", "Animal" } }, { "Pet", new string[0] }, }; private static bool Extends(string derived, string baseName) { return System.Array.IndexOf(Extending[derived], baseName) >= 0; } public class MostDerivedTests : TestFixture { public void NoCandidates_ReturnsNone() { CheckEqual(0, FamilyChoice.MostDerived(new string[0], Extends).Count); } public void OneCandidate_IsTheChoice() { CheckEqual(new[] { "Animal" }, FamilyChoice.MostDerived(new[] { "Animal" }, Extends)); } public void CandidateExtendingTheOthers_IsTheOnlyChoice() { CheckEqual(new[] { "Cat" }, FamilyChoice.MostDerived(new[] { "Animal", "Cat", "Predator" }, Extends)); } public void UnrelatedCandidates_AreAllReturnedInTheirOrder() { CheckEqual(new[] { "Pet", "Predator" }, FamilyChoice.MostDerived(new[] { "Pet", "Animal", "Predator" }, Extends)); } public void CandidateEqualToAnotherInValue_IsNotExtendedByIt() { CheckEqual(new[] { "Pet", "Pet" }, FamilyChoice.MostDerived(new[] { "Pet", "Pet" }, Extends)); } } } }