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

feature: add semantic version types #236

Merged
merged 17 commits into from
Aug 27, 2020
Merged

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented Jul 16, 2020

Summary

  • add greater than or equal and less than or equal for numbers
  • add semantic version match types.

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

first pass.

[Test]
public void TestGEMatcherReturnsFalseWhenAttributeValueIsLessButTrueForEqualToConditionValue()
{
Assert.That(GECondition.Evaluate(null, new UserAttributes { { "distance_ge", 5 } }, Logger), Is.False);
Copy link
Contributor

Choose a reason for hiding this comment

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

use Assert.IsTrue or Assert.IsFalse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Evaluate return bool? and Assert.IsTrue expects bool. That is the reason I used Assert.That

private BaseCondition ExactStrCondition = new BaseCondition { Name = "browser_type", Value = "firefox", Match = "exact", Type = "custom_attribute" };
private BaseCondition ExactBoolCondition = new BaseCondition { Name = "is_registered_user", Value = false, Match = "exact", Type = "custom_attribute" };
private BaseCondition ExactDecimalCondition = new BaseCondition { Name = "pi_value", Value = 3.14, Match = "exact", Type = "custom_attribute" };
private BaseCondition ExactIntCondition = new BaseCondition { Name = "lasers_count", Value = 9000, Match = "exact", Type = "custom_attribute" };
private BaseCondition InfinityIntCondition = new BaseCondition { Name = "max_num_value", Value = 9223372036854775807, Match = "exact", Type = "custom_attribute" };
private BaseCondition SemVerLTCondition = new BaseCondition { Name = "semversion_lt", Value = "3.7.1", Match = "semver_lt", Type = "custom_attribute" };
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please append values, so unit test will have more clarity.

@@ -156,6 +170,35 @@ public class BaseCondition : ICondition
return Convert.ToDouble(attributeValue) > Convert.ToDouble(Value);
}

public bool? GreaterOrEqualThanEvaluator(object attributeValue, ILogger logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Am not in favor of all these evaluator or we should put common logic in a separate method, the only evaluation logic should be kept inside every evaluator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets talk offline. CommonEvaluator should return either 0, 1, -1 or raise exception. We shouldn't parse anything in GE, LE, EQ (SemVer).

@msohailhussain msohailhussain marked this pull request as ready for review August 19, 2020 23:47
@msohailhussain msohailhussain requested a review from a team as a code owner August 19, 2020 23:47
Copy link

@thomaszurkan-optimizely thomaszurkan-optimizely left a comment

Choose a reason for hiding this comment

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

Looks good. Can. we just add a few invalid semver tests mentioned below?

}
// major.minor.patch
var versionPrefix = partialVersionParts[0];
versionSuffix = partialVersionParts[1];

Choose a reason for hiding this comment

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

will this blow up if we have a version mistake like "2.0-"?

Copy link
Contributor

@msohailhussain msohailhussain Aug 24, 2020

Choose a reason for hiding this comment

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

good catch Tom, adding unit tests but it will be caught before this line.

                {
                    // throw error
                    throw new Exception("Invalid Semantic Version.");
                }```


#endregion // LEMatcher Tests

#region SemVerLTMatcher Tests

Choose a reason for hiding this comment

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

Can we add some invalid attribute tests? (i.e. "3.0-", 3.x", 3.2, "3.0.0+", "+")?

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link

@thomaszurkan-optimizely thomaszurkan-optimizely left a comment

Choose a reason for hiding this comment

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

LGTM

@thomaszurkan-optimizely thomaszurkan-optimizely merged commit 7f59df3 into master Aug 27, 2020
@thomaszurkan-optimizely thomaszurkan-optimizely deleted the mnoman/semver branch August 27, 2020 18:03
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.

4 participants