Hey there,
for the Series exercise for Rust I stumbled upon this test that got me irritated:
#[test]
fn test_with_zero_length() {
let expected = vec!["".to_string(); 6];
assert_eq!(series("92017", 0), expected);
}
I hadn’t implemented anything for this, but sure - my initial thought was: Okey, you’d expect me to return “” if I ask for a 0-digit series - sound’s reasonable:
if len == 0 { return vec![String::from("")]; }
That yielded in another error; apparently one empty string wasn’t enough (well, if I read the test more thoroughly - it’s all there) - you want me to return an empty string for every possible 0-length sub string, which would be one per digit?.. Uhm… weird, but okey, let’s do that:
if len == 0 { return vec![String::from(""); digits.len()]; }
And again, the test fails - off by one. Well sure, I’d didn’t think that 0-indexed and length won’t … waiiit a minute. What?
Nope. I don’t get it. Why do you expect 6 empty strings on a 5-digit String that is to be sliced into 0-digit series?
What am I not getting? Or is this a bug? I looked into the other languages I joined, but there this is handled totally different (usually with an error). Then again, I cannot be the first one to be irritated about this, now, can I?