use crate::interface::{WithSeats, WithVotes};
#[derive(Debug)]
pub struct Candidacy {
votes: u32,
seats: u16,
}
impl Candidacy {
pub fn new(votes: u32, seats: u16) -> Candidacy {
Candidacy { votes, seats }
}
}
impl WithVotes for Candidacy {
fn get_votes(&self) -> u32 {
self.votes
}
fn set_votes(&mut self, votes: u32) {
self.votes = votes;
}
}
impl WithSeats for Candidacy {
fn get_seats(&self) -> u16 {
self.seats
}
fn set_seats(&mut self, seats: u16) {
self.seats = seats;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_candidacy() {
let mut candidacy = Candidacy::new(1000, 3);
assert_eq!(candidacy.get_votes(), 1000);
assert_eq!(candidacy.get_seats(), 3);
candidacy.set_votes(2000);
candidacy.set_seats(5);
assert_eq!(candidacy.get_votes(), 2000);
assert_eq!(candidacy.get_seats(), 5);
}
}