Skip to content
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

Expect equality using == #1951

Open
stla opened this issue Apr 12, 2024 · 0 comments
Open

Expect equality using == #1951

stla opened this issue Apr 12, 2024 · 0 comments

Comments

@stla
Copy link

stla commented Apr 12, 2024

Hello,

My package qspray defines the qspray objects which represent polynomials.

An equality is defined for qspray objects and it is possible that qspray1 == qspray2 returns TRUE but both tests expect_identical(qspray1, qspray2) and expect_equal(qspray1, qspray2) fail.

Why? Such an object is an S4 object with two slots, powers and coeffs, the list of powers and the list of coefficients of the polynomial. It is possible that two qspray objects qspray1 and qspray2 are equal in the sense that qspray1 == qspray2 returns TRUE while they are not identical, e.g. x² + x == x + x². That's because the order of the terms of a polynomial has no importance for the equality, so in order for qspray1 == qspray2 to be TRUE, it is enough that their lists of powers and coefficients are equal up to the order. Thus expect_identical(qspray1, qspray2) fails. The same for expect_equal(qspray1, qspray2) since this test compares the slots.

So I'd like to have a test expect_equality(qspray1, qspray2) (or another name) which would do the same as expect_true(qspray1 == qspray2) but with a notable difference: expect_true(qspray1 == qspray2) does not print any useful information when it fails, whereas expect_equality(qspray1, qspray2) could print qspray1 and qspray2.

Of course, if I take the liberty to do such a feature request, that's because I think it could be useful not only for me. E.g. there are other packages dealing with polynomials, and there certainly are many packages defining the equality test == for some custom objects (e.g. the quaternions in the onion package).

Cheers.

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

No branches or pull requests

1 participant