public void HomographValidationWorks() { CheckDisposed(); LexEntry lme = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme); string sLexForm = "unitTestLexemeForm"; lme.LexemeFormOA = new MoStemAllomorph(); lme.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; // Make sure it has 2 homographs. LexEntry lme2 = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme2); lme2.LexemeFormOA = new MoStemAllomorph(); lme2.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; LexEntry lme3 = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme3); lme3.LexemeFormOA = new MoStemAllomorph(); lme3.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; string homographForm = lme.HomographForm; Assert.AreEqual(sLexForm, homographForm, "lexeme form and homograph form are not the same."); // This version of the CollectHomographs will not include the lme entry. List<ILexEntry> rgHomographs = lme.CollectHomographs(); Assert.AreEqual(rgHomographs.Count, 2, "Wrong homograph count."); // Reset all the homograph numbers to zero. foreach (ILexEntry le in rgHomographs) { le.HomographNumber = 0; } // Restore valid homograph numbers by calling ValidateHomographNumbers. bool fOk = LexEntry.ValidateExistingHomographs(rgHomographs); Assert.IsFalse(fOk, "Validation had to renumber homographs"); int n = 1; foreach (ILexEntry le in rgHomographs) { Assert.AreEqual(n++, le.HomographNumber, "Wrong homograph number found."); } // If we get here without asserting, the renumbering worked okay. fOk = LexEntry.ValidateExistingHomographs(rgHomographs); Assert.IsTrue(fOk, "Validation should not have to renumber this time."); // Reset all the homograph numbers by multiplying each by 2. foreach (ILexEntry le in rgHomographs) { le.HomographNumber *= 2; } // Restore valid homograph numbers by calling ValidateHomographNumbers. fOk = LexEntry.ValidateExistingHomographs(rgHomographs); Assert.IsFalse(fOk, "Validation had to renumber homographs"); n = 1; foreach (ILexEntry le in rgHomographs) { Assert.AreEqual(n++, le.HomographNumber, "Wrong homograph number found."); } }
public void HomographCollectionWorks() { CheckDisposed(); LexEntry lme = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme); string sLexForm = "unitTestLexemeForm"; lme.LexemeFormOA = new MoStemAllomorph(); lme.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; // Make sure it has 2 other homographs. LexEntry lme2 = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme2); lme2.LexemeFormOA = new MoStemAllomorph(); lme2.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; LexEntry lme3 = new LexEntry(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(lme3); lme3.LexemeFormOA = new MoStemAllomorph(); lme3.LexemeFormOA.Form.VernacularDefaultWritingSystem = sLexForm; string homographForm = lme.HomographForm; Assert.AreEqual(sLexForm, homographForm, "Lexeme form and homograph form are not the same."); // These two tests check lexeme forms of the two/three entries. // This version of the CollectHomographs method will not include the lme entry. List<ILexEntry> rgHomographs = lme.CollectHomographs(homographForm, lme.Hvo); Assert.AreEqual(rgHomographs.Count, 2, "Wrong homograph count."); // This version of the CollectHomographs method will not include the lme entry. rgHomographs = lme.CollectHomographs(); Assert.AreEqual(rgHomographs.Count, 2, "Wrong homograph count."); // This version of the CollectHomographs method will include the lme entry. rgHomographs = lme.CollectHomographs(homographForm, 0); Assert.AreEqual(rgHomographs.Count, 3, "Wrong homograph count."); // Now set the citation form to something different than sLexForm. string sCitationForm = "unitTestCitationForm"; lme.CitationForm.VernacularDefaultWritingSystem = sCitationForm; homographForm = lme.HomographForm; Assert.AreEqual(sCitationForm, homographForm, "Citation form and homograph form are not the same."); // This version of the CollectHomographs method will include the lme entry. rgHomographs = lme.CollectHomographs(homographForm, 0); Assert.AreEqual(rgHomographs.Count, 1, "Wrong homograph count."); // This version of the CollectHomographs method will include the lme entry. rgHomographs = lme2.CollectHomographs(sLexForm, 0); Assert.AreEqual(rgHomographs.Count, 2, "Wrong homograph count."); }