public void TestSucceeded1In1_NotSwitched()
        {
            int amount = 1;
            int counter = 0;
            isSwitched = false;
            // set counter to 0 for all cards
            foreach (var card in dictionary)
                card.Counter1[type] = counter;

            int countersBefore = GetCountersSum();

            Training training = new Training(dictionary, isSwitched, amount, counter + 1, type, learnedBefore);

            // provide correct answer for one card
            var timeBefore = DateTime.Now;
            var cardToLearn = training.NextCard();
            var timeAfter = DateTime.Now;
            CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained);

            training.CheckAnswer(cardToLearn.Word2, true);
            CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained); // check that doesn't chaned after answer

            // check that card counter increased and number of learned cards
            int countersAfter = GetCountersSum();
            Assert.AreEqual(counter + 1, cardToLearn.Counter1[type], "Validating card counter");
            Assert.AreEqual(amount, training.CorrectAnswers, "Validating number of correct answers");
            Assert.AreEqual(amount, training.TotalCards, "Validating number of cards in training");
            Assert.AreEqual(countersBefore + training.CorrectAnswers, countersAfter, "Validating that only counter of one type for one word increased");
        }
        public void TestChoose()
        {
            maxCounter = 1;
            type = TrainingType.Choose;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter, type, learnedBefore);
            CheckTrainingList(training);

            // go trough all cards in training and choose cards
            var currentCard = training.NextCard();
            while (currentCard != null)
            {
                var chooseList = training.Choose();
                CheckChooseList(chooseList, currentCard);
                currentCard = training.NextCard();
            }
        }
        public void TestWrittingWHint()
        {
            maxCards = 1;
            type = TrainingType.WrittingWHint;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter, type, learnedBefore);
            var currentCard = training.NextCard();
            currentCard.Word2 = "Test";
            string actual = training.GetHint();
            string expected = "First letter is 'T', Word length is 4";

            Assert.AreEqual(expected, actual, "Validating hint");
        }
        public void TestChooseCardsLessThanType()
        {
            maxCounter = 1;
            type = TrainingType.Choose;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter, type, learnedBefore);
            CheckTrainingList(training);

            // set word type as currentCard            
            foreach (var card in dictionary)
                card.Type = WordType.Noun;
            var currentCard = training.NextCard();
            currentCard.Type = WordType.Verb;
            for (int i = 0; i < dictionary.Count - 1; i++)
                dictionary[i].Type = currentCard.Type;
            var chooseList = training.Choose(cardsToChoose);
            CheckChooseList(chooseList, currentCard);
        }
        public void TestChooseCards0Type()
        {
            maxCounter = 1;
            type = TrainingType.Choose;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter, type, learnedBefore);
            CheckTrainingList(training);

            // all other cards have different type as currentCard
            foreach (var card in dictionary)
                card.Type = WordType.Noun;
            var currentCard = training.NextCard();
            currentCard.Type = WordType.Verb;
            var chooseList = training.Choose(cardsToChoose);
            CheckChooseList(chooseList, currentCard);
        }
        public void TestChooseCardsMoreThanAvailableType()
        {
            maxCounter = 1;
            type = TrainingType.Choose;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter, type, learnedBefore);
            CheckTrainingList(training);

            // set word type as currentCard
            var currentCard = training.NextCard();
            foreach (var card in dictionary)
                card.Type = currentCard.Type;
            var chooseList = training.Choose(cardsToChoose);
            CheckChooseList(chooseList, currentCard);
        }
        public void TestFailedDecreaseCounterTo0()
        {
            maxCards = 1;
            maxCounter = 0;
            // set counter to 0 for all cards
            foreach (var card in dictionary)
                card.Counter1[type] = maxCounter;

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter + 1, type, learnedBefore);

            // increase counter from 0 to 1 for one card
            var cardToLearn = training.NextCard();
            training.CheckAnswer(cardToLearn.Word1, true);

            // check that card counter increased and number of learned cards
            Assert.AreEqual(maxCounter, cardToLearn.Counter1[type], "Validating card counter");
            Assert.AreEqual(0, training.CorrectAnswers, "Validating number of correct answers");
            Assert.AreEqual(maxCards, training.TotalCards, "Validating number of cards in training");
        }
        public void TestFailedDontDecreaseCounter()
        {
            maxCards = 1;
            maxCounter = 0;

            // set counter to 0 for all cards
            foreach (var card in dictionary)
                card.Counter1[type] = maxCounter;
            int countersBefore = GetCountersSum();

            Training training = new Training(dictionary, isSwitched, maxCards, maxCounter + 1, type, learnedBefore);

            // provide incorrect answer
            var timeBefore = DateTime.Now;
            var cardToLearn = training.NextCard();
            var timeAfter = DateTime.Now;
            CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained);
            training.CheckAnswer(cardToLearn.Word1, false);
            CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained); // check that doesn't chaned after answer

            // check that card counter increased and number of learned cards
            int countersAfter = GetCountersSum();
            Assert.AreEqual(maxCounter, cardToLearn.Counter1[type], "Validating card counter");
            Assert.AreEqual(0, training.CorrectAnswers, "Validating number of correct answers");
            Assert.AreEqual(maxCards, training.TotalCards, "Validating number of cards in training");
            Assert.AreEqual(countersBefore, countersAfter, "Validating that none counters increased");
        }
        public void TestSucceededSeveralInMany_Switched()
        {
            int amount = random.Next(maxCards / 2);
            isSwitched = true;
            // set counter to 0 for all cards
            foreach (var card in dictionary)
                card.Counter2[type] = 0;
            int countersBefore = GetCountersSum();

            Training training = new Training(dictionary, isSwitched, maxCards, 1, type, learnedBefore);
            CheckTrainingList(training);

            // provide correct answer for one card
            for (int i = 0; i < amount; i++)
            {
                var timeBefore = DateTime.Now;
                var cardToLearn = training.NextCard();
                var timeAfter = DateTime.Now;
                CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained);

                training.CheckAnswer(cardToLearn.Word2, true);
                CheckLastTrained(timeBefore, timeAfter, cardToLearn.LastTrained); // check that doesn't chaned after answer
            }

            // check number of correct answers and total cards in training
            int countersAfter = GetCountersSum();
            Assert.AreEqual(amount, training.CorrectAnswers, "Validating number of correct answers");
            Assert.AreEqual(maxCards, training.TotalCards, "Validating number of cards in training");
            Assert.AreEqual(countersBefore + training.CorrectAnswers, countersAfter, "Validating that corrent number of counters increased");
            training.Close();

            // check that training set decreased by learned cards
            training = new Training(dictionary, isSwitched, maxCards, 1, type, learnedBefore);
            int expected = maxCards - amount;
            Assert.AreEqual(expected, training.TotalCards, "Validating number of words to learn");
            CheckTrainingList(training);
        }
        // start training
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            WordCardElement.Lang1 = languages[langFrom];
            WordCardElement.Lang2 = languages[langTo];
            training = new Training(dictionary, isSwitched, NumOfWords, Counter, SelectedTrainingType, LearnedBefore);
            WordCardElement.SelectedCard = training.NextCard();
            if (WordCardElement.SelectedCard != null)
            {
                trainingTest.Visibility = Visibility.Visible;
                trainingSetting.IsEnabled = false;
                btnCheck.IsEnabled = true;
                Result = null;
                Answer = "";
                Hint = "";
                ChooseList = null;
                UpdateTrainingCard();

                // visual updates for training view
                WordCardElement.IsEnabled = false;
                WordCardElement.Counter1.Visibility = Visibility.Collapsed;
                WordCardElement.Counter2.Visibility = Visibility.Collapsed;
                WordCardElement.txtWord1.FontWeight = FontWeights.Bold;
                WordCardElement.txtWord2.FontWeight = FontWeights.Bold;
                WordCardElement.txtWord1.Background = Brushes.GreenYellow; // or (Brush)bc.ConvertFrom("#FFXXXXXX");
                WordCardElement.txtWord2.Background = Brushes.Gray;
                txtAnswer.Focus();
            }
        }