exercism / problem-specifications

Shared metadata for exercism exercises.
MIT License
320 stars 540 forks source link

New test case for Phone Number exercise #2434

Closed Aryan570 closed 2 months ago

Aryan570 commented 2 months ago

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());
}
github-actions[bot] commented 2 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use [this link](https://forum.exercism.org/new-topic?title=new%20test%20case%20for%20Phone%20Number%20&body=A%20case%20like%20-%20%22223.456abc.7890%22%20should%20be%20added%20to%20tests%20cause%20a%20code%20like%20mine%20(in%20Rust)%20can%20easily%20pass%20the%20tests%20%20-%0D%0A%60%60%60pub%20fn%20number(user_number:%20&str)%20-%3E%20Option%3CString%3E%20%7B%0D%0A%20%20%20%20let%20mut%20v%20=%20vec!%5B'%20';10%5D;%0D%0A%20%20%20%20let%20mut%20tmp%20=%209;%0D%0A%20%20%20%20for%20ch%20in%20user_number.chars().rev()%7B%0D%0A%20%20%20%20%20%20%20%20match%20ch%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20c%20@%20'0'..='9'%20=%3E%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(tmp%20==%20-1%20&&%20c%20!=%20'1')%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%20(tmp%20==%200%20&&%20c%20==%20'1')%20%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%20(tmp%20==%200%20&&%20c%20==%20'0')%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%20(tmp%20==%203%20&&%20c%20==%20'0')%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%7C%20(tmp%20==%203%20&&%20c%20==%20'1')%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20None;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20tmp%20%3E=0%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v%5Btmp%20as%20usize%5D%20=%20c;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20tmp%20-=%201;%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20_%20=%3E%20continue,%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20if%20v%5B0%5D%20==%20'%20'%7Breturn%20None;%7D%0D%0A%20%20%20%20Some(v.iter().collect())%0D%0A%7D%0D%0A%60%60%60%0D%0A%0D%0Atest%20like%20this%20should%20be%20added%20(the%20code%20above%20will%20treat%20it%20as%20a%20valid%20number,%20but%20it%20isn't%20valid)%20-%20%0D%0A%0D%0A%60%60%60%0D%0Afn%20invalid_chars()%20%7B%0D%0A%20%20%20%20let%20input%20=%20%22223.456abc.7890%22;%0D%0A%20%20%20%20let%20output%20=%20number(input);%0D%0A%20%20%20%20assert!(output.is_none());%0D%0A%7D%0D%0A%60%60%60&category=support ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.