1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Factorial.java Thu Dec 19 17:11:01 2013 +0100
1.3 @@ -0,0 +1,40 @@
1.4 +/**
1.5 + * HTML via Java(tm) Language Bindings Copyright (C) 2013 Jaroslav Tulach
1.6 + * <jaroslav.tulach@apidesign.org>
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify it under
1.9 + * the terms of the GNU General Public License as published by the Free Software
1.10 + * Foundation, version 2 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.15 + * details. apidesign.org designates this particular file as subject to the
1.16 + * "Classpath" exception as provided by apidesign.org in the License file that
1.17 + * accompanied this code.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License along with
1.20 + * this program. Look for COPYING file in the top folder. If not, see
1.21 + * http://wiki.apidesign.org/wiki/GPLwithClassPathException
1.22 + */
1.23 +
1.24 +package net.java.html.js.tests;
1.25 +
1.26 +import net.java.html.js.JavaScriptBody;
1.27 +
1.28 +/**
1.29 + *
1.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.31 + */
1.32 +public final class Factorial {
1.33 + int minusOne(int i) {
1.34 + return i - 1;
1.35 + }
1.36 +
1.37 + @JavaScriptBody(args = { "i" }, javacall = true,body =
1.38 + "if (i <= 1) return 1;\n"
1.39 + + "var im1 = this.@net.java.html.js.tests.Factorial::minusOne(I)(i);\n"
1.40 + + "return this.@net.java.html.js.tests.Factorial::factorial(I)(im1) * i;"
1.41 + )
1.42 + native int factorial(int n);
1.43 +}
2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Thu Dec 19 09:15:41 2013 +0100
2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Thu Dec 19 17:11:01 2013 +0100
2.3 @@ -137,6 +137,27 @@
2.4 @KOTest public void truth() {
2.5 assert Bodies.truth() : "True is true";
2.6 }
2.7 +
2.8 + @KOTest public void factorial2() {
2.9 + assert new Factorial().factorial(2) == 2;
2.10 + }
2.11 +
2.12 + @KOTest public void factorial3() {
2.13 + assert new Factorial().factorial(3) == 6;
2.14 + }
2.15 +
2.16 + @KOTest public void factorial4() {
2.17 + assert new Factorial().factorial(4) == 24;
2.18 + }
2.19 +
2.20 + @KOTest public void factorial5() {
2.21 + assert new Factorial().factorial(5) == 120;
2.22 + }
2.23 +
2.24 + @KOTest public void factorial6() {
2.25 + assert new Factorial().factorial(6) == 720;
2.26 + }
2.27 +
2.28 private static class R implements Runnable {
2.29 int cnt;
2.30 private final Thread initThread;