Skip to content

Simplify assertions with equivalent but more simple.#196

Merged
aherbert merged 1 commit intoapache:masterfrom
arturobernalg:feature/simplify_assert
Aug 13, 2021
Merged

Simplify assertions with equivalent but more simple.#196
aherbert merged 1 commit intoapache:masterfrom
arturobernalg:feature/simplify_assert

Conversation

@arturobernalg
Copy link
Member

No description provided.

@aherbert
Copy link
Contributor

aherbert commented Aug 8, 2021

Please fix checkstyle so the Travis CI job will run with the changes.

Copy link
Contributor

@aherbert aherbert left a comment

Choose a reason for hiding this comment

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

All looks good except for assertions testing the equals method on an object. These must put the object where the equals method will be invoked as the first argument to the assertion. In particular this allows testing o.equals(null) on the object being tested (since null.equals(o) is nonsense.

public void testEquals() {
Pair<Integer, Double> p1 = new Pair<>(null, null);
Assert.assertFalse(p1.equals(null));
Assert.assertNotEquals(null, p1);
Copy link
Contributor

Choose a reason for hiding this comment

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

p1 should be the first argument to allow the assert method to invoke p1.equals(null)

Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new Array2DRowRealMatrix(bigSingular)));
Assert.assertNotEquals(null, m);
Copy link
Contributor

Choose a reason for hiding this comment

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

m should be the first argument

Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new BlockFieldMatrix<>(bigSingular)));
Assert.assertNotEquals(null, m);
Copy link
Contributor

Choose a reason for hiding this comment

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

m should be the first argument

Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new BlockRealMatrix(bigSingular)));
Assert.assertNotEquals(null, m);
Copy link
Contributor

Choose a reason for hiding this comment

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

m should be the first argument

Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(new Array2DRowFieldMatrix<>(bigSingular)));
Assert.assertNotEquals(null, m);
Copy link
Contributor

Choose a reason for hiding this comment

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

m should be the first argument

Assert.assertFalse(m.equals(null));
Assert.assertFalse(m.equals(mt));
Assert.assertFalse(m.equals(createSparseMatrix(bigSingular)));
Assert.assertNotEquals(null, m);
Copy link
Contributor

Choose a reason for hiding this comment

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

m should be the first argument

final double[] p1 = new double[] { 1 };
final PointValuePair pv1 = new PointValuePair(p1, 2);
Assert.assertFalse(pv1.equals(null));
Assert.assertNotEquals(null, pv1);
Copy link
Contributor

Choose a reason for hiding this comment

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

pv1 should be the first argument

Assert.assertFalse(markers.equals(null));
Assert.assertFalse(markers.equals(""));
Assert.assertEquals(markers, markers);
Assert.assertNotEquals(null, markers);
Copy link
Contributor

Choose a reason for hiding this comment

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

markers should be the first argument

Assert.assertEquals(ptile, ptile);
Assert.assertFalse(ptile.equals(null));
Assert.assertFalse(ptile.equals(""));
Assert.assertNotEquals(null, ptile);
Copy link
Contributor

Choose a reason for hiding this comment

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

ptile should be the first argument

Assert.assertFalse(ptile.equals(null));
Assert.assertFalse(ptile.equals(""));
Assert.assertNotEquals(null, ptile);
Assert.assertNotEquals("", ptile);
Copy link
Contributor

Choose a reason for hiding this comment

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

ptile should be the first argument

@arturobernalg arturobernalg requested a review from aherbert August 12, 2021 05:21
@arturobernalg
Copy link
Member Author

HI @aherbert
Changed
TY

@coveralls
Copy link

coveralls commented Aug 12, 2021

Coverage Status

Coverage increased (+0.009%) to 90.49% when pulling a9d2f45 on arturobernalg:feature/simplify_assert into 872b655 on apache:master.

@aherbert
Copy link
Contributor

There are still a few assertions with null as the first argument. I think you updated 5 and there are 7 remaining.

@aherbert aherbert merged commit 1e4662d into apache:master Aug 13, 2021
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