#Rust: Bob

37 messages · Page 1 of 1 (latest)

potent dew
#

Hello, I'm having issues with one exercice, may someone explain me what's going wrong
link to the exercise : https://exercism.org/tracks/rust/exercises/bob

my code :

pub fn reply(message: &str) -> &str {
    match message {
        "How are you?" => "Sure.",
        message if (message.chars().all(|x| x.is_ascii_uppercase())) => "Whoa, chill out!",
        message if (message.chars().all(|x| x.is_ascii_uppercase()) && message.contains("?")) => "Calm down, I know what I'm doing!",
        "" => "Fine. Be that way!",
        _ => "Whatever."
    }
}

I don't get, it always return "Whatever."
it passes 9 tests, and fails the others I don't get why tho

Exercism

Can you solve Bob in Rust? Improve your Rust skills with support from our world-class team of mentors.

subtle idol
#

Can you copy/paste the output from a failing test in a codeblock?

#

What code does the test run, what does it expect, what does it get?

potent dew
# subtle idol Can you copy/paste the output from a failing test in a codeblock?

here's few lines of code, the test is running :

#[test]
/// stating something
fn stating_something() {
    process_response_case("Tom-ay-to, tom-aaaah-to.", "Whatever.");
}

#[test]
#[ignore]
/// ending with whitespace
fn ending_with_whitespace() {
    process_response_case("Okay if like my  spacebar  quite a bit?   ", "Sure.");
}

#[test]
#[ignore]
/// shouting numbers
fn shouting_numbers() {
    process_response_case("1, 2, 3 GO!", "Whoa, chill out!");
}

#[test]
#[ignore]
/// other whitespace
fn other_whitespace() {
    process_response_case("\r\r     ", "Fine. Be that way!");
}

#[test]
#[ignore]
/// shouting with special characters
fn shouting_with_special_characters() {
    process_response_case(
        "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
        "Whoa, chill out!",
    );
}

here is the results :

#

I feel like the output is random, even tho I don't understand why

subtle idol
#

Could you paste the test output in a codeblock?

#

Consider input "1, 2, 3 GO!"

#

What do you expect your function to return?

#

Do you understand what the test expects to get and why?

#

It looks like the test runner here doesn't show the function call with the input along with the output, which is unfortunate.

potent dew
potent dew
# subtle idol What do you expect your function to return?

it shouldnt return something precise described in the exercice :

Your task is to determine what Bob will reply to someone when they say something to him or ask him a question.

Bob only ever answers one of five things:

    "Sure." This is his response if you ask him a question, such as "How are you?" The convention used for questions is that it ends with a question mark.
    "Whoa, chill out!" This is his answer if you YELL AT HIM. The convention used for yelling is ALL CAPITAL LETTERS.
    "Calm down, I know what I'm doing!" This is what he says if you yell a question at him.
    "Fine. Be that way!" This is how he responds to silence. The convention used for silence is nothing, or various combinations of whitespace characters.
    "Whatever." This is what he answers to anything else.

subtle idol
#

Looking at your code and that specific input, what do you expect your code to return?

#

@potent dew ?

#

What do you expect your code to do with that input?

potent dew
#

and it shouldnt return whatever

subtle idol
#

Which line of your code would cause that input to return Sure?

potent dew
#

third line

subtle idol
#

The "How are you?" match?

#

Consider input "1, 2, 3 GO!"

potent dew
subtle idol
#

Why would input "1, 2, 3 GO!" match "How are you?" ?

#

Those strings are nothing alike

potent dew
subtle idol
potent dew
#

yes

subtle idol
#

What does that condition check?

potent dew
#

as every chars is in uppercase and it has a "!" in it

subtle idol
#

"1, 2, 3 GO!" has an uppercase for every char?

#

Is the first character an uppercase?

potent dew
#

well yes and no, GO is uppercase but are 1,2,3 are not are not counted as uppercase i guess

subtle idol
#

So that wouldn't match?

#

What would your code return for input "1, 2, 3 GO!" in that case?

potent dew
#

Whatever, but it should return "Whoa, Chill out!"

#

so there are problems in my if condition

subtle idol
#

Sounds like you've found a bug in your code 😉