You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I failed these tests initially, but when I looked at them, I realized that a reasonable interpretation of the instructions would produce different results.
Specifically, the tests test_bad_age, test_missing_age, and test_missing_name are not testing the behavior that I inferred from the instructions. I understood the instruction (4) to be "If the name is empty, return [a Person with the default name]" and (6) to be "If parsing the age fails, return [a Person with the default age]".
The reason my brain immediately jumped to this incorrect conclusion is that the context makes it clear that, in such a case, it's possilbe the rest of the information is valid--so why throw away valid information?
I don't think the tests or instructions are wrong, only that they could be clearer (or better).
For reference, here is what my initial implementation looked like:
impl From<&str> for Person { fn from(s: &str) -> Self { let strs: Vec::<&str> = s.split(',').collect(); match strs[..] { [in_name, in_age] => Person { name: match in_name {s if s.is_empty() => Person::default().name, s => s.to_string() }, age: in_age.parse::<u8>().unwrap_or(Person::default().age) }, _ => Person::default() } } }
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I failed these tests initially, but when I looked at them, I realized that a reasonable interpretation of the instructions would produce different results.
Specifically, the tests
test_bad_age,test_missing_age, andtest_missing_nameare not testing the behavior that I inferred from the instructions. I understood the instruction (4) to be "If the name is empty, return [a Person with the default name]" and (6) to be "If parsing the age fails, return [a Person with the default age]".The reason my brain immediately jumped to this incorrect conclusion is that the context makes it clear that, in such a case, it's possilbe the rest of the information is valid--so why throw away valid information?
I don't think the tests or instructions are wrong, only that they could be clearer (or better).
For reference, here is what my initial implementation looked like:
Beta Was this translation helpful? Give feedback.
All reactions