#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
pub struct Guess {
value: i32,
}
impl Rectangle {
fn can_hold(&self, other: &Rectangle) -> bool {
self.width > other.width && self.height > other.height
}
}
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Value should be between 1 and 100 only.");
}
Guess { value }
}
}
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn something_else() {
let result = add(2, 2);
assert_eq!(result, 4);
}
#[test]
fn larger_can_hold_smaller() {
let larger = Rectangle { width: 8, height: 7 };
let smaller = Rectangle { width: 5, height: 1 };
assert!(larger.can_hold(&smaller));
}
#[test]
fn smaller_can_not_hold_larger() {
let larger = Rectangle { width: 8, height: 7 };
let smaller = Rectangle { width: 5, height: 1 };
assert!(!smaller.can_hold(&larger));
}
#[test]
#[should_panic(expected = "between 1 and 100")]
fn greater_than_100() {
Guess::new(200);
}
}