

def test_state_rule_answer_logs(self):
    exp = exp_domain.Exploration.create_default_exploration('eid', 'title', 'category')
    exp_services.save_new_exploration('user_id', exp)
    state_name = exp.init_state_name
    answer_log = stats_domain.StateRuleAnswerLog.get('eid', state_name, self.DEFAULT_RULESPEC_STR)
    self.assertEquals(answer_log.answers, {
        
    })
    self.assertEquals(answer_log.total_answer_count, 0)
    self.assertEquals(answer_log.get_top_answers(2), [])
    event_services.AnswerSubmissionEventHandler.record('eid', 1, state_name, self.DEFAULT_RULESPEC_STR, 'answer1')
    answer_log = stats_domain.StateRuleAnswerLog.get('eid', state_name, self.DEFAULT_RULESPEC_STR)
    self.assertEquals(answer_log.answers, {
        'answer1': 1,
    })
    self.assertEquals(answer_log.total_answer_count, 1)
    self.assertEquals(answer_log.get_top_answers(1), [('answer1', 1)])
    self.assertEquals(answer_log.get_top_answers(2), [('answer1', 1)])
    event_services.AnswerSubmissionEventHandler.record('eid', 1, state_name, self.DEFAULT_RULESPEC_STR, 'answer1')
    event_services.AnswerSubmissionEventHandler.record('eid', 1, state_name, self.DEFAULT_RULESPEC_STR, 'answer2')
    answer_log = stats_domain.StateRuleAnswerLog.get('eid', state_name, self.DEFAULT_RULESPEC_STR)
    self.assertEquals(answer_log.answers, {
        'answer1': 2,
        'answer2': 1,
    })
    self.assertEquals(answer_log.total_answer_count, 3)
    self.assertEquals(answer_log.get_top_answers(1), [('answer1', 2)])
    self.assertEquals(answer_log.get_top_answers(2), [('answer1', 2), ('answer2', 1)])
    event_services.AnswerSubmissionEventHandler.record('eid', 1, state_name, self.DEFAULT_RULESPEC_STR, 'answer2')
    event_services.AnswerSubmissionEventHandler.record('eid', 1, state_name, self.DEFAULT_RULESPEC_STR, 'answer2')
    answer_log = stats_domain.StateRuleAnswerLog.get('eid', state_name, self.DEFAULT_RULESPEC_STR)
    self.assertEquals(answer_log.answers, {
        'answer1': 2,
        'answer2': 3,
    })
    self.assertEquals(answer_log.total_answer_count, 5)
    self.assertEquals(answer_log.get_top_answers(1), [('answer2', 3)])
    self.assertEquals(answer_log.get_top_answers(2), [('answer2', 3), ('answer1', 2)])

dataset/ETHPy150Open oppia/oppia/core/domain/stats_domain_test.py StateRuleAnswerLogUnitTests.test_state_rule_answer_logs/original