use of org.nutz.lang.util.Context in project nutz by nutzam.
the class SimpleSpeedTest method test_speed.
@Ignore
@Test
public void test_speed() throws SecurityException, NoSuchMethodException {
final SimpleSpeedTest z = new SimpleSpeedTest();
final String elstr = "num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7)-z.abc(i)";
final Context context = Lang.context("{num:0}");
context.set("z", z);
System.out.println("\n" + Strings.dup('=', 100));
Stopwatch sw = Stopwatch.run(new Atom() {
public void run() {
int num = 0;
for (int i = 0; i < max; i++) num = num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7) - z.abc(i);
//System.out.println("Num: " + num);
}
});
System.out.println("\n" + Strings.dup('=', 100));
Stopwatch sw3 = Stopwatch.run(new Atom() {
public void run() {
try {
context.set("num", 0);
for (int i = 0; i < max; i++) context.set("num", El.eval(context.set("i", i), elstr));
//System.out.println("Num: " + context.getInt("num"));
} catch (Exception e) {
throw Lang.wrapThrow(e);
}
}
});
System.out.println("\n" + Strings.dup('=', 100));
Stopwatch sw4 = Stopwatch.run(new Atom() {
public void run() {
try {
El el2pre = new El(elstr);
context.set("num", 0);
context.set("z", z);
for (int i = 0; i < max; i++) context.set("num", el2pre.eval(context.set("i", i)));
//System.out.println("Num: " + context.getInt("num"));
} catch (Exception e) {
throw Lang.wrapThrow(e);
}
}
});
System.out.println("\n" + Strings.dup('=', 100));
Stopwatch sw5 = Stopwatch.run(new Atom() {
public void run() {
try {
El el2pre = new El(elstr);
context.set("num", 0);
context.set("z", z);
for (int i = 0; i < max; i++) context.set("num", el2pre.eval(context.set("i", i)));
//System.out.println("Num: " + context.getInt("num"));
} catch (Exception e) {
throw Lang.wrapThrow(e);
}
}
});
System.out.println("\n" + Strings.dup('=', 100));
System.out.printf("\n%20s : %s", "Invoke", sw.toString());
System.out.printf("\n%20s : %s", "Reflect", sw3.toString());
System.out.printf("\n%20s : %s", "Reflect", sw4.toString());
System.out.printf("\n%20s : %s", "Reflect", sw5.toString());
System.out.println();
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method testIssue292.
@Test
public void testIssue292() {
Context context = Lang.context();
context.set("a", 123);
context.set("b", 20);
Object o = El.eval(context, "a>b?a:b");
assertEquals(123, o);
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method testIssue293.
@Test
public void testIssue293() {
Context context = Lang.context();
context.set("static", new Issue293());
context.set("a", Issue293.class);
assertEquals("xxx", El.eval(context, "a.printParam(a.info)"));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method complexOperation.
@SuppressWarnings("unused")
@Test
public void complexOperation() {
assertEquals(1000 + 100.0 * 99 - (600 - 3 * 15) % (((68 - 9) - 3) * 2 - 100) + 10000 % 7 * 71, El.eval("1000+100.0*99-(600-3*15)%(((68-9)-3)*2-100)+10000%7*71"));
assertEquals(6.7 - 100 > 39.6 ? true ? 4 + 5 : 6 - 1 : !(100 % 3 - 39.0 < 27) ? 8 * 2 - 199 : 100 % 3, El.eval("6.7-100>39.6 ? 5==5? 4+5:6-1 : !(100%3-39.0<27) ? 8*2-199: 100%3"));
Context vars = Lang.context();
vars.set("i", 100);
vars.set("pi", 3.14f);
vars.set("d", -3.9);
vars.set("b", (byte) 4);
vars.set("bool", false);
vars.set("t", "");
String t = "i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99 ==i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99";
// t =
// "i * pi + (d * b - 199) / (1 - d * pi) - (2 + 100 - i / pi) % 99";
assertEquals(true, El.eval(vars, t));
// assertEquals('A' == ('A') || 'B' == 'B' && "ABCD" == "" && 'A' ==
// 'A', el.eval(vars,
// "'A' == 'A' || 'B' == 'B' && 'ABCD' == t && 'A' == 'A'"));
assertEquals(true || true && false && true, El.eval(vars, "'A' == 'A' || 'B' == 'B' && 'ABCD' == t && 'A' == 'A'"));
}
use of org.nutz.lang.util.Context in project nutz by nutzam.
the class El2Test method field.
/**
* 属性测试
*/
@Test
public void field() {
class abc {
@SuppressWarnings("unused")
public String name = "jk";
}
Context context = Lang.context();
context.set("a", new abc());
assertEquals("jk", El.eval(context, "a.name"));
// 这个功能放弃
// assertFalse((Boolean)El.eval("java.lang.Boolean.FALSE"));
// assertFalse((Boolean)El.eval("Boolean.FALSE"));
}
Aggregations