Created
February 27, 2019 02:52
-
-
Save jimblandy/5a6776168866569def6be7b7279e372a to your computer and use it in GitHub Desktop.
How would you go about implementing `squeeze`?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod test { | |
use super::squeeze; | |
#[test] | |
fn test_squeeze() { | |
// The idea here is that any non-() type would work. | |
assert_eq!(squeeze(1i32, 2i32), (1, 2)); | |
assert_eq!(squeeze(true, false), (true, false)); | |
assert_eq!(squeeze("foo", Some("bar")), ("foo", Some("bar"))); | |
assert_eq!(squeeze(1i32, ()), 1); | |
assert_eq!(squeeze("foo", ()), "foo"); | |
assert_eq!(squeeze(Some(1.3), ()), Some(1.3)); | |
assert_eq!(squeeze((), 2i32), 2); | |
assert_eq!(squeeze((), "foo"), "foo"); | |
assert_eq!(squeeze((), Some(1.3)), Some(1.3)); | |
assert_eq!(squeeze((), ()), ()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment