Skip to content

exercises(pangram): test more non-alphanumeric printable ASCII#361

Merged
ee7 merged 1 commit intoexercism:mainfrom
MatthijsBlom:add-test-case-nonalphanum-print
Nov 30, 2023
Merged

exercises(pangram): test more non-alphanumeric printable ASCII#361
ee7 merged 1 commit intoexercism:mainfrom
MatthijsBlom:add-test-case-nonalphanum-print

Conversation

@MatthijsBlom
Copy link
Copy Markdown
Contributor

This test checks that the submitted solution does not panic on non-alphanumeric input.

Faulty solution 'from the wild' that is caught by this test but not by the others:

pub fn isPangram(str: []const u8) bool {
    var seen = std.bit_set.StaticBitSet('z' - 'a' + 1).initEmpty();
    for (str) |c| {
        const index = std.math.sub(u8, std.ascii.toLower(c), 'a') catch continue;
        // if  c > 'z'  then  index > 25  😱
        seen.set(index);  // panics when  index >= 26
    }
    return ~seen.mask == 0;
}

There are no test cases in problem-specifications that could be pulled in to the same effect. I will not myself pursue upstreaming into problem-specifications.

@github-actions
Copy link
Copy Markdown
Contributor

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

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


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions Bot closed this Nov 29, 2023
@ee7
Copy link
Copy Markdown
Member

ee7 commented Nov 30, 2023

Somewhat similar test cases were rejected or removed upstream in the past:

However, in this case I'm inclined to merge. It's true that the existing non-alphanumeric printable ASCII characters in the tests are sufficiently close to 'a' and 'z' to not cause a panic for an implementation similar to the one given. Thanks for the contribution.

@ee7 ee7 reopened this Nov 30, 2023
@ee7 ee7 self-assigned this Nov 30, 2023
@ee7 ee7 changed the title Add test case: non-alphanumeric printable ASCII exercises(pangram): add test for non-alphanumeric printable ASCII Nov 30, 2023
@ee7 ee7 merged commit 692936e into exercism:main Nov 30, 2023
@ee7 ee7 changed the title exercises(pangram): add test for non-alphanumeric printable ASCII exercises(pangram): test more non-alphanumeric printable ASCII Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants