phayes / tallystick Goto Github PK
View Code? Open in Web Editor NEWA rust library for tallying votes
A rust library for tallying votes
Dependabot couldn't parse the Cargo.toml found at /Cargo.toml
.
The error Dependabot encountered was:
Dependabot::DependencyFileNotParseable
Hello! I'm planning to use your library in my betterpoll project. Before I make the API publicly available, I'd like to know how tallystick
is licensed. I don't see any LICENSE file; if you plan to license tallystick
under a copyleft license I'd like to know that so I can license my project accordingly. (I'm currently planning to use the MIT license, but I'm happy to change that.)
Thanks!
Noticed this by chance in my own testing. While trivial to work around I figured I'd report it. I haven't checked if other methods have similar issues.
Here is a failing test:
#[test]
fn schulze_single_canidate() -> Result<(), TallyError> {
let candidates = vec!["A".to_string()];
let votes_raw = "A";
let votes = Cursor::new(votes_raw);
let votes = util::read_votes(votes).unwrap();
// Margin
let mut tally = DefaultSchulzeTally::with_candidates(1, Variant::Margin, candidates.clone());
for (vote, weight) in votes.iter() {
match vote {
util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
}
}
assert_eq!(tally.winners().into_unranked()[0], "A".to_string());
// Winning
let mut tally = DefaultSchulzeTally::with_candidates(1, Variant::Winning, candidates.clone());
for (vote, weight) in votes.iter() {
match vote {
util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
}
}
assert_eq!(tally.winners().into_unranked()[0], "A".to_string());
// Ratio
let votes = Cursor::new(votes_raw);
let votes = util::read_votes(votes).unwrap(); // reparse votes as f64
let mut tally = SchulzeTally::<_, f64>::with_candidates(1, Variant::Ratio, candidates.clone());
for (vote, weight) in votes.iter() {
match vote {
util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
}
}
assert_eq!(tally.winners().into_unranked()[0], "A".to_string());
Ok(())
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.