diff options
| author | Mo <76752051+mo8it@users.noreply.github.com> | 2024-04-18 13:02:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-18 13:02:35 +0200 |
| commit | 819dea250034a5658d0fe3306f6c35fc49961e17 (patch) | |
| tree | 122060cdc0ef3f81d367e0afc7b0e3e9d29d33ee /exercises/13_error_handling/errors4.rs | |
| parent | c613b70363c60c6f4305d09c7394c96cdc6b69e4 (diff) | |
| parent | 01e6732e4d920d9a1859e05fa28382e4307571af (diff) | |
Merge pull request #1949 from rust-lang/third-party-exercises
Support for third-party exercises
Diffstat (limited to 'exercises/13_error_handling/errors4.rs')
| -rw-r--r-- | exercises/13_error_handling/errors4.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/exercises/13_error_handling/errors4.rs b/exercises/13_error_handling/errors4.rs index 0e5c08b..993d42a 100644 --- a/exercises/13_error_handling/errors4.rs +++ b/exercises/13_error_handling/errors4.rs @@ -1,8 +1,3 @@ -// errors4.rs -// -// Execute `rustlings hint errors4` or use the `hint` watch subcommand for a -// hint. - #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); @@ -19,12 +14,21 @@ impl PositiveNonzeroInteger { } } -#[test] -fn test_creation() { - assert!(PositiveNonzeroInteger::new(10).is_ok()); - assert_eq!( - Err(CreationError::Negative), - PositiveNonzeroInteger::new(-10) - ); - assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); +fn main() { + // You can optionally experiment here. +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_creation() { + assert!(PositiveNonzeroInteger::new(10).is_ok()); + assert_eq!( + Err(CreationError::Negative), + PositiveNonzeroInteger::new(-10) + ); + assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); + } } |
