Regular-chatbot Exercise clarification

Regarding the regular-chatbot exercise and its “Check Valid Phone Number” task:

There are discrepancies between the exercise instructions, the source code template comments, and the test definition for the “check_phone_number” function input format.

  • The instructions suggest that the input description might be “chatbot command containing a phone number”
  • The solution source code template regular-chatbot.jq describes the input as “number”
  • The “well-formatted” test cases partially agree with the instructions, passing phrases, but only one of those is a “chatbot” command
  • The “ill-formatted” test cases only pass numbers, not phrases.

Assuming “phrase containing phone number” is the desired description, some simplification of where in the input to find the number would better fit this level of exercise, such as requiring exactly Call me at <phone number>, otherwise Hello chatbot, Happy 2024! My digits are (+1) 123-456-789 is difficult to parse for (and capture) the ill-formatted number.

Note, however, that the regular-chatbot exercise in the javascript track assumes the input to be just the phone number, no phrase around it. I think that that approach better keeps the focus on the learning objectives of this exercise, as I understand them. I’ve got a PR ready if this is a helpful direction to go to resolve the conflicts above. In this case, older submissions will not fail, as one test case would be removed and no test cases added.

This is explicitly a regular expression exercise. The whole point of regular expressions is that you can form a regex which can find a certain pattern anywhere in the string. Having a well defined input format or command defeats the purpose of the exercise.

With a correct regex, the format of the rest of the input should not matter at all.

I see your point. Unfortunately, the problem statement is not specific enough to deduce the correct solution using regex alone. In fact, the exemplar solution will fail with even slightly different inputs.

These two tests would fail on the current exemplar

@test 'recognizes a nearly-correctly-formatted phone number in a phrase' {
    ## task 3
    run jq -rn '
        include "regular-chatbot";
        "Hello, (+11) 987-654-3210 is my number" | check_phone_number
    '
    assert_success
    assert_output "Oops, it seems like I can't reach out to (+11) 987-654-3210."
}

@test 'From a phrase, informs the user that a phone number is incorrect' {
    ## task 3
    run jq -rn '
        include "regular-chatbot";
        "Hello, (+1) 987-654-321 is my number" | check_phone_number
    '
    assert_success
    assert_output "Oops, it seems like I can't reach out to (+1) 987-654-321."
}

The exemplar thinks that input #1 is ok (it’s not) and it can’t extract the bad number in input #2.

(edit: a typo in the first test case above)

@glennj What did you intend with this exercise? The exemplar uses "Oops, it seems like I can't reach out to \(.)." which suggests the input should be a number. But the test contains both sentences and raw numbers.

I think I stole the exercise from the javascript track, but I’ll need to take some time (that I don’t have right now) to recall its origins.

1 Like