initial commit
This commit is contained in:
4
exercises/04_traits/14_outro/Cargo.toml
Normal file
4
exercises/04_traits/14_outro/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "outro_03"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
10
exercises/04_traits/14_outro/src/lib.rs
Normal file
10
exercises/04_traits/14_outro/src/lib.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
// TODO: Define a new `SaturatingU16` type.
|
||||
// It should hold a `u16` value.
|
||||
// It should provide conversions from `u16`, `u8`, `&u16` and `&u8`.
|
||||
// It should support addition with a right-hand side of type
|
||||
// SaturatingU16, u16, &u16, and &SaturatingU16. Addition should saturate at the
|
||||
// maximum value for `u16`.
|
||||
// It should be possible to compare it with another `SaturatingU16` or a `u16`.
|
||||
// It should be possible to print its debug representation.
|
||||
//
|
||||
// Tests are located in the `tests` folder—pay attention to the visibility of your types and methods.
|
||||
17
exercises/04_traits/14_outro/tests/integration.rs
Normal file
17
exercises/04_traits/14_outro/tests/integration.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use outro_03::SaturatingU16;
|
||||
|
||||
#[test]
|
||||
fn test_saturating_u16() {
|
||||
let a: SaturatingU16 = (&10u8).into();
|
||||
let b: SaturatingU16 = 5u8.into();
|
||||
let c: SaturatingU16 = u16::MAX.into();
|
||||
let d: SaturatingU16 = (&1u16).into();
|
||||
let e = &c;
|
||||
|
||||
assert_eq!(a + b, SaturatingU16::from(15u16));
|
||||
assert_eq!(a + c, SaturatingU16::from(u16::MAX));
|
||||
assert_eq!(a + d, SaturatingU16::from(11u16));
|
||||
assert_eq!(a + a, 20u16);
|
||||
assert_eq!(a + 5u16, 15u16);
|
||||
assert_eq!(a + e, SaturatingU16::from(u16::MAX));
|
||||
}
|
||||
Reference in New Issue
Block a user