|
1 | 1 | /**
|
2 | 2 | *
|
3 |
| - * Copyright 2016-2017, Optimizely and contributors |
| 3 | + * Copyright 2016-2018, Optimizely and contributors |
4 | 4 | *
|
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import org.junit.Before;
|
21 | 21 | import org.junit.Test;
|
22 | 22 |
|
| 23 | +import java.math.BigInteger; |
23 | 24 | import java.util.ArrayList;
|
24 | 25 | import java.util.Collections;
|
25 | 26 | import java.util.HashMap;
|
@@ -172,6 +173,27 @@ public void exactMatchConditionEvaluatesTrue() throws Exception {
|
172 | 173 | assertTrue(testInstanceDouble.evaluate(testTypedUserAttributes));
|
173 | 174 | }
|
174 | 175 |
|
| 176 | + |
| 177 | + /** |
| 178 | + * Verify that UserAttribute.evaluate for EXACT match type returns null if the UserAttribute's |
| 179 | + * value type is invalid number. |
| 180 | + */ |
| 181 | + @Test |
| 182 | + public void invalidExactMatchConditionEvaluatesNull() throws Exception { |
| 183 | + BigInteger bigInteger = new BigInteger("33221312312312312"); |
| 184 | + Double infinitePositiveInfiniteDouble = Double.POSITIVE_INFINITY; |
| 185 | + Double infiniteNegativeInfiniteDouble = Double.NEGATIVE_INFINITY; |
| 186 | + Double infiniteNANDouble = Double.NaN; |
| 187 | + UserAttribute testInstanceInteger = new UserAttribute("num_size", "custom_attribute","exact", bigInteger); |
| 188 | + UserAttribute testInstancePositiveInfinite = new UserAttribute("num_counts", "custom_attribute","exact", infinitePositiveInfiniteDouble); |
| 189 | + UserAttribute testInstanceNegativeInfiniteDouble = new UserAttribute("num_counts", "custom_attribute","exact", infiniteNegativeInfiniteDouble); |
| 190 | + UserAttribute testInstanceNANDouble = new UserAttribute("num_counts", "custom_attribute","exact", infiniteNANDouble); |
| 191 | + |
| 192 | + assertNull(testInstanceInteger.evaluate(testTypedUserAttributes)); |
| 193 | + assertNull(testInstancePositiveInfinite.evaluate(testTypedUserAttributes)); |
| 194 | + assertNull(testInstanceNegativeInfiniteDouble.evaluate(testTypedUserAttributes)); |
| 195 | + assertNull(testInstanceNANDouble.evaluate(testTypedUserAttributes)); |
| 196 | + } |
175 | 197 | /**
|
176 | 198 | * Verify that UserAttribute.evaluate for EXACT match type returns false for known visitor
|
177 | 199 | * attributes where the value's type are the same, but the values are different
|
@@ -228,6 +250,27 @@ public void gtMatchConditionEvaluatesTrue() throws Exception {
|
228 | 250 | assertNull(testInstanceInteger.evaluate(badAttributes));
|
229 | 251 | }
|
230 | 252 |
|
| 253 | + /** |
| 254 | + * Verify that UserAttribute.evaluate for GT match type returns null if the UserAttribute's |
| 255 | + * value type is invalid number. |
| 256 | + */ |
| 257 | + @Test |
| 258 | + public void gtMatchConditionEvaluatesNullWithInvalidAttr() throws Exception { |
| 259 | + BigInteger bigInteger = new BigInteger("33221312312312312"); |
| 260 | + Double infinitePositiveInfiniteDouble = Double.POSITIVE_INFINITY; |
| 261 | + Double infiniteNegativeInfiniteDouble = Double.NEGATIVE_INFINITY; |
| 262 | + Double infiniteNANDouble = Double.NaN; |
| 263 | + UserAttribute testInstanceInteger = new UserAttribute("num_size", "custom_attribute","gt", bigInteger); |
| 264 | + UserAttribute testInstancePositiveInfinite = new UserAttribute("num_counts", "custom_attribute","gt", infinitePositiveInfiniteDouble); |
| 265 | + UserAttribute testInstanceNegativeInfiniteDouble = new UserAttribute("num_counts", "custom_attribute","gt", infiniteNegativeInfiniteDouble); |
| 266 | + UserAttribute testInstanceNANDouble = new UserAttribute("num_counts", "custom_attribute","gt", infiniteNANDouble); |
| 267 | + |
| 268 | + assertNull(testInstanceInteger.evaluate(testTypedUserAttributes)); |
| 269 | + assertNull(testInstancePositiveInfinite.evaluate(testTypedUserAttributes)); |
| 270 | + assertNull(testInstanceNegativeInfiniteDouble.evaluate(testTypedUserAttributes)); |
| 271 | + assertNull(testInstanceNANDouble.evaluate(testTypedUserAttributes)); |
| 272 | + } |
| 273 | + |
231 | 274 | /**
|
232 | 275 | * Verify that UserAttribute.evaluate for GT match type returns false for known visitor
|
233 | 276 | * attributes where the value's type is a number, and the UserAttribute's value is not greater
|
@@ -304,6 +347,27 @@ public void ltMatchConditionEvaluatesNull() throws Exception {
|
304 | 347 | assertNull(testInstanceNull.evaluate(testTypedUserAttributes));
|
305 | 348 | }
|
306 | 349 |
|
| 350 | + /** |
| 351 | + * Verify that UserAttribute.evaluate for LT match type returns null if the UserAttribute's |
| 352 | + * value type is not a number. |
| 353 | + */ |
| 354 | + @Test |
| 355 | + public void ltMatchConditionEvaluatesNullWithInvalidAttributes() { |
| 356 | + BigInteger bigInteger = new BigInteger("33221312312312312"); |
| 357 | + Double infinitePositiveInfiniteDouble = Double.POSITIVE_INFINITY; |
| 358 | + Double infiniteNegativeInfiniteDouble = Double.NEGATIVE_INFINITY; |
| 359 | + Double infiniteNANDouble = Double.NaN; |
| 360 | + UserAttribute testInstanceInteger = new UserAttribute("num_size", "custom_attribute","lt", bigInteger); |
| 361 | + UserAttribute testInstancePositiveInfinite = new UserAttribute("num_counts", "custom_attribute","lt", infinitePositiveInfiniteDouble); |
| 362 | + UserAttribute testInstanceNegativeInfiniteDouble = new UserAttribute("num_counts", "custom_attribute","lt", infiniteNegativeInfiniteDouble); |
| 363 | + UserAttribute testInstanceNANDouble = new UserAttribute("num_counts", "custom_attribute","lt", infiniteNANDouble); |
| 364 | + |
| 365 | + assertNull(testInstanceInteger.evaluate(testTypedUserAttributes)); |
| 366 | + assertNull(testInstancePositiveInfinite.evaluate(testTypedUserAttributes)); |
| 367 | + assertNull(testInstanceNegativeInfiniteDouble.evaluate(testTypedUserAttributes)); |
| 368 | + assertNull(testInstanceNANDouble.evaluate(testTypedUserAttributes)); |
| 369 | + } |
| 370 | + |
307 | 371 | /**
|
308 | 372 | * Verify that UserAttribute.evaluate for SUBSTRING match type returns true if the
|
309 | 373 | * UserAttribute's value is a substring of the condition's value.
|
|
0 commit comments