package io.featureflow.client;

import com.google.gson.JsonPrimitive;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by oliver on 21/11/16.
 */
public class RuleMatchesTest {

    @Test
    public void testRuleEquals() throws Exception {

        Rule rule = new Rule();

        Condition c1 = new Condition();
        c1.target = "name";
        c1.operator = Operator.equals;
        c1.values.get(0) = new JsonPrimitive("oliver");

        Audience a = new Audience();
        a.conditions = Arrays.asList(c1);
        rule.setAudience(a);

        FeatureFlowContext context = new FeatureFlowContext("oliver");
        Map<String, JsonPrimitive> contextValues = new HashMap<>();
        contextValues.put("name", new JsonPrimitive("oliver"));
        context.values = contextValues;

        Assert.assertTrue(rule.matches(context));

    }

    @Test
    public void testRuleGreaterThan() throws Exception {

        Rule rule = new Rule();

        Condition c1 = new Condition();
        c1.target = "age";
        c1.operator = Operator.greaterThan;
        c1.values.get(0)= new JsonPrimitive(25l);

        Audience a = new Audience();
        a.conditions = Arrays.asList(c1);
        rule.setAudience(a);

        FeatureFlowContext context = new FeatureFlowContext("oliver");
        Map<String, JsonPrimitive> contextValues = new HashMap<>();
        contextValues.put("name", new JsonPrimitive("oliver"));
        contextValues.put("age", new JsonPrimitive(26l));

        context.values = contextValues;

        Assert.assertTrue(rule.matches(context));

    }


}
@@ -485,17 +485,12 @@
 ues.
-get(0) = 
+add(
 new 
@@ -512,16 +512,17 @@
 oliver%22)
+)
 ;%0A%0A     
@@ -986,33 +986,32 @@
 ows Exception %7B%0A
-%0A
         Rule rul
@@ -1018,33 +1018,32 @@
 e = new Rule();%0A
-%0A
         Conditio
@@ -1159,16 +1159,12 @@
 ues.
-get(0)= 
+add(
 new 
@@ -1181,16 +1181,17 @@
 ive(25l)
+)
 ;%0A%0A     

Update condition values to array