Skip to content

feat: add assert/has-same-constructor #5446

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

abhishekblue
Copy link
Contributor


type: pre_push_report
description: Results of running various checks prior to pushing changes. report:

  • task: run_javascript_examples status: na
  • task: run_c_examples status: na
  • task: run_cpp_examples status: na
  • task: run_javascript_readme_examples status: na
  • task: run_c_benchmarks status: na
  • task: run_cpp_benchmarks status: na
  • task: run_fortran_benchmarks status: na
  • task: run_javascript_benchmarks status: na
  • task: run_julia_benchmarks status: na
  • task: run_python_benchmarks status: na
  • task: run_r_benchmarks status: na
  • task: run_javascript_tests status: na ---

Resolves #815.

Description

What is the purpose of this pull request?

This pull request:

  • Adds a fully implemented hasSameConstructor utility to the @stdlib/assert/ namespace to test if two values have the same constructor.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Feb 25, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 25, 2025

Coverage Report

Package Statements Branches Functions Lines
assert/has-same-constructor $\color{green}98/98$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}98/98$
$\color{green}+100.00\%$
assert $\color{green}2733/2733$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}2733/2733$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@abhishekblue abhishekblue changed the title feat(assert): Add @stdlib/assert/has-same-constructor feat(assert): add hasSameConstructor Feb 25, 2025
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---
@anandkaranubc
Copy link
Contributor

/stdlib lint-autofix

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Feb 26, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Feb 26, 2025
@anandkaranubc
Copy link
Contributor

anandkaranubc commented Feb 26, 2025

@abhishekblue Thanks for working on this issue. That looks like a good starting point.

The first step here is to ensure that every comment in this PR has been addressed in this one. Also, other similar packages in assert/* will be a good reference point too.

Can you also change the title to:

feat: add assert/has-same-constructor

@anandkaranubc
Copy link
Contributor

This will also resolve the CI failures you're currently experiencing.

@anandkaranubc anandkaranubc added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Feb 26, 2025
t.end();
});

tape( 'compare two null values', function test( t ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The test descriptions in this file should be more descriptive and follow project's code conventions. Looking at other packages would be useful to fix this.

Comment on lines 46 to 50
* // returns true
*
*/

function hasSameConstructor( x, y ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* // returns true
*
*/
function hasSameConstructor( x, y ) {
* // returns true
*/
function hasSameConstructor( x, y ) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure you are following correct spacing conventions throughout this PR.

@abhishekblue abhishekblue changed the title feat(assert): add hasSameConstructor feat: add assert/has-same-constructor Feb 26, 2025
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: failed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: failed
---
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Feb 27, 2025
@abhishekblue
Copy link
Contributor Author

@Neerajpathak07 @anandkaranubc, I’ve been working on this PR but I’m struggling to pass the tests despite multiple attempts. Could you please provide some guidance or point me to resources that might help me resolve these issues? I’d really appreciate your support. Thanks!

@@ -30,8 +30,10 @@
"bugs": {
"url": "https://github.com/stdlib-js/stdlib/issues"
},
"dependencies": {},
"devDependencies": {},
"dependencies": {
Copy link
Member

Choose a reason for hiding this comment

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

In absolutely no circumstances should you be editing this file in this PR. These dependencies should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must've accidentally edited this file. Apologies for this!

});

tape( 'the function returns `true` if provided two arguments which have the same constructor', function test ( t ) {
var values;
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure you have installed and setup EditorConfig. You have mixed tabs and spaces throughout this file. You can find more instructions in our contributing and development guides.

var bool;
var i;

values =[
Copy link
Member

Choose a reason for hiding this comment

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

You need to rethink these tests. Testing built-in primitives isn't particularly interesting. The entire purpose of this API is to determine whether two class instances share the same original constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kgryte, thank you for your feedback. To confirm, should I create custom classes and their constructors and run tests specifically on those constructors to determine whether class instances share the same original constructor? Just want to be sure before proceeding further.

* // returns true
*/
function hasSameConstructor( x, y ) {
if ( x === null || y === null ) {
Copy link
Member

Choose a reason for hiding this comment

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

What about undefined?

@kgryte kgryte changed the title feat: add assert/has-same-constructor feat: add assert/has-same-constructor Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First PR A pull request resolving a Good First Issue. Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Add @stdlib/assert/has-same-constructor
4 participants