/// <summary>
        /// Generates the test data.
        /// </summary>
        /// <param name="learningModules">The learning modules.</param>
        /// <param name="sessions">The sessions.</param>
        /// <param name="cardsPerSession">The cards per session.</param>
        /// <remarks>Documented by Dev03, 2008-11-18</remarks>
        internal void Generate(List<int> learningModules, int sessions, int cardsPerSession)
        {
            UserInputSubmitEventArgs e;

            TestStatusEventArgs args = new TestStatusEventArgs(sessions * cardsPerSession);
            ConnectionStringStruct css = m_learnLogic.CurrentLearningModule.ConnectionString;
            foreach (int id in learningModules)
            {
                m_connectionString.LmId = id;
                for (int i = 0; i < sessions; i++)
                {
                    css.LmId = id;
                    m_learnLogic.OpenLearningModule(new LearningModulesIndexEntry(css));
                    m_learnLogic.User.Dictionary.Settings.SelfAssessment = false;
                    for (int k = (i * cardsPerSession); k < (i * cardsPerSession) + cardsPerSession; k++)
                    {
                        m_learnLogic.OnLearningModuleOptionsChanged();
                        Card card = m_learnLogic.Dictionary.Cards.GetCardByID(m_learnLogic.CurrentCardID);

                        if (GetRandomBool())
                            e = new UserInputSubmitTextEventArgs(0, card.CurrentAnswer.Words.Count, card.CurrentAnswer.Words.Count, true, card.CurrentAnswer.Words.ToString());
                        else
                            e = new UserInputSubmitTextEventArgs(5, 0, 5, false, string.Empty);
                        m_learnLogic.OnUserInputSubmit(this, e);

                        if ((k % 10) == 0)
                        {
                            args.Progress = (k + 1) * (i + 1);
                            UpdateStatusMessage(args);
                        }
                    }
                    m_learnLogic.CloseLearningModule();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Grades the Text answer.
        /// </summary>
        /// <param name="args">The <see cref="MLifter.BusinessLayer.UserInputSubmitTextEventArgs"/> instance containing the event data.</param>
        /// <param name="result">The result (optional).</param>
        /// <returns>Promote or Demote.</returns>
        /// <remarks>Documented by Dev02, 2008-04-23</remarks>
        private bool GradeTextAnswer(UserInputSubmitTextEventArgs args, out AnswerResult result, out bool overrideSynonyms, out bool overrideTyping)
        {
            bool correct = args.correctsynonyms > 0;
            result = correct ? AnswerResult.Correct : AnswerResult.Wrong;

            overrideSynonyms = overrideTyping = false;

            //[ML-1331] Textbox counts synonyms somethimes wrong: following lines were wrong:
            //  else if (user.Dictionary.Settings.GradeSynonyms.FirstKnown.Value)  promotesynonyms = args.correctsynonyms >= 1;
            //  else if (user.Dictionary.Settings.GradeSynonyms.OneKnown.Value)   promotesynonyms = args.correctfirstsynonym;
            // ... were wrong

            // Grade Synonyms
            bool promotesynonyms = true;
            if (args.synonyms > 1 && args.correctsynonyms < args.synonyms)
            {
                if (user.Dictionary.Settings.GradeSynonyms.AllKnown.Value)
                    promotesynonyms = args.synonyms == args.correctsynonyms;
                else if (user.Dictionary.Settings.GradeSynonyms.HalfKnown.Value)
                    promotesynonyms = args.synonyms > 0 ? 2 * args.correctsynonyms >= args.synonyms : false;
                else if (user.Dictionary.Settings.GradeSynonyms.FirstKnown.Value)
                    promotesynonyms = args.correctfirstsynonym;
                else if (user.Dictionary.Settings.GradeSynonyms.OneKnown.Value)
                    promotesynonyms = args.correctsynonyms >= 1;
                else if (user.Dictionary.Settings.GradeSynonyms.Prompt.Value)
                {
                    UserGradingDialogEventArgs e = new UserGradingDialogEventArgs(user.Dictionary, currentCardID, UserGradingDialogEventArgs.GradingDialogKind.GradeSynonym);
                    OnUserDialog(e);
                    overrideSynonyms = promotesynonyms = e.promote;
                }
            }

            // Grade Typing
            bool promotetyping = true;
            if (args.typingerrors > 0 && !overrideSynonyms)
            {
                if (user.Dictionary.Settings.GradeTyping.AllCorrect.Value)
                    promotetyping = false;
                else if (user.Dictionary.Settings.GradeTyping.HalfCorrect.Value)
                    promotetyping = args.answer.Length > 0 ? 2 * args.typingerrors < args.answer.Length : false;
                else if (user.Dictionary.Settings.GradeTyping.NoneCorrect.Value)
                    promotetyping = true;
                else if (user.Dictionary.Settings.GradeTyping.Prompt.Value)
                {
                    UserGradingDialogEventArgs e = new UserGradingDialogEventArgs(user.Dictionary, currentCardID, UserGradingDialogEventArgs.GradingDialogKind.GradeTypo);
                    OnUserDialog(e);
                    overrideTyping = promotetyping = e.promote;
                }
            }

            //final decision about promoting
            bool promote = correct && promotesynonyms && promotetyping;
            if (overrideSynonyms)
                promote = promotesynonyms;
            if (overrideTyping)
                promote = promotetyping;

            if (correct && !promote)
                result = AnswerResult.Almost;

            return promote;
        }
Beispiel #3
0
        /// <summary>
        /// Submits the user input.
        /// </summary>
        /// <remarks>Documented by Dev02, 2008-04-23</remarks>
        void SubmitUserInput()
        {
            if (learnlogic != null)
            {
                UserInputSubmitTextEventArgs args = new UserInputSubmitTextEventArgs(
                    mLifterTextBox.Errors,
                    mLifterTextBox.CorrectSynonyms,
                    mLifterTextBox.Synonyms.Count,
                    mLifterTextBox.CorrectFirstSynonym,
                    mLifterTextBox.Text);

                UserInputSubmit(this, args);
            }
        }
Beispiel #4
0
        public void GetKnownTest()
        {
            if (TestInfrastructure.IsActive(TestContext))
            {
                ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext);
                LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate)delegate { return; });
                //learnLogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser,
                //    connectionString, (DataAccessErrorDelegate)delegate { return; });
                try
                {
                    learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString));
                }
                catch (IsOdxFormatException)
                {
                    if (TestInfrastructure.ConnectionType(TestContext) == "File")
                        return;
                    else
                        throw;
                }

                learnLogic.OnLearningModuleOptionsChanged();
                learnLogic.ResetLearningProgress();

                //Answer 5 cards correct
                for (int i = 0; i < 5; i++)
                {
                    Card currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID);

                    //Answer Card correct
                    UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, currentCard.CurrentAnswer.Words.Count,
                        currentCard.CurrentAnswer.Words.Count, true, currentCard.CurrentAnswer.Words.ToString());

                    learnLogic.OnUserInputSubmit(this, e);
                    learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs());
                }

                int known = learnLogic.Dictionary.Statistics.GetKnown(DateTime.Now.AddDays(1));
                Assert.AreEqual<int>(5, known, "GetKnown() did not return the correct number of known cards");
            }
        }
