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

Range Rule Implementation #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jetfreakk
Copy link
Contributor

Description

This change introduces RANGE_RULE based on discussion #10

Related Issue

#10

Motivation and Context

The RangeRule class will be specifically designed for validating whether a given fact falls within a specified numeric range with different inclusivity options. It's well-suited for scenarios where we have predefined expectations about the valid range of values for a particular fact.

How Has This Been Tested?

Custom Implementation for use case

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

if (step != null && min instanceof Number && max instanceof Number && step instanceof Number) {
double minVal = ((Number) min).doubleValue();
double maxVal = ((Number) max).doubleValue();
double stepVal = ((Number) step).doubleValue();
Copy link
Member

Choose a reason for hiding this comment

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

The type should be on the class: RangeRule, so there should be no need for this.


private Result evaluateIn(T fact) {
if (step == null) {
return evaluateBetween(fact);
Copy link
Member

Choose a reason for hiding this comment

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

Are you assumign that step=1 in this case? Have you considered failing if step is not specified in IN operation?

if (fact instanceof Number && step instanceof Number) {
double value = ((Number) fact).doubleValue();
double minVal = ((Number) min).doubleValue();
double stepVal = ((Number) step).doubleValue();
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I understand the step. Could we remove this for this initial iteration please?

}

private Result evaluateIsBefore(T fact) {
int compareMin = fact.compareTo(min);
Copy link
Member

Choose a reason for hiding this comment

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

Should consider the exclusive param for min here.

Copy link
Member

Choose a reason for hiding this comment

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

This comment is still valid.

@jetfreakk
Copy link
Contributor Author

Hi @sic2 , Thanks for the review and the comments. I have addressed the same. Please do have a look.

}

private Result evaluateIsBefore(T fact) {
int compareMin = fact.compareTo(min);
Copy link
Member

Choose a reason for hiding this comment

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

This comment is still valid.

", ignore=" + isIgnore() +
"}";
}
}
Copy link
Member

Choose a reason for hiding this comment

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

New line at end of file missing

DIVISIBLE_BY,
BETWEEN,
IS_BEFORE,
IS_AFTER

// Operators not supported yet
// BETWEEN,
Copy link
Member

Choose a reason for hiding this comment

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

Remove this

* @param <T> type of the fact (must extend Comparable)
*/
@Experimental
public class RangeRule<T extends Comparable<T>> extends OperatorBasedRule {
Copy link
Member

Choose a reason for hiding this comment

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

No need for an update to the README as this is experimental for now, but do have unit tests please.

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.

2 participants