Skip to content

New test case for Phone Number exercise #2434

Closed
@Aryan570

Description

@Aryan570

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions