예제 #1
0
 @Test(timeout = 10000)
 public void testRand() {
   Math.rand a = new Math.rand();
   for (int i = 0; i < 1000; i++) {
     long j = Static.getInt(a.exec(Target.UNKNOWN, env, C.onstruct(10)));
     if (!(j < 10 && j >= 0)) {
       fail("Expected a number between 0 and 10, but got " + j);
     }
     j = Static.getInt(a.exec(Target.UNKNOWN, env, C.onstruct(10), C.onstruct(20)));
     if (!(j < 20 && j >= 10)) {
       fail("Expected a number between 10 and 20, but got " + j);
     }
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(20), C.onstruct(10));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(-1));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(87357983597853791L));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
 }
예제 #2
0
 @Test(timeout = 10000)
 public void testSqrt() throws ConfigCompileException {
   assertEquals("3", StaticTest.SRun("sqrt(9)", fakePlayer));
   assertEquals(
       "Test failed",
       java.lang.Math.sqrt(2),
       Double.parseDouble(StaticTest.SRun("sqrt(2)", fakePlayer)),
       .000001);
   try {
     StaticTest.SRun("sqrt(-1)", fakePlayer);
     fail("Did not expect to pass");
   } catch (ConfigRuntimeException e) {
     // pass
   }
 }