Responses for exercises in Exercism.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

96 lines
1.9 KiB

mod divmod {
//! tests of divmod
//!
//! note that we're only testing positive quantities; no need to get into the mod/rem distinction
use low_power_embedded_game::divmod;
#[test]
fn example() {
assert_eq!(divmod(10, 3), (3, 1));
}
#[test]
fn powerup() {
assert_eq!(divmod(100, 3), (33, 1));
}
#[test]
fn less() {
assert_eq!(divmod(3, 10), (0, 3));
}
#[test]
fn eq() {
assert_eq!(divmod(3, 3), (1, 0));
}
#[test]
fn multiple() {
assert_eq!(divmod(9, 3), (3, 0));
}
}
mod evens {
use low_power_embedded_game::evens;
#[test]
fn simple_i32() {
let out: Vec<i32> = evens(0..).take(5).collect();
assert_eq!(out, &[0, 2, 4, 6, 8]);
}
#[test]
fn reverse_i32() {
let out: Vec<i32> = evens((0..=10).rev()).collect();
assert_eq!(out, &[10, 8, 6, 4, 2, 0]);
}
#[test]
fn offset_i32() {
let out: Vec<i32> = evens(1..).take(5).collect();
assert_eq!(out, &[1, 3, 5, 7, 9]);
}
#[test]
fn strs() {
let input = "You really must never be above joking.".split_whitespace();
let expected: Vec<_> = "You must be joking.".split_whitespace().collect();
let out: Vec<_> = evens(input).collect();
assert_eq!(out, expected);
}
}
mod manhattan {
use low_power_embedded_game::Position;
#[test]
fn origin() {
assert_eq!(Position(0, 0).manhattan(), 0);
}
#[test]
fn q1_unit() {
assert_eq!(Position(1, 1).manhattan(), 2);
}
#[test]
fn q2_unit() {
assert_eq!(Position(1, -1).manhattan(), 2);
}
#[test]
fn q3_unit() {
assert_eq!(Position(-1, -1).manhattan(), 2);
}
#[test]
fn q4_unit() {
assert_eq!(Position(-1, 1).manhattan(), 2);
}
#[test]
fn relative_prime() {
assert_eq!(Position(30, 70).manhattan(), 100);
}
}