exponentiation-basic.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. test("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. test("exponentiation with negatives", () => {
  13. expect(2 ** -3).toBe(0.125);
  14. expect((-2) ** 3).toBe(-8);
  15. // FIXME: This should fail :)
  16. // expect("-2 ** 3").not.toEval();
  17. });
  18. test("exponentiation with non-numeric primitives", () => {
  19. expect("2" ** "3").toBe(8);
  20. expect("" ** []).toBe(1);
  21. expect([] ** null).toBe(1);
  22. expect(null ** null).toBe(1);
  23. expect(undefined ** null).toBe(1);
  24. });
  25. test("exponentiation that produces NaN", () => {
  26. expect(NaN ** 2).toBeNaN();
  27. expect(2 ** NaN).toBeNaN();
  28. expect(undefined ** 2).toBeNaN();
  29. expect(2 ** undefined).toBeNaN();
  30. expect(null ** undefined).toBeNaN();
  31. expect(2 ** "foo").toBeNaN();
  32. expect("foo" ** 2).toBeNaN();
  33. });