private IList <EnRuWord> GetTestData(ITestTypes testType) { var testDataBulder = new TestDataBuilder(this._wordsCollection); var testData = testDataBulder .GetTestData(this._testCollectionSize, testType); return(testData); }
public IEnumerable <PickerTestModel> BuildPickerTest( ITestTypes testType, int anserOptionsCount ) { var testData = this.GetTestData(testType); var wordCount = testData.Count; var pickerModels = new List <PickerTestModel>(); if (!testData.Any()) { return(pickerModels); } var random = new Random(); for (int i = 0; i < wordCount; i++) { var answerIndex = random.Next(anserOptionsCount); var answer = testType.IsEnRu ? testData[i].RussianWord.RuWord : testData[i].EnglishWord.EnWord; var testWord = testType.IsEnRu ? testData[i].EnglishWord.EnWord : testData[i].RussianWord.RuWord; if (testWord == null || answer == null) { return(pickerModels); } var randAnswer = GetAnswerOptions( answer, i, this._wordsCollection, testType.IsEnRu, anserOptionsCount ); var pickerTestModel = new PickerTestModel { AnswerId = answerIndex, Word = testWord, WordId = testData[i].Id, Answers = randAnswer.ToList(), Example = testData[i].Example }; pickerTestModel.Answers[answerIndex] = answer; pickerModels.Add(pickerTestModel); } return(pickerModels); }
public IList <EnRuWord> GetTestData(int expectedSize, ITestTypes testType) { var enRuWords = this._wordCollection; if (enRuWords.Count() < expectedSize) { expectedSize = enRuWords.Count(); if (expectedSize < 1) { return(new List <EnRuWord>()); } } var levelAppropriateWords = enRuWords .Where( r => r.WordLevel >= testType.MinLevel && r.WordLevel <= testType.MaxLevel ); var testData = this.FilterByStudyPriority( levelAppropriateWords, expectedSize ); if (testData.Count() < expectedSize) { var lowerLevelWords = enRuWords .Where(r => r.WordLevel < testType.MinLevel); var lowerLevelTestData = this.FilterByStudyPriority( lowerLevelWords, expectedSize - testData.Count(), true ); testData = testData.Union(lowerLevelTestData); } return(testData.ToList()); }
public IEnumerable <WriteTestModel> BuildPickerTest(ITestTypes testType) { var testData = GetTestData(new WriteTest()); var writeTestModelList = new List <WriteTestModel>(); if (!testData.Any()) { return(writeTestModelList); } foreach (var testDataItem in testData) { var ruWord = _repositoryFactory.EnRuWordsRepository .AllRussianWords() .FirstOrDefault(r => r.Id == testDataItem.RussianWordId) .RuWord; var answerWord = _repositoryFactory.EnRuWordsRepository .AllEnglishWords() .FirstOrDefault(r => r.Id == testDataItem.EnglishWordId) .EnWord; if (ruWord == null || answerWord == null) { throw new Exception("russian or english word is null"); } var writeTestModel = new WriteTestModel { Word = ruWord, TrueAnswer = answerWord, EnRuWordId = testDataItem.Id, Example = testDataItem.Example }; writeTestModelList.Add(writeTestModel); } return(writeTestModelList); }