format
This commit is contained in:
parent
594ec641a4
commit
5ae03c47da
|
|
@ -214,9 +214,9 @@ describe("Bitmap", () => {
|
||||||
|
|
||||||
expect(bitmap.toString()).toEqual(resultString);
|
expect(bitmap.toString()).toEqual(resultString);
|
||||||
expect(String(bitmap)).toEqual(resultString);
|
expect(String(bitmap)).toEqual(resultString);
|
||||||
expect(`bitmap debug: ${bitmap}`).toEqual(`bitmap debug: ${resultString}`)
|
expect(`bitmap debug: ${bitmap}`).toEqual(`bitmap debug: ${resultString}`);
|
||||||
|
|
||||||
const bitmap2 = Bitmap.fromString(bitmap.toString());
|
const bitmap2 = Bitmap.fromString(bitmap.toString());
|
||||||
expect(bitmap2.toString()).toEqual(bitmap.toString());
|
expect(bitmap2.toString()).toEqual(bitmap.toString());
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,8 @@ export class Bitmap {
|
||||||
*/
|
*/
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
return Array.from(this.bits)
|
return Array.from(this.bits)
|
||||||
.map(x => x.toString(2).padStart(8, '0'))
|
.map((x) => x.toString(2).padStart(8, "0"))
|
||||||
.join(' ');
|
.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +89,7 @@ export class Bitmap {
|
||||||
*/
|
*/
|
||||||
static fromString(s: string): Bitmap {
|
static fromString(s: string): Bitmap {
|
||||||
// allow "00000001 00000010", "0000000100000010", etc.
|
// allow "00000001 00000010", "0000000100000010", etc.
|
||||||
const cleaned = s.replace(/\s+/g, '');
|
const cleaned = s.replace(/\s+/g, "");
|
||||||
|
|
||||||
if (cleaned.length % 8 !== 0) {
|
if (cleaned.length % 8 !== 0) {
|
||||||
throw new Error("Bitmap string must be aligned to bytes (len % 8 == 0)");
|
throw new Error("Bitmap string must be aligned to bytes (len % 8 == 0)");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue