UNPKG

reign

Version:

A persistent, typed-objects implementation.

102 lines (82 loc) 3.07 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; describeRealm('Builtin: Float32', function (options) { var realm = void 0; var backing = void 0; var T = void 0; var address = void 0; before(function () { realm = options.realm; backing = realm.backing; T = realm.T; address = backing.alloc(T.Float32.byteLength); }); after(function () { backing.free(address); }); describe('Cast', function () { it('should return an empty value for empty input', function () { T.Float32().should.equal(0); }); it('should cast an out of range number', function () { T.Float32(1231231.12312543534533).should.equal(1231231.125); }); it('should cast a stringly typed number', function () { T.Float32("16.5").should.equal(16.5); }); it('should cast a non-numeric string', function () { T.Float32("hello world").should.equal(0); }); }); it('should not create a new instance', function () { (function () { return new T.Float32(123); }).should.throw(TypeError); }); describe('.emptyValue()', function () { it('should return an empty value', function () { T.Float32.emptyValue().should.equal(0); }); }); describe('.randomValue()', function () { it('should return a random value', function () { var value = T.Float32.randomValue(); (typeof value === 'undefined' ? 'undefined' : _typeof(value)).should.equal('number'); }); it('should accept a random value', function () { T.Float32.accepts(T.Float32.randomValue()).should.equal(true); }); }); describe('.initialize(), .store(), .load() and .clear()', function () { var input = void 0; before(function () { input = T.Float32.randomValue(); }); it('should initialize an address', function () { T.Float32.initialize(backing, address); }); it('should load an empty value from a just-initialized address', function () { T.Float32.load(backing, address).should.equal(T.Float32.emptyValue()); }); it('should store a value at an address', function () { T.Float32.store(backing, address, input); }); it('should load a value from an address', function () { T.Float32.load(backing, address).should.equal(input); }); it('should clear a value from an address', function () { T.Float32.clear(backing, address); }); it('should load an empty value from a cleaned up address', function () { (T.Float32.load(backing, address) === T.Float32.emptyValue()).should.equal(true); }); }); describe('.hashValue()', function () { it('should hash a value', function () { T.Float32.hashValue(123).should.be.above(-1); }); it('should hash an empty value', function () { T.Float32.hashValue(T.Float32.emptyValue()).should.be.above(-1); }); }); });