public void ReadUser(string fileName) { XmlSerializer deserializer = new XmlSerializer(typeof(User)); using (TextReader tr = new StreamReader(fileName)) { User temp = (User)deserializer.Deserialize(tr); Name = temp.Name; TestsPassed = temp.TestsPassed; Vocabulary = temp.Vocabulary; foreach (Word w in Vocabulary.WordList) { if (w.TestsPassed[0] == TestType.none) w.TestsPassed.RemoveAt(0); } } }
public abstract void Test(Vocabulary testingVoc);
public User() { TestsPassed = new List<TestResults>(); Vocabulary = new Vocabulary(); }
public AbstractTest(List<Word> v) { TestVocabulary = new Vocabulary(v); }
public override void Test(Vocabulary testingVoc) { if (TestVocabulary.Count != testingVoc.Count) { return; } for (int i = 0; i < TestVocabulary.Count; i++) { if (!TestVocabulary[i].Wd.Equals(testingVoc[i].Wd, StringComparison.OrdinalIgnoreCase)) { return; } } TestResults res = new TestResults(TestVocabulary.Count,0,new DateTime(),TestType.WordTranslation); CorrectionOfAnswers = new List<bool>(); for (int i = 0; i < TestVocabulary.Count; i++) { if (TestVocabulary[i].Tr.Equals(testingVoc[i].Tr, StringComparison.OrdinalIgnoreCase)) { res.CorrectRes++; CorrectionOfAnswers.Add(true); } else { CorrectionOfAnswers.Add(false); } } res.TimeOfPassage = DateTime.Now; Results = res; for (int i = 0; i < TestVocabulary.WordList.Count; i++) { if(CorrectionOfAnswers[i] == true) TestVocabulary.WordList[i].AddTestPassed(TestType.WordTranslation); } }
public TestWT(List<Word> v) : base(v) { TestVocabulary = new Vocabulary(v); }
static void Main(string[] args) { #region User test User user = new User(); user.ReadUser("User.xml"); Console.WriteLine(user.Name); foreach (TestResults tr in user.TestsPassed) { Console.WriteLine(tr.ToString()); } //Console.WriteLine(); //Console.WriteLine(user.Vocabulary.ToString()); #endregion //user.Vocabulary = new Vocabulary( // new Word("water"), // new Word("treat"), // new Word("mouse"), // new Word("song"), // new Word("mirror"), // new Word("start")); //// Translate API test //foreach (Word w in user.Vocabulary.WordList) //{ // w.Translate(); //} Console.WriteLine("--------------------------------------"); Console.WriteLine(user.Vocabulary.ToString()); #region Vocebulary aditional functions test //voc += w; //Console.WriteLine("--------------------------------------"); //Console.WriteLine(voc.ToString()); //Console.WriteLine("--------------------------------------"); //voc -= new Word("apple", "яблоко"); //Console.WriteLine(voc.ToString()); //Console.WriteLine("--------------------------------------"); //voc.WriteWords("Words.xml"); //voc = new Vocabulary(new Word("phone", "телефон")); //Console.WriteLine(voc.ToString()); //Console.WriteLine("--------------------------------------"); //voc.ReadWords("Words.xml"); //Console.WriteLine(voc.ToString()); //Console.WriteLine("--------------------------------------"); //voc.VipeTranslations(); //Console.WriteLine(voc.ToString()); //Console.WriteLine("--------------------------------------"); //voc.TranslateAll(); //Console.WriteLine(voc.ToString()); //Text t = new Text(); //t.TextString = Console.ReadLine(); //foreach (string w in t.Words) //{ // Console.WriteLine(w.ToString()); //} #endregion #region Tests test // Word-Translation Test===================================== TestWT twt = new TestWT(user.Vocabulary.WordList); Vocabulary testingVocebulary = new Vocabulary(); foreach (Word w in user.Vocabulary.WordList) { testingVocebulary.Add(new Word() { Wd = w.Wd, Tr = w.Tr }); } testingVocebulary.VipeTranslations(); for (int i = 0; i < testingVocebulary.Count; i++) { Console.WriteLine("Word: " + testingVocebulary[i].Wd); testingVocebulary[i].Tr = Console.ReadLine(); } twt.Test(testingVocebulary); foreach (Word w in testingVocebulary.WordList) { Console.WriteLine(w.ToString()); } Console.WriteLine(); if (twt.Results != null) { Console.WriteLine(twt.Results.ToString()); Console.WriteLine(); foreach (bool b in twt.CorrectionOfAnswers) { if (b == true) Console.WriteLine("Correct"); if (b == false) Console.WriteLine("Incorrect"); } } Console.WriteLine("-------------------------------------------"); //// Translation-Word Test //TestTW ttw = new TestTW(user.Vocabulary.WordList); //testingVocebulary = new Vocabulary(); //foreach (Word w in user.Vocabulary.WordList) //{ // testingVocebulary.Add(new Word() { Wd = w.Wd, Tr = w.Tr }); //} //testingVocebulary.VipeWords(); //for (int i = 0; i < testingVocebulary.Count; i++) //{ // Console.WriteLine("Translation: " + testingVocebulary[i].Tr); // testingVocebulary[i].Wd = Console.ReadLine(); //} //ttw.Test(testingVocebulary); //foreach (Word w in testingVocebulary.WordList) //{ // Console.WriteLine(w.ToString()); //} //Console.WriteLine(); //if (ttw.Results != null) //{ // Console.WriteLine(ttw.Results.ToString()); // Console.WriteLine(); // foreach (bool b in ttw.CorrectionOfAnswers) // { // if (b == true) // Console.WriteLine("Correct"); // if (b == false) // Console.WriteLine("Incorrect"); // } //} #endregion #region TestType Serialization test (Need to comment everything) //Vocabulary voc = new Vocabulary(); //voc.ReadWords("TestWords.xml"); //Console.WriteLine(voc.ToString()); //voc.DeleteByPassage(TestType.WordTranslation); //Console.WriteLine(voc.ToString()); //voc.WriteWords("TestWords2.xml"); #endregion //user.TestsPassed.Add(twt.Results); //user.TestsPassed.Add(ttw.Results); user.WriteUser("User.xml"); }