This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add sort to otherSignatories (#993)
- Loading branch information
1 parent
8f80edf
commit e45eb32
Showing
4 changed files
with
35 additions
and
2 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
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,16 @@ | ||
import { assertEquals } from "../deps/std/testing/asserts.ts" | ||
import { compareBytes } from "./bytes.ts" | ||
|
||
Deno.test("equals", () => { | ||
assertEquals(compareBytes(Uint8Array.of(1), Uint8Array.of(1)), 0) | ||
}) | ||
|
||
Deno.test("less than", () => { | ||
assertEquals(compareBytes(Uint8Array.of(1, 0), Uint8Array.of(1, 1)), -1) | ||
assertEquals(compareBytes(Uint8Array.of(1, 0), Uint8Array.of(1, 1, 1, 1)), -1) | ||
}) | ||
|
||
Deno.test("greater than", () => { | ||
assertEquals(compareBytes(Uint8Array.of(1, 1), Uint8Array.of(1, 0)), 1) | ||
assertEquals(compareBytes(Uint8Array.of(1, 1, 1, 1), Uint8Array.of(1, 0)), 1) | ||
}) |
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 @@ | ||
export function compareBytes(a: Uint8Array, b: Uint8Array): number { | ||
for (let i = 0; i < a.byteLength; i++) { | ||
if (a[i]! < b[i]!) { | ||
return -1 | ||
} | ||
|
||
if (a[i]! > b[i]!) { | ||
return 1 | ||
} | ||
} | ||
|
||
return a.byteLength > b.byteLength ? 1 : a.byteLength < b.byteLength ? -1 : 0 | ||
} |
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