-
Notifications
You must be signed in to change notification settings - Fork 26
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
#203 added EQUALS_FAST and HASH_CODE_FAST #205
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/pl/pojo/tester/internal/tester/EqualsFastTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pl.pojo.tester.internal.tester; | ||
|
||
import pl.pojo.tester.internal.field.AbstractFieldValueChanger; | ||
|
||
public class EqualsFastTester extends EqualsTester { | ||
|
||
public EqualsFastTester() { | ||
super(); | ||
setThoroughTesting(false); | ||
} | ||
|
||
public EqualsFastTester(final AbstractFieldValueChanger abstractFieldValueChanger) { | ||
super(abstractFieldValueChanger); | ||
setThoroughTesting(false); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/pl/pojo/tester/internal/tester/HashCodeFastTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package pl.pojo.tester.internal.tester; | ||
|
||
import pl.pojo.tester.internal.field.AbstractFieldValueChanger; | ||
|
||
/** | ||
* Created by me on 26/08/17. | ||
*/ | ||
public class HashCodeFastTester extends HashCodeTester { | ||
|
||
public HashCodeFastTester() { | ||
super(); | ||
setThoroughTesting(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://stackoverflow.com/a/3404369 You can create protected constructor in |
||
} | ||
|
||
public HashCodeFastTester(final AbstractFieldValueChanger abstractFieldValueChanger) { | ||
super(abstractFieldValueChanger); | ||
setThoroughTesting(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pl.pojo.tester.internal.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public final class Sublists { | ||
private Sublists() { | ||
} | ||
|
||
/** | ||
* Given a list of objects, return a list of sublists, i-th sublist includes i-th element of | ||
* the original list and all elements that follow it in the original list. | ||
* All returned lists are read-only and backed by a copy of the original list, so later changes | ||
* in the original list will not affect the returned sublists. | ||
* | ||
* @param list list of objects | ||
* @param <T> the type of list element | ||
* @return sublists of list | ||
*/ | ||
public static <T> List<List<T>> subsequences(final List<T> list) { | ||
final List<T> copyOfList = new ArrayList<>(list); | ||
final List<List<T>> res = new ArrayList<>(); | ||
for (int i = 0; i < copyOfList.size(); i++) { | ||
res.add(Collections.unmodifiableList(copyOfList.subList(i, copyOfList.size()))); | ||
} | ||
return Collections.unmodifiableList(res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package pl.pojo.tester.api; | ||
|
||
import classesForTest.packageFilter.A; | ||
import classesForTest.packageFilter.B; | ||
import classesForTest.packageFilter.C; | ||
import classesForTest.packageFilter.next.D; | ||
import classesForTest.packageFilter.next.E; | ||
import org.junit.jupiter.api.Test; | ||
import pl.pojo.tester.api.assertion.Method; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.catchThrowable; | ||
import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; | ||
|
||
|
||
public class FastTestingTest { | ||
|
||
@Test | ||
void ShouldCompleteInReasonableTime() { | ||
long start = System.currentTimeMillis(); | ||
{ | ||
// given | ||
final Class<?> classUnderTest = Medium.class; | ||
|
||
// when | ||
|
||
// then | ||
assertPojoMethodsFor(classUnderTest) | ||
.testing(Method.EQUALS_FAST, Method.HASH_CODE_FAST) | ||
.areWellImplemented(); | ||
} | ||
long end = System.currentTimeMillis(); | ||
assertThat(end - start).isLessThan(500l); | ||
} | ||
} | ||
|
||
class Medium { | ||
int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u; | ||
|
||
@Override | ||
public boolean equals(Object o1) { | ||
if (this == o1) { | ||
return true; | ||
} | ||
if (o1 == null || getClass() != o1.getClass()) { | ||
return false; | ||
} | ||
|
||
Medium medium = (Medium) o1; | ||
|
||
if (a != medium.a) { | ||
return false; | ||
} | ||
if (b != medium.b) { | ||
return false; | ||
} | ||
if (c != medium.c) { | ||
return false; | ||
} | ||
if (d != medium.d) { | ||
return false; | ||
} | ||
if (e != medium.e) { | ||
return false; | ||
} | ||
if (f != medium.f) { | ||
return false; | ||
} | ||
if (g != medium.g) { | ||
return false; | ||
} | ||
if (h != medium.h) { | ||
return false; | ||
} | ||
if (i != medium.i) { | ||
return false; | ||
} | ||
if (j != medium.j) { | ||
return false; | ||
} | ||
if (k != medium.k) { | ||
return false; | ||
} | ||
if (l != medium.l) { | ||
return false; | ||
} | ||
if (m != medium.m) { | ||
return false; | ||
} | ||
if (n != medium.n) { | ||
return false; | ||
} | ||
if (o != medium.o) { | ||
return false; | ||
} | ||
if (p != medium.p) { | ||
return false; | ||
} | ||
if (q != medium.q) { | ||
return false; | ||
} | ||
if (r != medium.r) { | ||
return false; | ||
} | ||
if (s != medium.s) { | ||
return false; | ||
} | ||
if (t != medium.t) { | ||
return false; | ||
} | ||
return u == medium.u; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = a; | ||
result = 31 * result + b; | ||
result = 31 * result + c; | ||
result = 31 * result + d; | ||
result = 31 * result + e; | ||
result = 31 * result + f; | ||
result = 31 * result + g; | ||
result = 31 * result + h; | ||
result = 31 * result + i; | ||
result = 31 * result + j; | ||
result = 31 * result + k; | ||
result = 31 * result + l; | ||
result = 31 * result + m; | ||
result = 31 * result + n; | ||
result = 31 * result + o; | ||
result = 31 * result + p; | ||
result = 31 * result + q; | ||
result = 31 * result + r; | ||
result = 31 * result + s; | ||
result = 31 * result + t; | ||
result = 31 * result + u; | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
It would be better to pass some kind of policy, that would generate fields / list of fields e.g.