summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/exponentiation-basic.js
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-12 12:17:30 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-12 12:17:46 +0100
commit13d7c09125f8eec703d0a43a9a87fc8aa08f7319 (patch)
tree70fd643c429cea5c1f9362c2674511d17a53f3b5 /Userland/Libraries/LibJS/Tests/exponentiation-basic.js
parentdc28c07fa526841e05e16161c74a6c23984f1dd5 (diff)
downloadserenity-13d7c09125f8eec703d0a43a9a87fc8aa08f7319.zip
Libraries: Move to Userland/Libraries/
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/exponentiation-basic.js')
-rw-r--r--Userland/Libraries/LibJS/Tests/exponentiation-basic.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/exponentiation-basic.js b/Userland/Libraries/LibJS/Tests/exponentiation-basic.js
new file mode 100644
index 0000000000..d260f43a1b
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/exponentiation-basic.js
@@ -0,0 +1,37 @@
+test("regular exponentiation", () => {
+ expect(2 ** 0).toBe(1);
+ expect(2 ** 1).toBe(2);
+ expect(2 ** 2).toBe(4);
+ expect(2 ** 3).toBe(8);
+ expect(3 ** 2).toBe(9);
+ expect(0 ** 0).toBe(1);
+ expect(2 ** (3 ** 2)).toBe(512);
+ expect(2 ** (3 ** 2)).toBe(512);
+ expect((2 ** 3) ** 2).toBe(64);
+});
+
+test("exponentiation with negatives", () => {
+ expect(2 ** -3).toBe(0.125);
+ expect((-2) ** 3).toBe(-8);
+
+ // FIXME: This should fail :)
+ // expect("-2 ** 3").not.toEval();
+});
+
+test("exponentiation with non-numeric primitives", () => {
+ expect("2" ** "3").toBe(8);
+ expect("" ** []).toBe(1);
+ expect([] ** null).toBe(1);
+ expect(null ** null).toBe(1);
+ expect(undefined ** null).toBe(1);
+});
+
+test("exponentiation that produces NaN", () => {
+ expect(NaN ** 2).toBeNaN();
+ expect(2 ** NaN).toBeNaN();
+ expect(undefined ** 2).toBeNaN();
+ expect(2 ** undefined).toBeNaN();
+ expect(null ** undefined).toBeNaN();
+ expect(2 ** "foo").toBeNaN();
+ expect("foo" ** 2).toBeNaN();
+});