Random extends java.util.Random { public int guess(String str) { Matcher mat = guessPattern.matcher(str); int ret = 0; if (mat.matches()) { String num1 = mat.group(1); String wmode = mat.group(2); String wnum = mat.group(3); String mode = mat.group(4); String num2 = mat.group(5); String pmode = mat.group(6); String pnum = mat.group(7); int a, b, w, p; a = num1 == null ? 0 : Integer.parseInt(num1); b = num2 == null ? 0 : Integer.parseInt(num2); w = wnum == null ? 0 : Integer.parseInt(wnum); p = pnum == null ? 0 : Integer.parseInt(pnum); if (num1 != null && num2 != null) { if (wnum != null) { if (":".equals(wmode)) { if ("d".equals(mode)) { ret = bestOf(a, w, b); } } } else if ("d".equals(mode)) { ret = dice(a, b); } else if (":".equals(mode)) { ret = nextInt(a, b+1); } } else if (num1 != null) { if (":".equals(wmode)) { ret = nextInt(a, w+1); } else { ret = a; } } else if (num2 != null) { if (mode != null) { switch (mode) { case "d": ret = dice(1, b); break; case ":": ret = nextInt(0, b+1); break; } } } else { if (":".equals(wmode)) { ret = nextInt(0, w+1); } } if (pmode != null) { switch (pmode) { case "+": ret += p; break; case "-": ret -= p; break; case "*": ret *= p; break; case "/": ret /= p; break; } } } return ret; } Random();  Random(long arg0); static Random getInstance(); int bestOf(int num, int outof, int sides); int bestOf(int num, List<Integer> group); int bestOf(int num, int outof, String g); T choice(T c0, T... c); T choice(List<T> c); T choice(Collection<T> c); int dice(int num, int sides); List<Integer> diceList(int num, int sides); int guess(String str); int nextInt(int bottom, int top); void shuffle(List<T> list);  }
@Test public void testGuessEmpty() { int got; got = r.guess(""); assertEquals(0, got); }
@Test public void testPlus() { int got = r.guess("+2"); assertEquals(2, got); }
@Test public void testDiv() { int got = r.guess("8/4"); assertEquals(2, got); }
@Test public void testMul() { int got = r.guess("2*2"); assertEquals(4, got); }
@Test public void testSub() { int got = r.guess("6-2"); assertEquals(4, got); }
@Test public void testAdd() { int got = r.guess("2+2"); assertEquals(4, got); }
@Test public void testBestOfDice() { int got = r.guess("3:4d6"); assertEquals(18, got); }
@Test public void testBestOfDiceMul() { int got = r.guess("3:4d6*50"); assertEquals(900, got); }