public override void Validate()
        {
            var myAutocompletter = new TrieAutocompletter();
            myAutocompletter.FillVocabulary(_vocabulary);
            var _actualAnswer = myAutocompletter.GetWordsForPrefixes(_prefixes).ToArray();

            var rightAutocompletter = new CorrectAutocompletter();
            rightAutocompletter.FillVocabulary(_vocabulary);
            var _expectedAnswer = rightAutocompletter.GetWordsForPrefixes(_prefixes).ToArray();

            Assert.AreEqual(_prefixes.Count(), _actualAnswer.Count(),
                            string.Format("Count ofword's sets in reply is {0}," +
                                          " and isn't equal to {1} (number of prefixes)",
                                           _actualAnswer.Count(), _prefixes.Count()));

            Action<int> checkOnePrefix =
                (index) =>
                    {
                        var notEqualMessage =
                            string.Format("Set №{0} in reply. There shouls be {1}, but really there is {2}",
                                           index, _expectedAnswer[index].FormDefinitionString(),
                                           _actualAnswer[index].FormDefinitionString());
                        Assert.AreEqual(_expectedAnswer[index], _actualAnswer[index], notEqualMessage);
                    };
            Parallel.For(0, _prefixes.Count(), checkOnePrefix);
        }
        public override void Validate()
        {
            var pathToTempInputFile = Path.GetTempFileName();
            var pathToTempOutputFile = Path.GetTempFileName();
            Utils.SaveInputToFile(pathToTempInputFile,_vocabulary, _prefixes);

            try
            {
                var stopwatch = Stopwatch.StartNew();
                var inputReader = new InputFileReader(pathToTempInputFile);
                _fileReadingTimeInMills = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                var vocabulary = inputReader.ReadVocabulary();
                _vocabularyParsingTimeInMills = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                var prefixes = inputReader.ReadPrefixes();
                _prefixesParsingTimeInMills = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                var autocompletter = new TrieAutocompletter();
                autocompletter.FillVocabulary(vocabulary);
                _fillingTimeInMills = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                var wordsForPrefixes = autocompletter.GetWordsForPrefixes(prefixes);
                _answeringTimeInMills = stopwatch.ElapsedMilliseconds;

                stopwatch.Restart();
                var answerSaver = new FileAnswerSaver(pathToTempOutputFile);
                answerSaver.SaveAnswer(wordsForPrefixes);
                _fileWritingTimeInMills = stopwatch.ElapsedMilliseconds;

                _totalWorkTimeInMills = _fileReadingTimeInMills + _vocabularyParsingTimeInMills +
                                        _prefixesParsingTimeInMills
                                        + _fillingTimeInMills + _answeringTimeInMills + _fileWritingTimeInMills;
                SaveMetricsInfoToFile();

                Assert.IsTrue(_totalWorkTimeInMills < TestSettings.Default.MaxTotalTimeInMills,
                              string.Format("Total work time for '{0}' is {1} ms." +
                                            " It's greater than max permissible ({2} ms)",
                                            _inputSettings.FormDescriptionString(),
                                            _totalWorkTimeInMills, TestSettings.Default.MaxTotalTimeInMills));
            }
            finally
            {
                File.Delete(pathToTempInputFile);
                File.Delete(pathToTempOutputFile);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            var inputReader = new InputFileReader(Settings.Default.PathToInputFile);
            var vocabulary = inputReader.ReadVocabulary();
            var prefixes = inputReader.ReadPrefixes();

            var autocompletter = new TrieAutocompletter();
            autocompletter.FillVocabulary(vocabulary);
            var wordsForPrefixes = autocompletter.GetWordsForPrefixes(prefixes);

            var answerSaver = new FileAnswerSaver(Settings.Default.PathToOutputFile);
            answerSaver.SaveAnswer(wordsForPrefixes);

            foreach (var a in File.ReadAllLines(Settings.Default.PathToOutputFile))
            {
                Console.WriteLine(a);
            }
        }