Closed
Description
A case like - "223.456abc.7890" should be added to tests cause a code like mine (in Rust) can easily pass the tests -
let mut v = vec![' ';10];
let mut tmp = 9;
for ch in user_number.chars().rev(){
match ch {
c @ '0'..='9' =>{
if (tmp == -1 && c != '1')
|| (tmp == 0 && c == '1')
|| (tmp == 0 && c == '0')
|| (tmp == 3 && c == '0')
|| (tmp == 3 && c == '1'){
return None;
}
if tmp >=0 {
v[tmp as usize] = c;
}
tmp -= 1;
}
_ => continue,
}
}
if v[0] == ' '{return None;}
Some(v.iter().collect())
}
test like this should be added (the code above will treat it as a valid number, but it isn't valid) -
fn invalid_chars() {
let input = "223.456abc.7890";
let output = number(input);
assert!(output.is_none());
}
Metadata
Metadata
Assignees
Labels
No labels