diff options
author | matthewsot <matthewsot@outlook.com> | 2017-06-17 00:19:26 -0700 |
---|---|---|
committer | matthewsot <matthewsot@outlook.com> | 2017-06-17 00:19:26 -0700 |
commit | a5c3b86f7bc2ed42166adb074d357d66d467a6ed (patch) | |
tree | 4c8598b459043299128b2d44dec9f41ceb07a86c | |
parent | 3939729035dbcb863e35cbb14460147cfb9cfa91 (diff) |
-rw-r--r-- | test.html | 49 |
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> |