2020-07-03 18:39:25 -03:00
|
|
|
test("regular exponentiation", () => {
|
2020-07-06 11:37:45 -03:00
|
|
|
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);
|
2020-07-03 18:39:25 -03:00
|
|
|
});
|
2020-04-13 14:31:13 -03:00
|
|
|
|
2020-10-02 10:59:28 -03:00
|
|
|
test("exponentiation with negatives", () => {
|
2020-07-06 11:37:45 -03:00
|
|
|
expect(2 ** -3).toBe(0.125);
|
|
|
|
|
expect((-2) ** 3).toBe(-8);
|
2020-07-05 13:27:00 -03:00
|
|
|
|
2020-07-06 11:37:45 -03:00
|
|
|
// FIXME: This should fail :)
|
|
|
|
|
// expect("-2 ** 3").not.toEval();
|
2020-07-03 18:39:25 -03:00
|
|
|
});
|
2020-04-05 09:40:00 -03:00
|
|
|
|
2020-10-02 10:59:28 -03:00
|
|
|
test("exponentiation with non-numeric primitives", () => {
|
2020-07-06 11:37:45 -03:00
|
|
|
expect("2" ** "3").toBe(8);
|
|
|
|
|
expect("" ** []).toBe(1);
|
|
|
|
|
expect([] ** null).toBe(1);
|
|
|
|
|
expect(null ** null).toBe(1);
|
|
|
|
|
expect(undefined ** null).toBe(1);
|
2020-07-05 13:27:00 -03:00
|
|
|
});
|
2020-07-03 18:39:25 -03:00
|
|
|
|
2020-10-02 10:59:28 -03:00
|
|
|
test("exponentiation that produces NaN", () => {
|
2020-07-06 11:37:45 -03:00
|
|
|
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();
|
2020-07-03 18:39:25 -03:00
|
|
|
});
|