Skip to content

updating tests diffie-hellman #2584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 6, 2025

Conversation

jagdish-15
Copy link
Member

@jagdish-15 jagdish-15 commented Jan 5, 2025

Pull Request

This PR syncs tests.toml with the problem-specifications repository and verifies the presence of new tests in the test file.

Copy link
Contributor

github-actions bot commented Jan 5, 2025

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 Jan 5, 2025
@Cool-Katt Cool-Katt reopened this Jan 6, 2025
@Cool-Katt
Copy link
Contributor

I was going to make a comment about the tests in this exercise not being very consistent with the naming in tests.toml but upon closer inspection, I noticed that this exercise has been marked as deprecated in exercism/problem-specifications#2149 so I'm thinking I'll let it slide.
Thoughts @SleeplessByte ?

@SleeplessByte
Copy link
Member

Eh. Right.

I think because the change is not hard @jagdish-15 can you rename the test in the JavaScript file to match the description of the test in tests.toml?

Can you also mark the exercise as deprecated in the config.json?

@Cool-Katt good stuff.

@Cool-Katt
Copy link
Contributor

Do we need to deprecate it tho? In the PR that deprecates this it seems like people reached the conclusion that tracks that have it already implemented may chose to keep it if they feel like it.

Personally, i don't think it's a particularly exciting exercise, but I also don't think it should be booted off, as it's not the worst in terms of complexity.

@jagdish-15
Copy link
Member Author

I’ve renamed one of the test sections to match the description in the tests.toml file. However, I couldn’t find the test corresponding to the "private key is random" label in the JavaScript file.

Also, @Cool-Katt and @SleeplessByte, could you let me know what you’ve agreed upon regarding marking the exercise as deprecated? Personally, I don’t think there’s any issue with keeping it as @Cool-Katt suggested, but I’m happy to proceed with whatever you all decide.

@SleeplessByte
Copy link
Member

@Cool-Katt if you think we should keep it, we'll keep it. I don't have an opinion on this particular one.

@jagdish-15 what did you mean with not being able to find "private key"? Do you mean you cannot find the test in JS or cannot find the test from JS in the .toml file? Sorry I have not checked the files yet!

@SleeplessByte
Copy link
Member

(we have extra tests that are not part of the official tests. That's fine!)

@jagdish-15
Copy link
Member Author

@SleeplessByte, what I meant was that the "private key" test from the toml file isn't present in the JS file. However, there are some extra tests in the JS file, and as you mentioned, having extra tests is fine since we have some unofficial tests. So, it's all good now!

@@ -14,7 +14,7 @@ describe('diffie-hellman', () => {
}).toThrow();
});

describe('input validation', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since our tests include custom cases that are not part of the predefined ones, the structure of our test file in not standard either. As such, the name of this section of test cases is not incorrect, and shouldn't be changed.

However, it is missing two of the standard tests, private key is greater than 1 and less than p and private key is random (i think they would be placed under validation).
@jagdish-15 can you implement the two missing tests? You can look at other tracks for inspiration, for example something similar to the Java or C# tracks' implementations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll make the changes by checking out other tracks for inspiration. It'll take a bit of time since I need to prepare for a college exam tomorrow, but I'll get to it once the exam is over. Thanks for your understanding!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best of luck on the exam!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the kind words, @Cool-Katt! I really appreciate it!

Regarding the tests, I realized while implementing them that they check the getPrivateKey method, which isn't included in either the student starter code or the proof solution. After reviewing other tracks, I saw that this method typically returns a private key, randomly chosen between 1 and p, exclusive (i.e., strictly between 1 and p). Since the tests are designed to validate this, it seems we should have such a method in place.

Would you like me to add the getPrivateKey method to both the proof solution and the starter code for students?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would probably explain why the tests for validating the private key were missing 😅
You can also amend the stub and the ci proof

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will get to it as soon as possible!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagdish-15 how is it going now? Still have time for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SleeplessByte, I apologize for the delay—I didn’t intend to hold up the PR. I was occupied with organizing a college club event for CodePVG. I’ll get to work on this right away!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SleeplessByte and @Cool-Katt,

I've made the necessary changes and implemented the getPrivateKey function along with the required tests. I ran format.mjs, lint.mjs, and test.mjs locally, and everything passed. However, the tests on GitHub are still failing. Could you help me identify the issue so I can fix it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2604

Not because of you. I'll figure that out.

Thanks for making the changes!

@Cool-Katt
Copy link
Contributor

@SleeplessByte so should we wait to sort out the CI or should we merge this?
I'm for a tentative merge, i think.

@SleeplessByte
Copy link
Member

@Cool-Katt because CI is broken, it won't be deployed at all. I'll see if I can look into that next week. Ping me if not.

@jagdish-15
Copy link
Member Author

jagdish-15 commented Apr 1, 2025

@Cool-Katt @SleeplessByte
Is it gonna take a while to be fixed?

@jagdish-15
Copy link
Member Author

@SleeplessByte , the issue has been taken care of right? Should we merge this now?

@SleeplessByte
Copy link
Member

@SleeplessByte , the issue has been taken care of right? Should we merge this now?

#2637 needs to be merged, and then #2638 needs to be merged. The result needs to be merged into this / this needs to be rebased. That will make all the failing CI pass again, and THEN this is done! <3

@Cool-Katt
Copy link
Contributor

@SleeplessByte Both prerequisite PRs have been merged o7

@SleeplessByte
Copy link
Member

@jagdish-15 if you have a moment, can you rebase? If not we will do it next week.

Thanks again!

@jagdish-15
Copy link
Member Author

Sure, I'll rebase it by EOD! And now I can start working on updating the test of further exercises right? Since the CL issue has been fixed now.

@SleeplessByte
Copy link
Member

Sure, I'll rebase it by EOD! And now I can start working on updating the test of further exercises right? Since the CL issue has been fixed now.

Yes! ❤️

@Cool-Katt
Copy link
Contributor

// diffie-hellman › private key is greater than 1 and less than p

    expect(received).toBeLessThan(expected)

    Expected: < 23
    Received:   23

That's randomness for you. Of course the very first time the tests run it randomly gets a value that makes the test fail.

@jagdish-15
Copy link
Member Author

jagdish-15 commented Jun 3, 2025

That's randomness for you. Of course the very first time the tests run it randomly gets a value that makes the test fail.

Makes sense! Is it happening every time?
I mean, when I ran the tests locally for the first time after the failed tests here, it failed on the local system too, but the second time it passed. Strange, isn't it?

@Cool-Katt
Copy link
Contributor

Makes sense! Is it happening every time? I mean, when I ran the tests locally for the first time after the failed tests here, it failed on the local system too, but the second time it passed. Strange.

Well. I don't think it should do that but I also think technically it's fine, the tests are the more important part of the PR and the proof solution is mostly to satisfy the CI gods. Generally, anything that has to do with randomness is hard to get consistency out of.

@jagdish-15
Copy link
Member Author

@SleeplessByte
I tested the code after your suggestion by temporarily replacing the random part with 0.9999 to simulate Math.random() returning the maximum value. The issue where the random key wasn't strictly less than p no longer occurs.

After the test, I reverted it back to use the actual random expression. Everything seems to be working fine now. Could you please review the final expression for generating the random key? If it looks good to you, I think we’re ready to merge!

@SleeplessByte
Copy link
Member

Yep. This should work.

@SleeplessByte SleeplessByte dismissed their stale review June 6, 2025 13:47

Resolved

@SleeplessByte SleeplessByte merged commit 3c3f39a into exercism:main Jun 6, 2025
6 checks passed
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.

3 participants