/*
         * Starts the test set with the given information.
         * If the files are read successfully, starts the test.
         * Otherwise, displays an error dialog.
         */
        private void startTestSet(Info.CategoryInfo categoryInfo, Info.TestSetInfo testSetInfo, int numRounds, int numQuestionsPerRound)
        {
            // Read the test set
            TestSet testSet = TestFileReader.readTestSet(categoryInfo, testSetInfo);

            // If the test set files were read successfully
            if (testSet != null)
            {
                // Remove the bad questions
                testSet.removeIncompleteOrInvalidQuestions();

                // Randomize the questions
                testSet.randomizeQuestions();

                // Calculate the total number of questions
                int numQuestions = numRounds * numQuestionsPerRound;

                // If there are enough questions in the test set
                if (numQuestions <= testSet.numQuestionsAvailable())
                {
                    // Set the number of rounds and questions
                    testSet.numRounds            = numRounds;
                    testSet.numQuestionsPerRound = numQuestionsPerRound;

                    // Go to the test start page
                    contentWindow.Content = new TestStartPage(contentWindow, testSet);
                }

                // If there are not enough questions in the test set
                else
                {
                    MessageBox.Show(
                        "Only " + testSet.numQuestionsAvailable() + " questions are available for \"" + testSetInfo.testSetStringLong + "\"." +
                        " You have selected " + numQuestions + " questions.",
                        "Not Enough Questions Available",
                        MessageBoxButton.OK,
                        MessageBoxImage.Warning
                        );

                    updatePage();
                    setDefaults(categoryInfo, testSetInfo);
                }
            }

            // If the test set files were not read
            else
            {
                MessageBox.Show(
                    "The test files for \"" + testSetInfo.testSetStringLong + "\" could not be found." +
                    "\n\nMake sure that the test files are located in the Tests folder." +
                    " If this error persists, redownload the application.",
                    "Test Files Not Found",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                    );

                updatePage();
                setDefaults(categoryInfo);
            }
        }
Пример #2
0
        /*
         * Returns a test set, as read and combined from the files for the tests in the set.
         * May return null if none of the test files are opened correctly.
         */
        public static TestSet readTestSet(Info.CategoryInfo categoryInfo, Info.TestSetInfo testSetInfo)
        {
            List <Test> tests = new List <Test>();

            // Go through each of the tests in the test set
            foreach (Info.TestName testName in testSetInfo.testNames)
            {
                // Read the test
                Test test = readTest(testName);

                // If the test was read successfully, add it to the list
                if (test != null)
                {
                    tests.Add(test);
                }
            }

            // If any tests were read successfully, create the test set
            if (tests.Count > 0)
            {
                return(new TestSet(categoryInfo, testSetInfo, tests, 0, 0));
            }
            else
            {
                return(null);
            }
        }
        /*
         * Sets a default category.
         */
        private void setDefaults(Info.CategoryInfo defaultCategoryInfo)
        {
            updatePage();

            enableCategoryComboBox();
            categoryComboBox.SelectedIndex = availableCategories.IndexOf(defaultCategoryInfo);

            enableTestComboBox(defaultCategoryInfo);
        }
        /*
         * Start button event handler.
         */
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            // Hide the warning label
            hideWarning();

            // If a category is selected
            if (isACategorySelected())
            {
                // If a test is selected
                if (isATestSelected())
                {
                    // If a number of rounds is selected
                    if (areRoundsSelected())
                    {
                        // If a number of questions is selected
                        if (areQuestionsSelected())
                        {
                            Info.CategoryInfo categoryInfo = getSelectedCategory();
                            Info.TestSetInfo  testSetInfo  = getSelectedTest();
                            int numRounds    = getSelectedRounds();
                            int numQuestions = getSelectedQuestions();

                            startTestSet(categoryInfo, testSetInfo, numRounds, numQuestions);
                        }

                        // If a number of questions is not selected
                        else
                        {
                            warningLabel.Content    = "You must select the questions per round.";
                            warningLabel.Visibility = Visibility.Visible;
                        }
                    }

                    // If a number of rounds is not selected
                    else
                    {
                        warningLabel.Content    = "You must select the rounds.";
                        warningLabel.Visibility = Visibility.Visible;
                    }
                }

                // If a test is not selected
                else
                {
                    warningLabel.Content    = "You must select a test.";
                    warningLabel.Visibility = Visibility.Visible;
                }
            }

            // If a category is not selected
            else
            {
                warningLabel.Content    = "You must select a category.";
                warningLabel.Visibility = Visibility.Visible;
            }
        }
        /*
         * Constructor with default category and test.
         */
        public SelectionPage(Window contentWindow, Info.CategoryInfo defaultCategoryInfo, Info.TestSetInfo defaultTestSetInfo)
        {
            InitializeComponent();

            this.contentWindow = contentWindow;

            this.availableCategories = Info.availableCategories;
            this.availableTestSets   = new List <Info.TestSetInfo>();
            this.availableRounds     = AVAILABLE_ROUNDS;
            this.availableQuestions  = AVAILABLE_QUESTIONS;

            updatePage();

            setDefaults(defaultCategoryInfo, defaultTestSetInfo);
        }
Пример #6
0
        /*
         * Constructor
         */
        public TestSet(Info.CategoryInfo categoryInfo, Info.TestSetInfo testSetInfo, List <Test> tests, int numRounds, int numQuestionsPerRound)
        {
            this.categoryInfo = categoryInfo;
            this.testSetInfo  = testSetInfo;

            this.questions = new List <TestQuestion>();
            foreach (Test test in tests)
            {
                this.questions.AddRange(test.questions);
            }

            this.numRounds            = numRounds;
            this.numQuestionsPerRound = numQuestionsPerRound;

            this.currentRoundIndex         = 0;
            this.currentRoundQuestionIndex = 0;
        }
        /*
         * Enables the test combo box and sets its items to match the category.
         */
        private void enableTestComboBox(Info.CategoryInfo categoryInfo)
        {
            testComboBox.IsEnabled = true;

            availableTestSets = Info.availableTestSets[categoryInfo.categoryName];

            List <String> testSetStrings = new List <String>();

            foreach (Info.TestSetInfo testSetInfo in availableTestSets)
            {
                testSetStrings.Add(testSetInfo.testSetStringShort);
            }

            testComboBox.ItemsSource   = testSetStrings;
            testComboBox.SelectedIndex = -1;

            updateStartButton();
        }