Serenity Operating System
1test("regular exponentiation", () => {
2 expect(2 ** 0).toBe(1);
3 expect(2 ** 1).toBe(2);
4 expect(2 ** 2).toBe(4);
5 expect(2 ** 3).toBe(8);
6 expect(3 ** 2).toBe(9);
7 expect(0 ** 0).toBe(1);
8 expect(2 ** (3 ** 2)).toBe(512);
9 expect(2 ** (3 ** 2)).toBe(512);
10 expect((2 ** 3) ** 2).toBe(64);
11});
12
13test("exponentiation with negatives", () => {
14 expect(2 ** -3).toBe(0.125);
15 expect((-2) ** 3).toBe(-8);
16
17 // FIXME: This should fail :)
18 // expect("-2 ** 3").not.toEval();
19});
20
21test("exponentiation with non-numeric primitives", () => {
22 expect("2" ** "3").toBe(8);
23 expect("" ** []).toBe(1);
24 expect([] ** null).toBe(1);
25 expect(null ** null).toBe(1);
26 expect(undefined ** null).toBe(1);
27});
28
29test("exponentiation that produces NaN", () => {
30 expect(NaN ** 2).toBeNaN();
31 expect(2 ** NaN).toBeNaN();
32 expect(undefined ** 2).toBeNaN();
33 expect(2 ** undefined).toBeNaN();
34 expect(null ** undefined).toBeNaN();
35 expect(2 ** "foo").toBeNaN();
36 expect("foo" ** 2).toBeNaN();
37});
38
39test("exponentiation with infinities", () => {
40 expect((-1) ** Infinity).toBeNaN();
41 expect(0 ** Infinity).toBe(0);
42 expect(1 ** Infinity).toBeNaN();
43 expect((-1) ** -Infinity).toBeNaN();
44 expect(0 ** -Infinity).toBe(Infinity);
45 expect(1 ** -Infinity).toBeNaN();
46 expect(Infinity ** -1).toBe(0);
47 expect(Infinity ** 0).toBe(1);
48 expect(Infinity ** 1).toBe(Infinity);
49 expect((-Infinity) ** -1).toBe(-0);
50 expect((-Infinity) ** 0).toBe(1);
51 expect((-Infinity) ** 1).toBe(-Infinity);
52});