### Question:
RateLimiterUtils extends CounterAbstractPolicy { public Boolean getFinalresult(String val) throws Exception { List<String> expression = simplifyExpression(val, new LinkedList<String>()); int cnt = 0; Boolean lastoutput = null; String lastlogicalOperation = null; for (String a : expression) { if (a != null) { a = a.trim(); if ("true".equalsIgnoreCase(a)) { if (cnt == 0) { lastoutput = true; cnt++; continue; } else { lastoutput = proccesOperation(lastoutput, true, lastlogicalOperation); lastlogicalOperation = null; } } else if ("false".equalsIgnoreCase(a)) { if (cnt == 0) { lastoutput = false; cnt++; continue; } else { lastoutput = proccesOperation(lastoutput, false, lastlogicalOperation); lastlogicalOperation = null; } } else if (("||").equalsIgnoreCase(a)) { if (cnt == 0) { System.out .println("error expression cannot start with ||"); break; } else { if (lastlogicalOperation == null) { lastlogicalOperation = "||"; } else { System.out.println("Invalid exprestion " + expression); } } } else if (("&&").equalsIgnoreCase(a)) { if (cnt == 0) { System.out .println("error expression can not start with &&"); break; } else { if (lastlogicalOperation == null) { lastlogicalOperation = "&&"; } else { System.out.println("Invalid exprestion " + expression); } } } } cnt++; } return lastoutput; } RateLimiterUtils(final String ipOrSubjectGroup, final boolean sg); Boolean getFinalresult(String val);  }### Answer:
@Test public void testsimpleExp() throws Exception { Boolean flag; flag = limiterUtils.getFinalresult("1>2"); assertEquals("\"1>2\" should be false", false, flag); flag = limiterUtils.getFinalresult(" 1 > 3 "); assertEquals("\" 1 > 3 \" should be false", false, flag); flag = limiterUtils.getFinalresult("4 > 2"); assertEquals("\"4 > 2\" should be true", true, flag); flag = limiterUtils.getFinalresult("1>1"); assertEquals("\"1>1 \" should be false", false, flag); }
@Test public void testOrExp() throws Exception { Boolean flag; flag = limiterUtils.getFinalresult("1>2||3>6"); assertEquals("\"1>2||3>6\" should be false", false, flag); flag = limiterUtils.getFinalresult(" 1 > 3 || 4 > 6 || 5 >7 "); assertEquals("\" 1 > 3 || 4 > 6 || 5 >7 \" should be false", false, flag); flag = limiterUtils.getFinalresult("1 > 3 || 4 > 6 || 4 > 2"); assertEquals("\"1 > 3 || 4 > 6 || 4 > 2\" should be true", true, flag); flag = limiterUtils.getFinalresult("1>1 || 2>10 || 3>5"); assertEquals("\"1>1 || 2>10 || 3>5 \" should be false", false, flag); }
@Test public void testAndExp() throws Exception { Boolean flag; flag = limiterUtils.getFinalresult("1>2&&3>6"); assertEquals("\"1>2||3>6\" should be false", false, flag); flag = limiterUtils.getFinalresult(" 1 > 3 && 4 > 6 && 5 >7 "); assertEquals("\" 1 > 3 || 4 > 6 || 5 >7 \" should be false", false, flag); flag = limiterUtils.getFinalresult("1 < 3 && 4 < 6 && 4 > 2"); assertEquals("\"1 < 3 && 4 < 6 && 4 > 2\" should be true", true, flag); }
@Test public void testIvalidExpression() { try { limiterUtils.getFinalresult("1>>2"); fail("invalid expression should fail"); } catch (Exception e) { } try { limiterUtils.getFinalresult("1>>2 2"); fail("invalid expression should fail"); } catch (Exception e) { } try { limiterUtils.getFinalresult("1>>2 && 2 >1"); fail("invalid expression should fail"); } catch (Exception e) { } }