initial commit
This commit is contained in:
29
exercises/03_ticket_v1/01_struct/src/lib.rs
Normal file
29
exercises/03_ticket_v1/01_struct/src/lib.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// Define a struct named `Order` with the following fields:
|
||||
// - `price`, an unsigned integer
|
||||
// - `quantity`, an unsigned integer
|
||||
//
|
||||
// It should also have a method named `is_available` that returns a `true` if the quantity is
|
||||
// greater than 0, otherwise `false`.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_order_is_available() {
|
||||
let order = Order {
|
||||
price: 100,
|
||||
quantity: 10,
|
||||
};
|
||||
assert!(order.is_available());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_order_is_not_available() {
|
||||
let order = Order {
|
||||
price: 100,
|
||||
quantity: 0,
|
||||
};
|
||||
assert!(!order.is_available());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user