exponentiation-basic.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. });
  34. test("exponentiation with infinities", () => {
  35. expect((-1) ** Infinity).toBeNaN();
  36. expect(0 ** Infinity).toBe(0);
  37. expect(1 ** Infinity).toBeNaN();
  38. expect((-1) ** -Infinity).toBeNaN();
  39. expect(0 ** -Infinity).toBe(Infinity);
  40. expect(1 ** -Infinity).toBeNaN();
  41. expect(Infinity ** -1).toBe(0);
  42. expect(Infinity ** 0).toBe(1);
  43. expect(Infinity ** 1).toBe(Infinity);
  44. expect((-Infinity) ** -1).toBe(-0);
  45. expect((-Infinity) ** 0).toBe(1);
  46. expect((-Infinity) ** 1).toBe(-Infinity);
  47. });