feat (audience match types): Update condition evaluator for new audience match types.#55
Conversation
Pull Request Test Coverage Report for Build 539
💛 - Coveralls |
oakbani
left a comment
There was a problem hiding this comment.
Minor feedback. Nice work.
| # limitations under the License. | ||
| # | ||
| module Optimizely | ||
| class ConditionTreeEvaluator |
There was a problem hiding this comment.
Let's make this a module as it doesn't have state and it's methods can be directly namespaced without creating an object.
| class ConditionTreeEvaluator | ||
| CUSTOM_ATTRIBUTE_CONDITION_TYPE = 'custom_attribute' | ||
|
|
||
| # Default operator types |
|
|
||
| if conditions.is_a? Array | ||
| # Operator to apply is not explicit - assume 'or' | ||
| first_operator = EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0]) ? conditions[0] : OR_CONDITION |
There was a problem hiding this comment.
Can we group both under a single check of EVALUATORS_BY_OPERATOR_TYPE.include?(conditions[0])
| # | ||
| module Optimizely | ||
| class ConditionTreeEvaluator | ||
| CUSTOM_ATTRIBUTE_CONDITION_TYPE = 'custom_attribute' |
There was a problem hiding this comment.
nit. is this used within this module?
|
|
||
| condition_match = leaf_condition['match'] | ||
|
|
||
| return nil if !condition_match.nil? && !EVALUATORS_BY_MATCH_TYPE.include?(condition_match) |
There was a problem hiding this comment.
You can avoid checking !condition_match.nil? is you keep the below condition_match = EXACT_MATCH_TYPE if condition_match.nil? before this
| end | ||
|
|
||
| it 'should return nil if there is no user-provided value' do | ||
| condition_evaluator = Optimizely::CustomAttributeConditionEvaluator.new('sum' => {}) |
There was a problem hiding this comment.
same. Do not provide anything is attributes. Do this for all others
| end | ||
| end | ||
|
|
||
| describe 'with a number condition value' do |
There was a problem hiding this comment.
Add all the testcases for float as well where the exact_number_conditions has a float value.
| end | ||
|
|
||
| it 'should return false if the user-provided value is not greater than the condition value' do | ||
| condition_evaluator = Optimizely::CustomAttributeConditionEvaluator.new('input_value' => 8) |
| end | ||
|
|
||
| it 'should return nil if user-provided value is greater than specified limit' do | ||
| condition_evaluator = Optimizely::CustomAttributeConditionEvaluator.new('input_value' => 2.0e+53) |
There was a problem hiding this comment.
Let's put this testcase in validator.
|
|
||
| describe 'less than match type' do | ||
| before(:context) do | ||
| @lt_conditions = {'match' => 'lt', 'name' => 'input_value', 'type' => 'custom_attribute', 'value' => 10} |
There was a problem hiding this comment.
Both for gt and lt add same testcases where condition value is a float. See Python PR optimizely#146
Summary
This adds support for new audience match type conditions to the condition evaluator:
exact, exists, gt, lt, and substring conditions
Abort and return null when appropriate in leaf evaluators
Null handling in and/or/not evaluators
Assume implicit "or" when operator is missing