Skip to content

Commit

Permalink
test: add tests for each function
Browse files Browse the repository at this point in the history
  • Loading branch information
iahmadgad committed Oct 28, 2024
1 parent 567837a commit cbfb19e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,51 @@ impl Timer {
self
}
}

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

#[test]
fn test_new() {
let left = Timer {
length: 0,
message: None,
vibrate: false,
};

let right = Timer::new();

assert_eq!(left, right);
}

#[test]
fn test_hour() {
let alarm = Timer::new().hour(6);
assert_eq!(alarm.length, 21_600);
}

#[test]
fn test_minutes() {
let alarm = Timer::new().minutes(30);
assert_eq!(alarm.length, 1_800);
}

#[test]
fn test_seconds() {
let alarm = Timer::new().seconds(600);
assert_eq!(alarm.length, 600);
}

#[test]
fn test_message() {
let alarm = Timer::new().message(String::from("Wake Up!"));
assert_eq!(alarm.message, Some(String::from("Wake Up!")));
}

#[test]
fn test_vibrate() {
let alarm = Timer::new().vibrate(true);
assert_eq!(alarm.vibrate, true);
}
}

0 comments on commit cbfb19e

Please sign in to comment.