summaryrefslogtreecommitdiff
path: root/exercises/13_error_handling/errors4.rs
diff options
context:
space:
mode:
Diffstat (limited to 'exercises/13_error_handling/errors4.rs')
-rw-r--r--exercises/13_error_handling/errors4.rs30
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));
+ }
}