initial commit
This commit is contained in:
10
exercises/03_ticket_v1/01_struct/Cargo.toml
Normal file
10
exercises/03_ticket_v1/01_struct/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "struct_"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lints.rust]
|
||||
# We silence dead code warnings for the time being in order to reduce
|
||||
# compiler noise.
|
||||
# We'll re-enable them again once we explain how visibility works in Rust.
|
||||
dead_code = "allow"
|
||||
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