Created
June 13, 2019 16:28
-
-
Save BallerIndustries/a147e4b42c0bf1b4f23cbc626a08eff0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dkc.pp; | |
import com.dkc.pp.util.Globals; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.HashMap; | |
import java.util.Map; | |
import static org.junit.Assert.assertEquals; | |
public class BooleanPredicateProcessorTest { | |
private Globals globals = new Globals(); | |
private Map<String, Integer> variables = new HashMap<>(); | |
@Before | |
public void setUp() throws Exception { | |
variables.put("friend_count", 100); | |
variables.put("a", 60); | |
variables.put("b", 60); | |
variables.put("c", 60); | |
variables.put("d", 60); | |
} | |
@Test | |
public void can_process_greater_than_predicate() { | |
assertEquals(true, globals.processPredicate("friend_count > 40", variables)); | |
assertEquals(false, globals.processPredicate("friend_count > 200", variables)); | |
} | |
@Test | |
public void can_process_greater_than_or_equal_to_predicate() { | |
assertEquals(false, globals.processPredicate("friend_count >= 101", variables)); | |
assertEquals(true, globals.processPredicate("friend_count >= 100", variables)); | |
assertEquals(true, globals.processPredicate("friend_count >= 99", variables)); | |
} | |
@Test | |
public void can_process_less_than_predicate() { | |
assertEquals(true, globals.processPredicate("friend_count < 120", variables)); | |
assertEquals(false, globals.processPredicate("friend_count < 80", variables)); | |
} | |
@Test | |
public void can_process_less_than_or_equal_to_predicate() { | |
assertEquals(true, globals.processPredicate("friend_count <= 101", variables)); | |
assertEquals(true, globals.processPredicate("friend_count <= 100", variables)); | |
assertEquals(false, globals.processPredicate("friend_count <= 99", variables)); | |
} | |
@Test | |
public void can_process_equal_to_predicate() { | |
assertEquals(false, globals.processPredicate("friend_count == 101", variables)); | |
assertEquals(true, globals.processPredicate("friend_count == 100", variables)); | |
assertEquals(false, globals.processPredicate("friend_count == 99", variables)); | |
} | |
@Test | |
public void can_process_predicate_with_arithmetic() { | |
assertEquals(true, globals.processPredicate("a + b + c + d > 200", variables)); | |
assertEquals(false, globals.processPredicate("a + b + c + d > 900", variables)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment