Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: allCharactersSame, binary2Decimal, getVersion, and isObjectEmpty …
- Loading branch information
1 parent
d15446d
commit 54829f2
Showing
6 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
/** | ||
* Convert a number/string to a decimal | ||
* Convert a binary number to a decimal | ||
* | ||
* @example | ||
* binary2Decimal(101010); // 42 | ||
* binary2Decimal("101010"); // 42 | ||
* | ||
* @param {number|string} binary - the number/string to be converted | ||
* @param {string} binary - the value to be converted | ||
* @returns {number} - conversion decimal | ||
*/ | ||
export function binary2Decimal(binary) { | ||
if (typeof binary === "string") return parseInt(binary.split("").reverse().join(""), 2); | ||
else if (typeof binary === "number") return parseInt(binary, 2); | ||
if (typeof binary === "string") return parseInt(binary, 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { allCharactersSame } from "../src/index"; | ||
|
||
describe("allCharactersSame.js", () => { | ||
test("if all characters of a string are equal", () => { | ||
expect(allCharactersSame("beep")).toBe(false); | ||
expect(allCharactersSame("")).toBe(true); | ||
expect(allCharactersSame("b")).toBe(true); | ||
expect(allCharactersSame("aaaaaaaaaaaa")).toBe(true); | ||
}); | ||
|
||
test("if all characters of a array are equal", () => { | ||
expect(allCharactersSame(["a", "a"])).toBe(true); | ||
expect(allCharactersSame(["beep", "beep"])).toBe(true); | ||
expect(allCharactersSame(["a", "b"])).toBe(false); | ||
expect(allCharactersSame([1, 2])).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { binary2Decimal } from "../src/index"; | ||
|
||
describe("binary2Decimal.js", () => { | ||
it("should return 42 for '101010'", () => { | ||
expect(binary2Decimal("101010")).toBe(42); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getVersion } from "../src/index"; | ||
import Package from "../package.json"; | ||
|
||
describe("getVersion.js", () => { | ||
it("should return the current lib version", () => { | ||
expect(getVersion()).toBe(Package.version); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isObjectEmpty } from "../src/index"; | ||
|
||
describe("isObjectEmpty.js", () => { | ||
it("should return true for the empties object", () => { | ||
expect(isObjectEmpty([])).toBe(true); | ||
expect(isObjectEmpty({})).toBe(true); | ||
}); | ||
|
||
it("should return false for the non empties object", () => { | ||
expect(isObjectEmpty([1, 2])).toBe(false); | ||
expect(isObjectEmpty({ beep: "Boop" })).toBe(false); | ||
}); | ||
}); |