Beispiel #5
0
        public void GetCurrentStatsTest()
        {
            if (TestInfrastructure.IsActive(TestContext))
            {
                ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext);
                LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate)delegate { return; });
                try
                {
                    learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString));
                }
                catch (IsOdxFormatException)
                {
                    if (TestInfrastructure.ConnectionType(TestContext) == "File")
                        return;
                    else
                        throw;
                }

                learnLogic.OnLearningModuleOptionsChanged();
                learnLogic.Dictionary.ResetLearningProgress();

                //Answer Card correct
                Card currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID);
                UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, currentCard.CurrentAnswer.Words.Count,
                    currentCard.CurrentAnswer.Words.Count, true, currentCard.CurrentAnswer.Words.ToString());
                learnLogic.OnUserInputSubmit(this, e);
                learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs());

                //Answer Card wrong
                currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID);
                e = new UserInputSubmitTextEventArgs(0, 0, currentCard.CurrentAnswer.Words.Count, false, string.Empty);
                learnLogic.OnUserInputSubmit(this, e);
                learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs());

                LearnStats stats = learnLogic.Dictionary.Statistics.GetCurrentStats();
                Assert.AreEqual<int>(1, stats.NumberOfRights, "GetCurrentStats() did not return the correct LearnStats.NumberOfRights");
                Assert.AreEqual<int>(1, stats.NumberOfWrongs, "GetCurrentStats() did not return the correct LearnStats.NumberOfWrongs");
            }
        }
        public void GradeCardTest()
        {
            if (TestInfrastructure.IsActive(TestContext))
            {
                ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext);
                LearnLogic llogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate)delegate { return; });
                //llogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser,
                //    connectionString, (DataAccessErrorDelegate)delegate { return; });

                try
                {
                    llogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString));
                }
                catch (IsOdxFormatException)
                {
                    if (TestInfrastructure.ConnectionType(TestContext) == "File")
                        return;
                    else
                        throw;
                }

                llogic.OnLearningModuleOptionsChanged();

                Card card = llogic.Dictionary.Cards.GetCardByID(llogic.CurrentCardID);
                int oldBox = card.BaseCard.Box = 5;

                UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, card.CurrentAnswer.Words.Count, card.CurrentAnswer.Words.Count, true, card.CurrentAnswer.Words.ToString());
                llogic.OnUserInputSubmit(this, e);

                Assert.AreEqual<int>(oldBox + 1, card.BaseCard.Box, "Card was not correctly promoted!");

                card.BaseCard.Box = oldBox;

                e = new UserInputSubmitTextEventArgs(5, 0, 5, false, string.Empty);
                llogic.OnUserInputSubmit(this, e);

                Assert.AreEqual<int>(1, card.BaseCard.Box, "Card was not demoted!");
            }
        }