A Godot Engine app to help streamers organize Majority Judgment polls in their streams.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

106 lines
3.2 KiB

extends WAT.Test
enum Grades2 {
DISAPPROVE
APPROVE
}
enum Grades3 {
TO_REJECT
PASSABLE
GOOD
}
enum Grades4 {
TO_REJECT
PASSABLE
GOOD
EXCELLENT
}
enum Grades5 {
TO_REJECT
POOR
PASSABLE
GOOD
EXCELLENT
}
enum Grades6 {
TO_REJECT
POOR
PASSABLE
GOOD
VERY_GOOD
EXCELLENT
}
func test_common_usage():
var grading = MajorityJudgmentGrading.new()
grading.set_grades([
MajorityJudgmentGrade.make("To Reject"),
MajorityJudgmentGrade.make("Poor"),
MajorityJudgmentGrade.make("Passable"),
MajorityJudgmentGrade.make("Good"),
MajorityJudgmentGrade.make("Very Good"),
MajorityJudgmentGrade.make("Excellent"),
])
asserts.is_not_null(grading, "Instantiate Grading")
var poll = MajorityJudgmentPoll.new()
asserts.is_not_null(poll, "Instantiate Poll")
asserts.is_class_instance(poll, MajorityJudgmentPoll, "Check Poll class")
poll.set_grading(grading)
poll.set_title("POTUS 2020?")
var candidates = [
MajorityJudgmentCandidate.make("Joe Dalton"),
MajorityJudgmentCandidate.make("Rantanplan"),
MajorityJudgmentCandidate.make("Ma Dalton"),
MajorityJudgmentCandidate.make("Jolly Jumper"),
]
poll.set_candidates(candidates)
var sylvain = MajorityJudgmentParticipant.make("Sylvain")
var judgment_of_sylvain_on_rantanplan = MajorityJudgmentJudgment.new()
judgment_of_sylvain_on_rantanplan.set_participant(sylvain)
judgment_of_sylvain_on_rantanplan.set_candidate(candidates[1])
judgment_of_sylvain_on_rantanplan.set_grade(poll.grading.grades[Grades6.POOR])
poll.add_judgment(judgment_of_sylvain_on_rantanplan)
asserts.is_not_null(poll.judgments, "Sylvain judges Rantanplan")
asserts.is_equal(poll.judgments.size(), 1, "Sylvain's judgment is recorded")
var poll_tally = poll.tally()
asserts.is_not_null(poll_tally, "Poll can be tallied")
asserts.is_class_instance(poll_tally, MajorityJudgmentPollTally, "Poll tally has correct class")
asserts.is_equal(poll_tally.candidates_tallies.size(), 4, "Tally has correct size")
asserts.is_equal(poll_tally.candidates_tallies[0].candidate.name, "Rantanplan", "Rantanplan is the winner")
asserts.is_equal(poll_tally.candidates_tallies[0].position, 1, "Rantanplan is number one")
var saved_tally = ResourceSaver.save('res://test_poll_tally.tres', poll_tally)
asserts.is_equal(saved_tally, OK, "Save Poll Tally to file")
var saved_poll = ResourceSaver.save('res://test_poll.tres', poll)
asserts.is_equal(saved_poll, OK, "Save Poll to file")
var loaded_poll = ResourceLoader.load('res://test_poll.tres')
asserts.is_not_null(loaded_poll, "Load Poll from file")
asserts.is_class_instance(loaded_poll, MajorityJudgmentPoll, "Loaded poll has correct class")
asserts.is_true('title' in loaded_poll, "Loaded poll has a title")
asserts.is_equal(loaded_poll.title, poll.title, "Titles match")
asserts.is_class_instance(loaded_poll.grading, MajorityJudgmentGrading, "Loaded poll grading has correct class")
asserts.is_Array(loaded_poll.candidates, "Loaded poll has candidates")
asserts.is_equal(loaded_poll.candidates.size(), 4, "Loaded poll has all candidates")
asserts.is_class_instance(loaded_poll.candidates[0], MajorityJudgmentCandidate, "Loaded poll has correct candidates")
asserts.is_equal(loaded_poll.candidates[1].name, 'Rantanplan', "Loaded poll has correct candidates names")