using System; using Tessera.Text; using UnitTestSharp; namespace Tessera.UnitTests.Text { public class NounTests : TestFixture { public class CtorTests : TestFixture { public void KeepsEveryTrait() { var noun = new Noun("sword", gender: 2, isPlural: true, isName: true, sound: InitialSound.Vowel); CheckEqual("sword", noun.Text); CheckEqual(2, noun.Gender); CheckTrue(noun.IsPlural); CheckTrue(noun.IsName); CheckEqual(InitialSound.Vowel, noun.Sound); } public void TheDefaults_AreASingularCommonNounOfTheFirstGender() { var noun = new Noun("sword"); CheckEqual(0, noun.Gender); CheckFalse(noun.IsPlural); CheckFalse(noun.IsName); CheckEqual(InitialSound.Auto, noun.Sound); } public void AGenderAtTheTop_IsKept() { CheckEqual(Noun.MaxGenderCount - 1, new Noun("x", gender: Noun.MaxGenderCount - 1).Gender); } public void ANullText_Throws() { CheckThrow(typeof(ArgumentNullException)); new Noun(null); } public void AnEmptyText_Throws() { CheckThrow(typeof(ArgumentException)); new Noun(""); } public void ANegativeGender_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x", gender: -1); } public void AGenderPastTheMost_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x", gender: Noun.MaxGenderCount); } public void ANonExistentSound_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x", sound: (InitialSound)3); } public void ANegativeSound_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x", sound: (InitialSound)(-1)); } public void FormsOfTheWrongLength_Throw() { CheckThrow(typeof(ArgumentException)); new Noun("x", forms: new string[GrammarRules.NounRoleCount - 1]); } public void AnEmptyForm_Throws() { CheckThrow(typeof(ArgumentException)); new Noun("x", forms: new[] { null, "", null, null }); } public void TheFormsArray_IsCopied() { string[] forms = { "a", "b", "c", "d" }; var noun = new Noun("x", forms: forms); forms[1] = "changed"; CheckEqual("b", noun.FormIn(GrammarRole.Object)); } } public class FormInTests : TestFixture { public void WithNoForms_EveryRoleIsTheText() { var noun = new Noun("sword"); CheckEqual("sword", noun.FormIn(GrammarRole.Subject)); CheckEqual("sword", noun.FormIn(GrammarRole.Object)); CheckEqual("sword", noun.FormIn(GrammarRole.Dative)); CheckEqual("sword", noun.FormIn(GrammarRole.Genitive)); } public void AGivenForm_IsUsedForItsRole() { var noun = new Noun("Kinder", forms: new[] { "KS", "KO", "KD", "KG" }); CheckEqual("KS", noun.FormIn(GrammarRole.Subject)); CheckEqual("KO", noun.FormIn(GrammarRole.Object)); CheckEqual("KD", noun.FormIn(GrammarRole.Dative)); CheckEqual("KG", noun.FormIn(GrammarRole.Genitive)); } public void ANullForm_FallsBackToTheText() { var noun = new Noun("Kinder", forms: new[] { null, null, "Kindern", null }); CheckEqual("Kinder", noun.FormIn(GrammarRole.Subject)); CheckEqual("Kindern", noun.FormIn(GrammarRole.Dative)); } public void ARoleANounDoesntTake_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x").FormIn(GrammarRole.Possessive); } public void ANegativeRole_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new Noun("x").FormIn((GrammarRole)(-1)); } public void ADefaultNoun_Throws() { CheckThrow(typeof(InvalidOperationException)); default(Noun).FormIn(GrammarRole.Subject); } } } }