def test_get_final_result_without_questions(self): selected_proposals = [self.p1, self.p3] calculator = Calculator(self.election, [], selected_proposals) R = calculator._get_result().tolist() self.assertEquals(R, [[2], [2], [0]]) final_result = calculator.get_result() expected = {'candidates': [{'candidate':self.c1, 'value': 100}, {'candidate':self.c2, 'value': 100}], 'election': self.election} self.assertEquals(final_result, expected)
def test_instanciate(self): self.setUpQuestions() selected_positions = [self.position1, self.position4] selected_proposals = [self.p1, self.p3] calculator = Calculator(self.election, selected_positions, selected_proposals) P_x_R = calculator._get_questions_vector_result().tolist() expected_questions_result = [[1], [0], [0]] self.assertEquals(P_x_R, expected_questions_result) C = calculator.get_commitments_result().tolist() self.assertEquals(C, [[2], [2], [0]])
def test_get_the_hundred(self): self.setUpQuestions() selected_positions = [self.position1, self.position4] selected_proposals = [self.p1, self.p3] calculator = Calculator(self.election, selected_positions, selected_proposals) self.assertEquals(calculator.hundred_percent, 2.0) a = Area.objects.create(name=u"Valdivia") election2 = Election.objects.create( name=u'the name', area=a) calculator = Calculator(election2, selected_positions, selected_proposals) self.assertEquals(calculator.hundred_percent, 2) calculator = Calculator(election2, [], []) self.assertEquals(calculator.hundred_percent, 1)
def done(self, form_list, **kwargs): cleaned_data = self.get_all_cleaned_data() results = [] has_parent = True element_selector = cleaned_data['element_selector'] elections = self.get_proposal_class()().get_elections(element_selector) for election in elections: calculator = Calculator(election, cleaned_data['positions'], cleaned_data['proposals']) results.append(calculator.get_result()) is_creator_of_this_proposals_filter = Q(organization__proposals__in=cleaned_data['proposals']) is_liker_of_this_proposals = Q(organization__likes__proposal__in=cleaned_data['proposals']) organization_templates = OrganizationTemplate.objects.filter(is_creator_of_this_proposals_filter|is_liker_of_this_proposals).distinct() return render(self.request, 'medianaranja2/resultado.html', { 'results': results, 'organizations': organization_templates })
def test_get_result(self): TakenPosition.objects.create(topic=self.topic2, person=self.c3, position=self.position4) TakenPosition.objects.create(topic=self.topic1, person=self.c3, position=self.position1) positions = [self.position1, self.position4] adapter = Adapter(self.election, positions) calculator = Calculator(self.election) calculator.set_questions_adapter(adapter) result = calculator._get_questions_vector_result().tolist() expected_result = [[1], [0], [2]] self.assertEquals(result, expected_result) candidate_result = calculator.get_questions_result() expected = { 'candidates': [{ 'candidate': self.c3, 'value': 2 }, { 'candidate': self.c1, 'value': 1 }, { 'candidate': self.c2, 'value': 0 }], "election": self.election } self.assertEquals(candidate_result, expected)
def test_get_final_result(self): self.setUpQuestions() selected_positions = [self.position1, self.position4] selected_proposals = [self.p1, self.p3] calculator = Calculator(self.election, selected_positions, selected_proposals) calculator.set_questions_importance(0.5) calculator.set_proposals_importance(0.5) R = calculator._get_result().tolist() self.assertEquals(R, [[1.5],[1],[0]]) final_result = calculator.get_result() expected = {'candidates': [{'candidate':self.c1, 'value':75.0}, {'candidate':self.c2, 'value': 50.0}], 'election': self.election} self.assertEquals(final_result, expected)
def test_get_result(self): TakenPosition.objects.create(topic=self.topic2, person=self.c3, position=self.position4) TakenPosition.objects.create(topic=self.topic1, person=self.c3, position=self.position1) positions = [self.position1, self.position4] adapter = Adapter(self.election, positions) calculator = Calculator(self.election) calculator.set_questions_adapter(adapter) result = calculator._get_questions_vector_result().tolist() expected_result = [[1], [0], [2]] self.assertEquals(result, expected_result) candidate_result = calculator.get_questions_result() expected = {'candidates': [{'candidate':self.c3, 'value': 2}, {'candidate':self.c1, 'value': 1}, {'candidate':self.c2, 'value': 0}], "election": self.election } self.assertEquals(candidate_result, expected)
def test_get_result(self): adapter = CommitmentsAdapter(self.election, [self.p1, self.p3]) calculator = Calculator(self.election) calculator.set_commitments_adapter(adapter) R = calculator.get_commitments_result().tolist() self.assertEquals(R, [[2], [2], [0]])