public void ComplexEntropyTest() { var knowledgeBase = new Dictionary<string, AnswerStatistic> { { "1", new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {1, 5, 1, 1}}}, {"2", new QuestionStatistic {ChoicesFrequencies = new[] {1, 1, 1, 1}}}, {"3", new QuestionStatistic {ChoicesFrequencies = new[] {1, 5, 1, 1}}} } } }, { "2", new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {1, 1, 1, 1}}}, {"2", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1, 1, 1}}}, {"3", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1, 1, 1}}} } } } }; var genie = new Genie(knowledgeBase, 4); var answeredQuestions = new List<AnsweredQuestion>(); var nextQuestionId = genie.GetNextQuestionId(answeredQuestions, genie.GetAnswerGuesses(answeredQuestions)); Assert.AreEqual("3", nextQuestionId); }
public void SaveLoadTest() { var genie = new Genie(new Dictionary<string, AnswerStatistic> { {"2", new AnswerStatistic { AnswerCount = 2, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"5", new QuestionStatistic {ChoicesFrequencies = new[] {1, 2, 3}}} } }} }, 3); var answers = new Dictionary<string, Answer> { {"2", new Answer {Text = "A", Description = "B"}} }; var questions = new Dictionary<string, Question> { {"5", new Question {Text = "Q"}} }; var memoryStream = new MemoryStream(); (new BkinatorState(genie, answers, questions)).SaveToStream(memoryStream); memoryStream.Position = 0; var resultBkinatorState = BkinatorState.LoadFromStream(memoryStream); var field = typeof(Genie).GetField("answerStatistics", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); if (field == null) Assert.Fail(); var resultingKnowledgeBase = (IDictionary<string, AnswerStatistic>)field.GetValue(resultBkinatorState.Genie); Assert.AreEqual(1, resultingKnowledgeBase.Count); Assert.AreEqual(2, resultingKnowledgeBase["2"].AnswerCount); Assert.AreEqual(1, resultingKnowledgeBase["2"].AnsweredQuestionsById.Count); Assert.AreEqual(3, resultingKnowledgeBase["2"].AnsweredQuestionsById["5"].ChoicesFrequencies.Length); Assert.AreEqual(1, resultingKnowledgeBase["2"].AnsweredQuestionsById["5"].ChoicesFrequencies[0]); Assert.AreEqual(2, resultingKnowledgeBase["2"].AnsweredQuestionsById["5"].ChoicesFrequencies[1]); Assert.AreEqual(3, resultingKnowledgeBase["2"].AnsweredQuestionsById["5"].ChoicesFrequencies[2]); Assert.AreEqual(1, resultBkinatorState.Answers.Count); Assert.AreEqual("A", resultBkinatorState.Answers["2"].Text); Assert.AreEqual("B", resultBkinatorState.Answers["2"].Description); Assert.AreEqual(1, resultBkinatorState.Questions.Count); Assert.AreEqual("Q", resultBkinatorState.Questions["5"].Text); }
public static PlayerState GetPlayerState(HttpSessionStateBase session, Genie genie) { var state = session[playerStateName]; if (state == null) { var answeredQuestions = new List<AnsweredQuestion>(); var answerGuesses = genie.GetAnswerGuesses(answeredQuestions); var currQuestionId = genie.GetNextQuestionId(answeredQuestions, answerGuesses); var newState = new PlayerState { AnswerGuesses = answerGuesses, AnsweredQuestions = answeredQuestions, CurrentQuestionId = currQuestionId }; session[playerStateName] = newState; return newState; } return (PlayerState) state; }
public void LastQuestionRemainsTest() { var knowledgeBase = new Dictionary<string, AnswerStatistic> { {"1", new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1}}}, {"2", new QuestionStatistic {ChoicesFrequencies = new[] {1, 1}}} } }} }; var genie = new Genie(knowledgeBase, 2); var answeredQuestions = new List<AnsweredQuestion> { new AnsweredQuestion {Choise = 1, QuestionId = "1"} }; var nextQuestionId = genie.GetNextQuestionId(answeredQuestions, genie.GetAnswerGuesses(answeredQuestions)); Assert.AreEqual("2", nextQuestionId); }
private static BkinatorState GetDefaultState() { var answerStrings = new[] { "C#", "C", "Java", "C++" }; var answerDescriptions = new[] { "Объектно-ориентированный язык программирования. Разработан в 1998—2001 годах в компании Microsoft как язык разработки приложений для платформы Microsoft .NET Framework.", "Стандартизированный процедурный язык программирования, разработанный в 1969—1973 годах сотрудниками Bell Labs. Си был создан для использования в операционной системе UNIX.", "Объектно-ориентированный язык программирования, разработанный компанией Sun Microsystems. Приложения Java обычно компилируются в специальный байт-код, поэтому они могут работать на любой виртуальной Java-машине.", "Компилируемый статически типизированный язык программирования общего назначения. Поддерживает такие парадигмы программирования как процедурное программирование, объектно-ориентированное программирование, обобщенное программирование." }; var answerIds = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var questionStrings = new[] { "Это ООП язык?", "VM?" }; var questionIds = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var answers = new Dictionary<string, Answer> { {answerIds[0], new Answer {Text = answerStrings[0], Description = answerDescriptions[0]}}, {answerIds[1], new Answer {Text = answerStrings[1], Description = answerDescriptions[1]}}, {answerIds[2], new Answer {Text = answerStrings[2], Description = answerDescriptions[2]}}, {answerIds[3], new Answer {Text = answerStrings[3], Description = answerDescriptions[3]}} }; var questions = new Dictionary<string, Question> { {questionIds[0], new Question {Text = questionStrings[0]}}, {questionIds[1], new Question {Text = questionStrings[1]}} }; var genie = new Genie(new Dictionary<string, AnswerStatistic> { {answerIds[0], new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {questionIds[0], new QuestionStatistic {ChoicesFrequencies = new[] {2, 1, 1, 1}}}, {questionIds[1], new QuestionStatistic {ChoicesFrequencies = new[] {2, 1, 1, 1}}} } }}, {answerIds[1], new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {questionIds[0], new QuestionStatistic {ChoicesFrequencies = new[] {1, 2, 1, 1}}}, {questionIds[1], new QuestionStatistic {ChoicesFrequencies = new[] {1, 2, 1, 1}}} } }}, {answerIds[2], new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {questionIds[0], new QuestionStatistic {ChoicesFrequencies = new[] {2, 1, 1, 1}}}, {questionIds[1], new QuestionStatistic {ChoicesFrequencies = new[] {2, 1, 1, 1}}} } }}, {answerIds[3], new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {questionIds[0], new QuestionStatistic {ChoicesFrequencies = new[] {2, 1, 1, 1}}}, {questionIds[1], new QuestionStatistic {ChoicesFrequencies = new[] {1, 2, 1, 1}}} } }} }, 4); return new BkinatorState(genie, answers, questions); }
private void SetUpComplex() { genie = new Genie(new Dictionary<string, AnswerStatistic> { {"1", new AnswerStatistic { AnswerCount = 3, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1}}} } }}, {"2", new AnswerStatistic { AnswerCount = 2, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"3", new QuestionStatistic {ChoicesFrequencies = new[] {1, 5}}} } }}, {"3", new AnswerStatistic { AnswerCount = 2, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1}}}, {"2", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1}}}, {"3", new QuestionStatistic {ChoicesFrequencies = new[] {5, 1}}} } }} }, 2); }
private void SetUpSimple() { genie = new Genie(new Dictionary<string, AnswerStatistic> { {"1", new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {2, 1}}} } }}, {"2", new AnswerStatistic { AnswerCount = 1, AnsweredQuestionsById = new Dictionary<string, QuestionStatistic> { {"1", new QuestionStatistic {ChoicesFrequencies = new[] {1, 2}}} } }} }, 2); }
// ReSharper restore UnusedMember.Local public BkinatorState(Genie genie, IDictionary<string, Answer> answers, IDictionary<string, Question> questions) { Genie = genie; Answers = answers; Questions = questions; }