@@ -53,6 +53,43 @@ def test_identity(self):
5353
5454 values = response .json ()
5555 self .assertEqual (values , expected_result )
56+
57+ #Value y expected_result son distintos
58+ def test_identity_multiple_questions_fails (self ):
59+ data = [{
60+ 'type' : 'IDENTITY' ,
61+ 'options' : [
62+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : 5 },
63+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : 0 },
64+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : 3 }
65+ ]
66+ }, {
67+ 'type' : 'IDENTITY' ,
68+ 'options' : [
69+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : 2 },
70+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : 5 },
71+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : 1 }
72+ ]
73+ }]
74+
75+ #El orden debe ser descendente, según el serializer
76+ expected_result = [{
77+ 'type' : 'IDENTITY' ,
78+ 'options' : [
79+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : 5 ,
80+ 'postproc' : 5 },
81+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : 3 ,
82+ 'postproc' : 3 },
83+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : 0 ,
84+ 'postproc' : 0 }
85+ ]
86+ }]
87+
88+ response = self .client .post ('/postproc/' , data , format = 'json' )
89+ self .assertEqual (response .status_code , 200 )
90+
91+ values = response .json ()
92+ self .assertNotEqual (values , expected_result )
5693
5794
5895
@@ -104,6 +141,7 @@ def test_identity_multiple_questions_1(self):
104141 values = response .json ()
105142 self .assertEqual (values , expected_result )
106143
144+
107145 def test_identity_multiple_questions_2 (self ):
108146 data = [{
109147 'type' : 'IDENTITY' ,
@@ -154,7 +192,7 @@ def test_identity_multiple_questions_2(self):
154192 values = response .json ()
155193 self .assertEqual (values , expected_result )
156194
157-
195+ #TESTS DE HONDT
158196 def test_hondt (self ):
159197 data = [{
160198 'type' : 'HONDT' ,
@@ -315,5 +353,95 @@ def test_hondt_without_options(self):
315353 }]
316354
317355 response = self .client .post ('/postproc/' , data , format = 'json' )
356+
357+ #TESTS DE BORDA
358+ def test_borda (self ):
359+ data = [{
360+ 'type' : 'BORDA' ,
361+ 'options' : [
362+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [6 , 1 , 2 , 4 , 3 , 2 ]},
363+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [1 , 2 , 7 , 1 , 6 , 1 ]},
364+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 , 7 , 4 , 3 , 1 , 1 ]},
365+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [4 , 1 , 2 , 4 , 3 , 4 ]},
366+ {'option' : 'Option 5' , 'number' : 5 , 'votes' : [3 , 6 , 2 , 2 , 1 , 4 ]},
367+ {'option' : 'Option 6' , 'number' : 6 , 'votes' : [2 , 1 , 1 , 4 , 4 , 6 ]},
368+ ]
369+ }]
370+
371+ expected_result = [{
372+ 'type' : 'BORDA' ,
373+ 'options' : [
374+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 , 7 , 4 , 3 , 1 , 1 ], 'postproc' : 75 },
375+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [6 , 1 , 2 , 4 , 3 , 2 ], 'postproc' : 69 },
376+ {'option' : 'Option 5' , 'number' : 5 , 'votes' : [3 , 6 , 2 , 2 , 1 , 4 ], 'postproc' : 68 },
377+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [1 , 2 , 7 , 1 , 6 , 1 ], 'postproc' : 60 },
378+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [4 , 1 , 2 , 4 , 3 , 4 ], 'postproc' : 59 },
379+ {'option' : 'Option 6' , 'number' : 6 , 'votes' : [2 , 1 , 1 , 4 , 4 , 6 ], 'postproc' : 47 },
380+ ]
381+ }]
382+
383+ response = self .client .post ('/postproc/' , data , format = 'json' )
384+ self .assertEqual (response .status_code , 200 )
318385
386+ values = response .json ()
387+ self .assertEqual (values , expected_result )
388+
389+ def test_borda_one_option (self ):
390+ data = [{
391+ 'type' : 'BORDA' ,
392+ 'options' : [
393+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [4 ]},
394+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [3 ]},
395+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 ]},
396+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [1 ]},
397+ ]
398+ }]
399+
400+ expected_result = [{
401+ 'type' : 'BORDA' ,
402+ 'options' : [
403+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [4 ], 'postproc' : 4 },
404+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [3 ], 'postproc' : 3 },
405+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 ], 'postproc' : 2 },
406+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [1 ], 'postproc' : 1 },
407+ ]
408+ }]
409+
410+ #El resultado debe cuadrar con las votaciones de cada opcion ya que no se ha establecido un orden de preferencia, si no que unicamente se ha votado
411+ #por la opcion preferida y el factor multiplicador será 1
412+
413+ response = self .client .post ('/postproc/' , data , format = 'json' )
414+ self .assertEqual (response .status_code , 200 )
415+
416+ values = response .json ()
417+ self .assertEqual (values , expected_result )
418+
419+
420+ def test_borda_different_size_preferences (self ):
421+ data = [{
422+ 'type' : 'BORDA' ,
423+ 'options' : [
424+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [4 ,2 ]},
425+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [2 ,2 ,3 ]},
426+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 ,2 ]},
427+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [1 ,3 ]},
428+ ]
429+ }]
430+
431+ expected_result = [{
432+ 'type' : 'BORDA' ,
433+ 'options' : [
434+ {'option' : 'Option 1' , 'number' : 1 , 'votes' : [4 ,2 ], 'postproc' : 10 },
435+ {'option' : 'Option 3' , 'number' : 3 , 'votes' : [2 ,2 ], 'postproc' : 6 },
436+ {'option' : 'Option 4' , 'number' : 4 , 'votes' : [1 ,3 ], 'postproc' : 5 },
437+ #Como la opcion 2 tiene mas variables se considera nula
438+ {'option' : 'Option 2' , 'number' : 2 , 'votes' : [2 ,2 ,3 ], 'postproc' : 0 },
439+ ]
440+ }]
441+
442+ response = self .client .post ('/postproc/' , data , format = 'json' )
443+ self .assertEqual (response .status_code , 200 )
444+
445+ values = response .json ()
446+ self .assertEqual (values , expected_result )
319447
0 commit comments