summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsot <matthewsot@outlook.com>2017-06-17 00:19:26 -0700
committermatthewsot <matthewsot@outlook.com>2017-06-17 00:19:26 -0700
commita5c3b86f7bc2ed42166adb074d357d66d467a6ed (patch)
tree4c8598b459043299128b2d44dec9f41ceb07a86c
parent3939729035dbcb863e35cbb14460147cfb9cfa91 (diff)
added a tests pageHEADmaster
-rw-r--r--test.html49
1 files changed, 49 insertions, 0 deletions
diff --git a/test.html b/test.html
new file mode 100644
index 0000000..00bc805
--- /dev/null
+++ b/test.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>jfn Tests</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <h1 id="status"></h1>
+ <script type="text/javascript" src="jfn.js"></script>
+ <script type="text/javascript">
+ var good = true;
+ function assert(res, msg) {
+ console.log(res);
+ if (res) return;
+ document.getElementById("status").innerHTML += "<br/>";
+ document.getElementById("status").textContent += msg;
+ good = false;
+ }
+
+ jfn.defineFunction("testFunction", ["string"], function (str) {
+ return "String: " + str;
+ });
+
+ jfn.defineFunction("testFunction", ["number"], function (num) {
+ return "Num: " + num;
+ });
+
+ jfn.defineFunction("testFunction", "*", function (data) {
+ return "Catchall: " + JSON.stringify(data);
+ });
+
+ assert(testFunction("Hello!") === "String: Hello!", "String overloading failed.");
+ assert(testFunction(1) === "Num: 1", "Number overloading failed.");
+ assert(testFunction({ "property": "value" }) === "Catchall: " + JSON.stringify({ "property": "value" }), "Catchall failed.");
+
+ // Returns the root of a number, defaulting to the square root
+ jfn.defineFunction(Math, "root", ["number", "number"], [2], function (base, power) {
+ return Math.pow(base, (1 / power));
+ });
+
+ assert(Math.root(8, 3) == 2, "Supplying defaulted values failed.")
+ assert(Math.root(9) == 3, "Default value failed.")
+
+ if (good) {
+ document.getElementById("status").textContent = "All tests passed!";
+ }
+ </script>
+ </body>
+</html>
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback