Wrote program for Day 4
This commit is contained in:
parent
0dc867ecb5
commit
539eddce01
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "is_johnny_making_progress"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
@ -0,0 +1,11 @@
|
||||
pub fn progress_days(days: &'static [usize]) -> usize {
|
||||
let mut progress_days = 0;
|
||||
|
||||
for i in 1..days.len() {
|
||||
if days[i] > days[i-1] {
|
||||
progress_days += 1;
|
||||
}
|
||||
}
|
||||
|
||||
progress_days
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Run `cargo test`.");
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
use is_johnny_making_progress::progress_days;
|
||||
|
||||
#[test]
|
||||
fn no_progress_days() {
|
||||
assert_eq!(progress_days(&[9, 9]), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_progress_day() {
|
||||
assert_eq!(progress_days(&[6, 5, 4, 3, 2, 9]), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_progress_days() {
|
||||
assert_eq!(progress_days(&[3, 4, 1, 2]), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn three_progress_days() {
|
||||
assert_eq!(progress_days(&[10, 11, 12, 9, 10]), 3);
|
||||
}
|
Loading…
Reference in New Issue
Block a user