Skip to content

Commit

Permalink
chore: cleanup max_seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Nov 17, 2024
1 parent cb543dc commit 628e20f
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
gloo-timers = "0.3.0"
log = "0.4.20"
wasm-logger = "0.2.0"
yew = { version="0.21.0", features=["csr"] }
yew = { version="0.21.0", features=["csr"] }
201 changes: 199 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl App {
}

fn max_seconds(&self) -> usize {
if self.round_time.minutes > 0 || self.round_time.seconds == 0 {
if self.round_time.minutes > 0 {
60
} else {
self.round_time.seconds
self.round_time.seconds.max(1)
}
}

Expand Down Expand Up @@ -233,3 +233,200 @@ fn main() {
info!("Starting up");
yew::Renderer::<App>::new().render();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_max_seconds() {
let app = App {
round_time: Time {
seconds: 30,
minutes: 1,
tenths: 0,
},
timer: Timer {
current_time: Time {
seconds: 30,
minutes: 1,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 60);
}

#[test]
fn test_max_seconds_zero() {
let app = App {
round_time: Time {
seconds: 0,
minutes: 0,
tenths: 0,
},
timer: Timer {
current_time: Time {
seconds: 0,
minutes: 0,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 1);
}

#[test]
fn test_max_seconds_one() {
let app = App {
round_time: Time {
seconds: 1,
minutes: 0,
tenths: 0,
},
timer: Timer {
current_time: Time {
seconds: 1,
minutes: 0,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 1);
}

#[test]
fn test_max_seconds_one_minute() {
let app = App {
round_time: Time {
seconds: 0,
minutes: 1,
tenths: 0,
},
timer: Timer {
current_time: Time {
seconds: 0,
minutes: 1,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 60);
}

#[test]
fn test_max_seconds_one_minute_one_second() {
let app = App {
round_time: Time {
seconds: 1,
minutes: 1,
tenths: 0,
},
timer: Timer {
current_time: Time {
seconds: 1,
minutes: 1,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 60);
}

#[test]
fn test_max_seconds_one_minute_one_second_one_tenth() {
let app = App {
round_time: Time {
seconds: 1,
minutes: 1,
tenths: 1,
},
timer: Timer {
current_time: Time {
seconds: 1,
minutes: 1,
tenths: 1,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 60);
}

#[test]
fn test_max_seconds_one_minute_one_tenth() {
let app = App {
round_time: Time {
seconds: 0,
minutes: 1,
tenths: 1,
},
timer: Timer {
current_time: Time {
seconds: 0,
minutes: 1,
tenths: 1,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 60);
}

#[test]
fn test_max_seconds_one_minute_one_tenth_zero_seconds() {
let app = App {
round_time: Time {
seconds: 0,
minutes: 1,
tenths: 1,
},
timer: Timer {
current_time: Time {
seconds: 0,
minutes: 1,
tenths: 0,
},
rounds: 1,
current_round: 1,
running: false,
},
blinked: false,
interval: None,
};
assert_eq!(app.max_seconds(), 1);
}
}

0 comments on commit 628e20f

Please sign in to comment.