|
| 1 | +import { isPowerOfTwo } from "../dist/ch"; |
| 2 | + |
| 3 | +test("sends null to isPowerOfTwo", () => { |
| 4 | + expect(isPowerOfTwo(null)).toBe(false); |
| 5 | +}); |
| 6 | + |
| 7 | +test("sends true to isPowerOfTwo", () => { |
| 8 | + expect(isPowerOfTwo(true)).toBe(false); |
| 9 | +}); |
| 10 | + |
| 11 | +test("sends false to isPowerOfTwo", () => { |
| 12 | + expect(isPowerOfTwo(false)).toBe(false); |
| 13 | +}); |
| 14 | + |
| 15 | +test("sends string to isPowerOfTwo", () => { |
| 16 | + expect(isPowerOfTwo("string")).toBe(false); |
| 17 | +}); |
| 18 | + |
| 19 | +test("sends 2 integer to isPowerOfTwo", () => { |
| 20 | + expect(isPowerOfTwo(2)).toBe(true); |
| 21 | +}); |
| 22 | + |
| 23 | +test("sends 16 integer to isPowerOfTwo", () => { |
| 24 | + expect(isPowerOfTwo(16)).toBe(true); |
| 25 | +}); |
| 26 | + |
| 27 | +test("sends 1 integer to isPowerOfTwo", () => { |
| 28 | + expect(isPowerOfTwo(1)).toBe(true); |
| 29 | +}); |
| 30 | + |
| 31 | +test("sends zero to isPowerOfTwo", () => { |
| 32 | + expect(isPowerOfTwo(0)).toBe(false); |
| 33 | +}); |
| 34 | + |
| 35 | +test("sends positive float to isPowerOfTwo", () => { |
| 36 | + expect(isPowerOfTwo(1.1)).toBe(false); |
| 37 | +}); |
| 38 | + |
| 39 | +test("sends negative odd integer to isPowerOfTwo", () => { |
| 40 | + expect(isPowerOfTwo(-1)).toBe(false); |
| 41 | +}); |
| 42 | + |
| 43 | +test("sends negative even integer to isPowerOfTwo", () => { |
| 44 | + expect(isPowerOfTwo(-2)).toBe(false); |
| 45 | +}); |
| 46 | + |
| 47 | +test("sends negative float to isPowerOfTwo", () => { |
| 48 | + expect(isPowerOfTwo(-1.1)).toBe(false); |
| 49 | +}); |
| 50 | + |
| 51 | +test("sends object to isPowerOfTwo", () => { |
| 52 | + expect(isPowerOfTwo({})).toBe(false); |
| 53 | +}); |
| 54 | + |
| 55 | +test("sends empty array to isPowerOfTwo", () => { |
| 56 | + expect(isPowerOfTwo([])).toBe(false); |
| 57 | +}); |
| 58 | + |
| 59 | +test("sends array to isPowerOfTwo", () => { |
| 60 | + expect(isPowerOfTwo(["white", "grey", "black"])).toBe(false); |
| 61 | +}); |
| 62 | + |
| 63 | +var json = `{ |
| 64 | + "actor": { |
| 65 | + "name": "Tom Cruise", |
| 66 | + "age": 56, |
| 67 | + "Born At": "Syracuse, NY", |
| 68 | + "Birthdate": "July 3 1962", |
| 69 | + "photo": "https://jsonformatter.org/img/tom-cruise.jpg" |
| 70 | + } |
| 71 | +}`; |
| 72 | + |
| 73 | +test("sends json to isPowerOfTwo", () => { |
| 74 | + expect(isPowerOfTwo(json)).toBe(false); |
| 75 | +}); |
| 76 | + |
| 77 | +var invalidjson = `{ |
| 78 | + "actor: { |
| 79 | + "name": "Tom Cruise", |
| 80 | + "age": 56 |
| 81 | + "Born At": "Syracuse, NY", |
| 82 | + "Birthdate": "July 3 1962", |
| 83 | + "photo": "https://jsonformatter.org/img/tom-cruise.jpg" |
| 84 | + } |
| 85 | +}`; |
| 86 | + |
| 87 | +test("sends invalid json to isPowerOfTwo", () => { |
| 88 | + expect(isPowerOfTwo(invalidjson)).toBe(false); |
| 89 | +}); |
| 90 | + |
| 91 | +function testFunction() { |
| 92 | + console.log("function"); |
| 93 | +} |
| 94 | + |
| 95 | +test("sends function to isPowerOfTwo", () => { |
| 96 | + expect(isPowerOfTwo(testFunction)).toBe(false); |
| 97 | +}); |
| 98 | + |
| 99 | +var para = document.createElement("p"); |
| 100 | + |
| 101 | +test("sends htmlElement to isPowerOfTwo", () => { |
| 102 | + expect(isPowerOfTwo(para)).toBe(false); |
| 103 | +}); |
| 104 | + |
| 105 | +var node = document.createTextNode("new node"); |
| 106 | + |
| 107 | +test("sends node to isPowerOfTwo", () => { |
| 108 | + expect(isPowerOfTwo(node)).toBe(false); |
| 109 | +}); |
| 110 | + |
| 111 | +test("sends regex to isPowerOfTwo", () => { |
| 112 | + expect(isPowerOfTwo(/ab+c/i)).toBe(false); |
| 113 | +}); |
0 commit comments