示例#1
0
 public void TestWordCardInit()
 {
     card = new WordCard(word1, word2, type);
     Assert.AreEqual(word1, card.Word1, "Validating that word1 is initialized correctly");
     Assert.AreEqual(word2, card.Word2, "Validating that word2 is initialized correctly");
     Assert.AreEqual(type, card.Type, "Validating that word2 is initialized correctly");
     Assert.IsFalse(card.Switched, "Validating that card i not switched");
 }
示例#2
0
 /// <summary>
 /// Returns randomly generated word card
 /// Counters are 0
 /// </summary>
 /// <returns>Generated WordCard</returns>
 public WordCard GetCard()
 {
     WordCard card = new WordCard(RandomString(lang1, random.Next(2, 10)), RandomString(lang2, random.Next(2, 10)), RandomType());
     card.Comment1 = RandomString(lang1, random.Next(0, 10));
     card.Comment2 = RandomString(lang2, random.Next(0, 10));
     card.CommentCommon = RandomString(lang1, random.Next(0, 10));
     card.LastTrained = DateTime.Now.AddDays(-10 * random.NextDouble());
     return card;
 }
示例#3
0
        /// <summary>
        /// Read Dictionary from xml file
        /// Returns Dictionary
        /// </summary>
        /// <returns>WordsDictionary</returns>
        public override WordsDictionary Read()
        {
            XDocument xd = XDocument.Load(pathToXml);

            WordsDictionary dictionary = new WordsDictionary(xd.Root.Attribute(strLang1).Value, xd.Root.Attribute(strLang2).Value);

            foreach (XElement cardXml in xd.Root.Elements(strCard))
            {
                XElement word1Xml = cardXml.Element(strLang1);
                XElement word2Xml = cardXml.Element(strLang2);

                // create word card class
                string word1 = word1Xml.Element(strWordText).Value;
                string word2 = word2Xml.Element(strWordText).Value;
                string type = cardXml.Attribute(strWordType).Value;
                WordCard card = new WordCard(word1, word2, (WordType)Enum.Parse(typeof(WordType), type));

                // set counter and comment for word1
                foreach (XElement counter in word1Xml.Element(strCounters).Elements(strCounter))
                {
                    TrainingType trainingType = (TrainingType)Enum.Parse(typeof(TrainingType), counter.Attribute(strCounterType).Value, true);
                    card.Counter1[trainingType] = int.Parse(counter.Attribute(strCounterValue).Value);
                }
                XElement commentXml = word1Xml.Element(strComment);
                if (commentXml != null)
                    card.Comment1 = commentXml.Value;

                // set counter and comment for word2
                foreach (XElement counter in word2Xml.Element(strCounters).Elements(strCounter))
                {
                    TrainingType trainingType = (TrainingType)Enum.Parse(typeof(TrainingType), counter.Attribute(strCounterType).Value, true);
                    card.Counter2[trainingType] = int.Parse(counter.Attribute(strCounterValue).Value);
                }
                commentXml = word2Xml.Element(strComment);
                if (commentXml != null)
                    card.Comment2 = commentXml.Value;

                // set common comment
                commentXml = cardXml.Element(strComment);
                if (commentXml != null)
                    card.CommentCommon = commentXml.Value;

                XElement lastTrained = cardXml.Element(strLastTrained);
                if (lastTrained != null)
                {
                    DateTime time = DateTime.Now;
                    if (DateTime.TryParse(lastTrained.Value, out time))
                        card.LastTrained = time;
                }

                dictionary.Add(card);
            }

            return dictionary;
        }
        public void TestAddWordCard()
        {
            WordCard card = generator.GetCard();
            WordCard cardExpected = new WordCard(card.Word1, card.Word2, card.Type);
            dictionary.Add(card);
            WordCard cardActual = dictionary[0];
            Assert.AreEqual(cardExpected, cardActual, "Validating that card is added correctly");

            int sizeExpected = 1;
            int sizeActual = dictionary.Count;
            Assert.AreEqual(sizeExpected, sizeActual, "Validating dictionary size");
        }
示例#5
0
 private void CheckChooseList(IList<WordCard> chooseList, WordCard currentCard)
 {
     Assert.IsTrue(chooseList.Contains(currentCard), "Validating that chooseList contains currentCard");
     foreach (var card in chooseList)
     {
         Assert.AreEqual(card.Type, currentCard.Type, "Validating that card in chooseList has the same type as currentCard");
     }
 }
示例#6
0
 public void TestCardsEqual2()
 {
     WordCard card2 = new WordCard(card.Word1, card.Word2, card.Type);
     Assert.IsTrue(card.Equals(card2), "Validating that cards are equal");
 }
示例#7
0
 public void SetUp()
 {
     card = new CardsGenerator().GetCardExtra(5);
     trainingType = trainingTypeList[random.Next(trainingTypeList.Count)];
 }
示例#8
0
 public void TestSwitchBack()
 {
     WordCard card2 = new WordCard(card.Word1, card.Word2, card.Type);
     card2.Comment1 = card.Comment1;
     card2.Comment2 = card.Comment2;
     card2.CommentCommon = card.CommentCommon;
     card2.Counter1 = card.Counter1;
     card2.Counter2 = card.Counter2;
     card.Switched = true;
     card.Switched = false;
     Assert.IsFalse(card.Switched, "Validating that card is switched (Property)");
     Assert.AreEqual(card, card2, "Validating that card is switched (Cards)");
     Assert.AreEqual(card.CommentCommon, card2.CommentCommon, "Validating that card is switched (Comment)");
     Assert.AreEqual(card.Comment1, card2.Comment1, "Validating that card is switched (Comment1)");
     Assert.AreEqual(card.Comment2, card2.Comment2, "Validating that card is switched (Comment2)");
     Assert.AreEqual(card.Counter1, card2.Counter1, "Validating that card is switched (Counter1)");
     Assert.AreEqual(card.Counter2, card2.Counter2, "Validating that card is switched (Counter2)");
 }
示例#9
0
 public void TestCardsnotEqual3()
 {
     card.Type = WordType.Noun;
     WordCard card2 = new WordCard(card.Word1, card.Word2, WordType.Pronoun);
     Assert.IsFalse(card.Equals(card2), "Validating that cards are not equal (diff in Type)");
 }
示例#10
0
 public void TestCardsnotEqual2()
 {
     WordCard card2 = new WordCard(card.Word1, "Tsau", card.Type);
     Assert.IsFalse(card.Equals(card2), "Validating that cards are not equal (diff in Word2)");
 }
示例#11
0
 // prepation to add new card
 private void New_Click(object sender, RoutedEventArgs e)
 {
     SelectedCard = new WordCard("new", "new", WordType.Noun);
     isNew = true;
     UpdateView();
 }