SHARE
TWEET

Untitled

a guest Jun 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.dkc.pp;
  2.  
  3. import com.dkc.pp.util.Globals;
  4.  
  5. import org.junit.Before;
  6. import org.junit.Test;
  7.  
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. import static org.junit.Assert.assertEquals;
  12.  
  13. public class BooleanPredicateProcessorTest {
  14.  
  15.     private Globals globals = new Globals();
  16.     private Map<String, Integer> variables = new HashMap<>();
  17.  
  18.     @Before
  19.     public void setUp() throws Exception {
  20.         variables.put("friend_count", 100);
  21.         variables.put("a", 60);
  22.         variables.put("b", 60);
  23.         variables.put("c", 60);
  24.         variables.put("d", 60);
  25.     }
  26.  
  27.     @Test
  28.     public void can_process_greater_than_predicate() {
  29.         assertEquals(true, globals.processPredicate("friend_count > 40", variables));
  30.         assertEquals(false, globals.processPredicate("friend_count > 200", variables));
  31.     }
  32.  
  33.     @Test
  34.     public void can_process_greater_than_or_equal_to_predicate() {
  35.         assertEquals(false, globals.processPredicate("friend_count >= 101", variables));
  36.         assertEquals(true, globals.processPredicate("friend_count >= 100", variables));
  37.         assertEquals(true, globals.processPredicate("friend_count >= 99", variables));
  38.     }
  39.  
  40.     @Test
  41.     public void can_process_less_than_predicate() {
  42.         assertEquals(true, globals.processPredicate("friend_count < 120", variables));
  43.         assertEquals(false, globals.processPredicate("friend_count < 80", variables));
  44.     }
  45.  
  46.     @Test
  47.     public void can_process_less_than_or_equal_to_predicate() {
  48.         assertEquals(true, globals.processPredicate("friend_count <= 101", variables));
  49.         assertEquals(true, globals.processPredicate("friend_count <= 100", variables));
  50.         assertEquals(false, globals.processPredicate("friend_count <= 99", variables));
  51.     }
  52.  
  53.     @Test
  54.     public void can_process_equal_to_predicate() {
  55.         assertEquals(false, globals.processPredicate("friend_count == 101", variables));
  56.         assertEquals(true, globals.processPredicate("friend_count == 100", variables));
  57.         assertEquals(false, globals.processPredicate("friend_count == 99", variables));
  58.     }
  59.  
  60.     @Test
  61.     public void can_process_predicate_with_arithmetic() {
  62.         assertEquals(true, globals.processPredicate("a + b + c + d > 200", variables));
  63.         assertEquals(false, globals.processPredicate("a + b + c + d > 900", variables));
  64.     }
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top