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);
            }
        }
Esempio n. 2
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);
            }
        }