rustlings/exercises/07_structs/structs1.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2024-06-21 23:22:37 +03:00
struct ColorRegularStruct {
// TODO: Add the fields that the test `regular_structs` expects.
// What types should the fields have? What are the minimum and maximum values for RGB colors?
2019-05-25 14:39:58 +03:00
}
2024-06-21 23:22:37 +03:00
struct ColorTupleStruct(/* TODO: Add the fields that the test `tuple_structs` expects */);
2019-05-25 14:39:58 +03:00
#[derive(Debug)]
2024-06-21 23:22:37 +03:00
struct UnitStruct;
2019-05-25 14:39:58 +03:00
fn main() {
// You can optionally experiment here.
}
2019-05-25 14:39:58 +03:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
2024-06-21 23:22:37 +03:00
fn regular_structs() {
// TODO: Instantiate a regular struct.
2019-05-25 14:39:58 +03:00
// let green =
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
assert_eq!(green.blue, 0);
2019-05-25 14:39:58 +03:00
}
#[test]
fn tuple_structs() {
2024-06-21 23:22:37 +03:00
// TODO: Instantiate a tuple struct.
2019-05-25 14:39:58 +03:00
// let green =
assert_eq!(green.0, 0);
assert_eq!(green.1, 255);
assert_eq!(green.2, 0);
2019-05-25 14:39:58 +03:00
}
#[test]
fn unit_structs() {
2024-06-21 23:22:37 +03:00
// TODO: Instantiate a unit struct.
// let unit_struct =
let message = format!("{unit_struct:?}s are fun!");
2019-05-25 14:39:58 +03:00
2024-06-21 23:22:37 +03:00
assert_eq!(message, "UnitStructs are fun!");
2019-05-25 14:39:58 +03:00
}
}