Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Liquid Majority Judgment
Limaju CLI Python
Commits
a6fd8d74
Commit
a6fd8d74
authored
Dec 13, 2019
by
Dominique Merle
💬
Browse files
Add basic unit-testing and fix some bugs.
We're getting ready for tagging a release…
parent
fcee644b
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a6fd8d74
...
...
@@ -4,6 +4,8 @@
## Usage
Download the source files. (or just
`limaju.py`
)
cd limaju
### Via STDIN
...
...
@@ -37,11 +39,15 @@ Mentions are ordered. Topmost wins. Case matters.
REJECT
##
Input Vote Data
##
Judgments Data Example
### As CSV
#### votes.csv
#### judgments.csv
Quotes (
`"`
) are optional,
if you don't put commas or quotes in your candidates or mentions. _(best not)_
```
csv
"Tyrant","Capitalist","Ecologist","Communist","Preacher","Random"
POOR,REJECT,VERY GOOD,VERY GOOD,PASSABLE,EXCELLENT
...
...
@@ -91,8 +97,10 @@ PASSABLE,PASSABLE,REJECT,GOOD,PASSABLE,VERY GOOD
## Tests
This software is unit-tested with
`unittest`
.
It's basic, but it works.
python limaju/test_limaju.py -vvv
limaju/limaju.py
View file @
a6fd8d74
...
...
@@ -98,8 +98,8 @@ def sort_two_candidates(judgments_of, tally_of, mentions, ca, cb):
positions
=
get_positions
(
mentions
)
if
mdca
==
mdcb
:
cotoca
=
copy
.
copy
(
toca
)
cotocb
=
copy
.
copy
(
tocb
)
cotoca
=
copy
.
deep
copy
(
toca
)
cotocb
=
copy
.
deep
copy
(
tocb
)
while
not
is_tally_empty
(
cotoca
)
and
not
is_tally_empty
(
cotocb
):
nemdca
=
get_median
(
cotoca
,
mentions
)
...
...
@@ -109,7 +109,8 @@ def sort_two_candidates(judgments_of, tally_of, mentions, ca, cb):
decrement_mention
(
cotocb
,
nemdcb
)
else
:
return
positions
[
nemdca
]
-
positions
[
nemdcb
]
log
(
"EXACT EQUALITY FOUND FOR CANDIDATES"
)
log
(
"%s == %s"
%
(
ca
,
cb
))
return
0
else
:
return
positions
[
mdca
]
-
positions
[
mdcb
]
...
...
@@ -162,6 +163,7 @@ def main(args_parser, args): # move to bottom, no need for a func
int
(
args
.
skip_cols
)
)
log
(
"
\n
DELIBERATION"
)
for
i
,
candidate
in
enumerate
(
deliberation
):
log
(
"%02d.
\t
%18s
\t
%s"
%
(
i
+
1
,
...
...
@@ -181,8 +183,8 @@ def load_judgments_from_string(judgments_string):
return
judgments_data
def
load_mentions_from_string
(
ms
):
return
[
m
.
strip
()
for
m
in
ms
.
strip
().
split
()
if
m
and
m
.
strip
()]
def
load_mentions_from_string
(
ms
,
sep
=
"
\n
"
):
return
[
m
.
strip
()
for
m
in
ms
.
strip
().
split
(
sep
)
if
m
and
m
.
strip
()]
def
deliberate
(
judgments_data
,
...
...
limaju/test_limaju.py
0 → 100644
View file @
a6fd8d74
import
unittest
from
limaju
import
deliberate
class
TestLimaju
(
unittest
.
TestCase
):
test_mentions_array
=
[
u
'EXCELLENT'
,
u
'VERY GOOD'
,
u
'GOOD'
,
u
'SOMEWHAT GOOD'
,
u
'PASSABLE'
,
u
'POOR'
,
u
'REJECT'
,
]
test_mentions
=
"""
EXCELLENT
VERY GOOD
GOOD
SOMEWHAT GOOD
PASSABLE
POOR
REJECT
"""
def
test_run_with_array
(
self
):
deliberation
,
tally
=
deliberate
([
[
'A'
,
'B'
,
'C'
],
[
'POOR'
,
'GOOD'
,
'REJECT'
],
[
'EXCELLENT'
,
'GOOD'
,
'EXCELLENT'
],
],
self
.
test_mentions_array
)
self
.
assertEqual
(
deliberation
,
[
'B'
,
'A'
,
'C'
])
def
test_dumb_deliberation_with_one_candidate
(
self
):
deliberation
,
tally
=
deliberate
(
u
"""
A
PASSABLE
EXCELLENT
"""
,
self
.
test_mentions
)
self
.
assertEqual
(
deliberation
,
[
'A'
])
def
test_deliberation_with_one_judge
(
self
):
deliberation
,
tally
=
deliberate
(
u
"""
A, B, C, D
REJECT, PASSABLE, POOR, GOOD
"""
,
self
.
test_mentions
)
self
.
assertEqual
(
deliberation
,
[
'D'
,
'B'
,
'C'
,
'A'
])
def
test_deliberation_with_two_judges
(
self
):
deliberation
,
tally
=
deliberate
(
u
"""
A, B, C
POOR, GOOD, REJECT
EXCELLENT, GOOD, EXCELLENT
"""
,
self
.
test_mentions
)
self
.
assertEqual
(
deliberation
,
[
'B'
,
'A'
,
'C'
])
def
test_deliberation_with_same_median_mention
(
self
):
deliberation
,
tally
=
deliberate
(
u
"""
A, B, C, D
POOR, GOOD, REJECT, PASSABLE
EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT
EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT
"""
,
self
.
test_mentions
)
self
.
assertEqual
(
deliberation
,
[
'B'
,
'D'
,
'A'
,
'C'
])
# def test_raise(self):
# with self.assertRaises(TypeError):
# s.split(2)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment