Пример #1
0
 /** Convert specific starting hand to HoldemAtomicGroup object.
     @param groupSpec starting hand (e.g., AhKd, 8h3s)
 */
 public HoldemAtomicGroup(String groupSpec) {
   myspec = groupSpec;
   myhands = new HashSet();
   Perl5Compiler compiler = new Perl5Compiler();
   Perl5Matcher matcher = new Perl5Matcher();
   Pattern atomicPattern;
   try {
     atomicPattern = compiler.compile
       ("^([AKQJT98765432])([shdc])([AKQJT98765432])([shdc])$");
   } catch (MalformedPatternException e) {
     throw new RuntimeException("BUG: " + e.toString());
   }
   MatchResult result;
   if (matcher.matches(groupSpec, atomicPattern)) {
     result = matcher.getMatch();
     int rank1 = Deck.parseRank(result.group(1));
     int suit1 = Deck.parseSuit(result.group(2));
     int rank2 = Deck.parseRank(result.group(3));
     int suit2 = Deck.parseSuit(result.group(4));
     addAtomic(rank1, suit1, rank2, suit2);
   } else {
     throw new IllegalArgumentException("unable to parse groupSpec: " +
                                        groupSpec);
   }
 }
Пример #2
0
  @Override
  public Object visit(StringBinaryComparison n, Void arg) {
    String first = (String) n.getLeftOperand().accept(this, null);
    String second = (String) n.getRightOperand().accept(this, null);

    Operator op = n.getOperator();
    switch (op) {
      case EQUALSIGNORECASE:
        return first.equalsIgnoreCase(second) ? TRUE_VALUE : FALSE_VALUE;
      case EQUALS:
        return first.equals(second) ? TRUE_VALUE : FALSE_VALUE;
      case ENDSWITH:
        return first.endsWith(second) ? TRUE_VALUE : FALSE_VALUE;
      case CONTAINS:
        return first.contains(second) ? TRUE_VALUE : FALSE_VALUE;
      case PATTERNMATCHES:
        return second.matches(first) ? TRUE_VALUE : FALSE_VALUE;
      case APACHE_ORO_PATTERN_MATCHES:
        {
          Perl5Matcher matcher = new Perl5Matcher();
          Perl5Compiler compiler = new Perl5Compiler();
          Pattern pattern;
          try {
            pattern = compiler.compile(first);
          } catch (MalformedPatternException e) {
            throw new RuntimeException(e);
          }
          return matcher.matches(second, pattern) ? TRUE_VALUE : FALSE_VALUE;
        }
      default:
        log.warn("StringComparison: unimplemented operator!" + op);
        return null;
    }
  }
Пример #3
0
 /**
  * Make sure the response satisfies the specified assertion requirements.
  *
  * @param response an instance of SampleResult
  * @return an instance of AssertionResult
  */
 private AssertionResult evaluateResponse(SampleResult response) {
   boolean pass = true;
   boolean not = (NOT & getTestType()) > 0;
   AssertionResult result = new AssertionResult();
   if (response.getResponseData() == null) {
     return setResultForNull(result);
   }
   String responseString = new String(response.getResponseData());
   try {
     // Get the Matcher for this thread
     Perl5Matcher localMatcher = (Perl5Matcher) matcher.get();
     PropertyIterator iter = getTestStrings().iterator();
     while (iter.hasNext()) {
       String stringPattern = iter.next().getStringValue();
       Pattern pattern = patternCache.getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
       boolean found;
       if ((CONTAINS & getTestType()) > 0) {
         found = localMatcher.contains(responseString, pattern);
       } else {
         found = localMatcher.matches(responseString, pattern);
       }
       pass = not ? !found : found;
       if (!pass) {
         result.setFailure(true);
         result.setFailureMessage(
             "Test Failed, expected " + notMessage + failMessage + stringPattern);
         break;
       }
     }
     if (pass) {
       result.setFailure(false);
     }
     result.setError(false);
   } catch (MalformedCachePatternException e) {
     result.setError(true);
     result.setFailure(false);
     result.setFailureMessage("Bad test configuration" + e);
   }
   return result;
 }
Пример #4
0
 public static boolean isMatches(String strQuery, String strPattern) {
   return matcher.matches(strQuery, PatternUtils.getPattern(strPattern));
 }