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

Refactor significance heuristic tests for easier extensability #75264

Merged
merged 5 commits into from
Jul 13, 2021

Conversation

benwtrent
Copy link
Member

The significant terms heuristic tests do not lend themselves well for new heuristics being added.

This commit extracts common code and builds an abstract significant heuristic test class.

This way new heuristics get the common suite of tests by extending a test class.

@benwtrent benwtrent added >test Issues or PRs that are addressing/adding tests :Analytics/Aggregations Aggregations v8.0.0 v7.15.0 labels Jul 12, 2021
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jul 12, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

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

I think this is a good refactoring. My only request is for more javadoc on the abstractions.

long c = randomLong();
long d = randomLong();
score = heuristic.getScore(a, b, c, d);
} catch (IllegalArgumentException e) {
Copy link
Member

Choose a reason for hiding this comment

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

Should the test fail here if getScore throws?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would think so, but that would require more logic in generating the values to ensure that they don't trip any checks.

I kept it the way it was to try to make this a "refactoring only" sort of PR.

assertThat(score, greaterThanOrEqualTo(0.0));
}

public abstract void testAssertions();
Copy link
Member

Choose a reason for hiding this comment

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

Needs javadoc. Abstract methods should outline what subclasses need to do to implement them correctly. I think there's a couple other undocumented abstract methods on this class that need fixed too.

GND gnd = new GND(true);
//term is only in the subset, not at all in the other set but that is because the other set is empty.
// this should actually not happen because only terms that are in the subset are considered now,
// however, in this case the score should be 0 because a term that does not exist cannot be relevant...
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking, but multi-line comments should use the /* block comment style


public class SignificanceHeuristicTests extends ESTestCase {
public abstract class AbstractSignificanceHeuristicTests extends ESTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

I think a little javadoc here to explain what you'll get by implementing this class, and what you still need to hand roll for each heuristic would be helpful. In general, I'm trying to avoid undocumented abstract classes.

@benwtrent
Copy link
Member Author

@elasticmachine update branch

@benwtrent benwtrent merged commit 379fad1 into elastic:master Jul 13, 2021
@benwtrent benwtrent deleted the tests/heuristic-test-refactor branch July 13, 2021 11:40
elasticsearchmachine pushed a commit that referenced this pull request Jul 13, 2021
… (#75291)

The significant terms heuristic tests do not lend themselves well for new heuristics being added.

This commit extracts common code and builds an abstract significant heuristic test class.

This way new heuristics get the common suite of tests by extending a test class.
benwtrent added a commit that referenced this pull request Jul 21, 2021
The original PR #75264 made some test mistakes

NXY Significant term heuristics have additional values that need to be set when testing
basicScore properties.

Additionally, previous refactor kept the abstract test class in a package that other plugins
don't have access to.

closes #75442, #75561
elasticsearchmachine pushed a commit that referenced this pull request Jul 21, 2021
The original PR #75264 made some test mistakes

NXY Significant term heuristics have additional values that need to be set when testing
basicScore properties.

Additionally, previous refactor kept the abstract test class in a package that other plugins
don't have access to.

closes #75442, #75561
ywangd pushed a commit to ywangd/elasticsearch that referenced this pull request Jul 30, 2021
The original PR elastic#75264 made some test mistakes

NXY Significant term heuristics have additional values that need to be set when testing
basicScore properties.

Additionally, previous refactor kept the abstract test class in a package that other plugins
don't have access to.

closes elastic#75442, elastic#75561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) >test Issues or PRs that are addressing/adding tests v7.15.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants