ffjavascript/test/scalar.js

30 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

import * as chai from "chai";
import * as Scalar from "../src/scalar.js";
2020-04-20 13:34:41 +02:00
const assert = chai.assert;
2020-04-20 13:34:41 +02:00
describe("Basic scalar convertions", () => {
it("Should convertion Native", () => {
assert(Scalar.eq(Scalar.e("0x12"), 18));
assert(Scalar.eq(Scalar.e("0x12", 16), 18));
assert(Scalar.eq(Scalar.e("12", 16), 18));
assert(Scalar.eq(Scalar.e("18"), 18));
assert(Scalar.eq(Scalar.e("18", 10), 18));
assert(Scalar.eq(Scalar.e(18, 10), 18));
assert(Scalar.eq(Scalar.e(18n, 10), 18));
assert(Scalar.eq(Scalar.e(0x12, 10), 18));
assert(Scalar.eq(Scalar.e(0x12n, 10), 18));
2020-04-20 13:34:41 +02:00
});
it("Should convert to js Number Native", () => {
const maxJsNum = Number.MAX_SAFE_INTEGER;
const maxToScalar = Scalar.e(maxJsNum);
const backToNum = Scalar.toNumber(maxToScalar);
assert(backToNum, maxJsNum);
const overMaxJsNum = Scalar.add(maxToScalar, 1);
assert.throws(() => Scalar.toNumber(overMaxJsNum));
});
2020-04-20 13:34:41 +02:00
});