-
Notifications
You must be signed in to change notification settings - Fork 96
EsLint and Tests fix #67
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
Conversation
hot9cups
commented
Oct 9, 2022
- A lot of files had Linting issues. Used EsLint to fix all the troublesome files.
- Fixed the tests that were failing. Node Tests.js should run just fine now!
- A lot of files had Linting issues. Used EsLint to fix all the troublesome files. - Fixed the tests that were failing. Node Tests.js should run just fine now!
Good to see the green check for the lint tests, finally :)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! super happy to see this!
Could you add to the README file an example of how to run the test locally?
let result = 0; | ||
while (true) { | ||
const replaced = s.replaceAll('01', '10'); | ||
for(;;) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 is this new? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so ESLint triggers lint errors on while(true)
because of the constant condition.
for(;;)
is allowed though and is seen as a workaround to this (silly) restriction.
Refer this.
We would probably need to add an exception to disable that in the workflow if we would like to disable the check for this. I'm not very sure of that right now but we can have a look at this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is super confusing 😢 but ok for now.
var test = function () { | ||
assert.deepEqual([0,1], twoSum([2,7,11,15], 9)); | ||
assert.deepEqual([1,2], twoSum([3,2,4], 6)); | ||
assert.deepEqual([0,1], twoSum([3,3], 6)); | ||
}; | ||
|
||
var test2 = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave two functions for the two different solutions? That way both cases are isolated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. Infact, the way the file was earlier with two functions, the second function 'test2' was actually not running, so the other solution wasn't even being tested. You can add some console.log statements to confirm the same but you can also have a look directly at the code that corresponds to running the test functions which can be found here. It can be seen that only the 'test' method gets invoked, if we required 'test2' to be invoked we'd have to add that in there.
And what do we do if we have 10 solutions to a problem? I don't think adding 'test2', 'test3', ...'test10' in the main Tests.js file in the test_all function is a good way to do it, besides having to deal with the exception handling for files that do not have the 'testX' method.
So maybe having just one 'test' method and testing every solution to the problem within that method was what came to my mind. Let me know if this reasoning doesn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like to have one test function for a solution so that if there is a bug in a particular solution the specific test fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well ideally I would like that to happen too but I'm not sure how we can achieve that in a clean manner without a lot of hardcoding.
Essentially, we would want to have multiple test functions exported per test file, and somehow loop through all of the functions in the import without knowing the name explicitly.
I haven't coded a lot in JavaScript so I'll need a bit of time to check. I think it's possible to do it though, as the import should be an Object instance so Object.keys might get us what we need.
I'm not super sure so I'll have to experiment and check :D
Right, sure. Did you mean the unit tests though? I believe we already have them - Or was it the linting tests. I'm not sure what's the universal way of doing it. I installed EsLint locally and ran it through the CLI. |
Lint tests I meant, we can include the node Test.js // runs all the unit tests. It already exists.
node LintTest // runs all the unit tests.
node test // runs Linter + unit tests. We can rename Test.js with a specific name for unit tests. |
I will merge this PR and if you want to tackle that you can do it in a separate PR. Again, thanks for this improvement! |
I think an even better way of doing it would perhaps be having a pre-commit hook that runs the linter before the dev is allowed to commit any code. |