-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
99 lines (78 loc) · 2.63 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
describeRealm('Builtin: Float64', function (options) {
let realm;
let backing;
let T;
let address;
before(() => {
realm = options.realm;
backing = realm.backing;
T = realm.T;
address = backing.alloc(T.Float64.byteLength);
});
after(() => {
backing.free(address);
});
describe('Cast', function () {
it('should return an empty value for empty input', function () {
T.Float64().should.equal(0);
});
it('should cast an out of range number', function () {
T.Float64(1231231.12312543534533).should.equal(1231231.1231254353);
});
it('should cast a stringly typed number', function () {
T.Float64("16.5").should.equal(16.5);
});
it('should cast a non-numeric string', function () {
T.Float64("hello world").should.equal(0);
});
});
it('should not create a new instance', function () {
(() => new T.Float64(123)).should.throw(TypeError);
});
describe('.emptyValue()', function () {
it('should return an empty value', function () {
T.Float64.emptyValue().should.equal(0);
});
});
describe('.randomValue()', function () {
it('should return a random value', function () {
const value = T.Float64.randomValue();
(typeof value).should.equal('number');
});
it('should accept a random value', function () {
T.Float64.accepts(T.Float64.randomValue()).should.equal(true);
});
});
describe('.initialize(), .store(), .load() and .clear()', function () {
let input;
before(() => {
input = T.Float64.randomValue();
});
it('should initialize an address', function () {
T.Float64.initialize(backing, address);
});
it('should load an empty value from a just-initialized address', function () {
T.Float64.load(backing, address).should.equal(T.Float64.emptyValue());
});
it('should store a value at an address', function () {
T.Float64.store(backing, address, input);
});
it('should load a value from an address', function () {
T.Float64.load(backing, address).should.equal(input);
});
it('should clear a value from an address', function () {
T.Float64.clear(backing, address);
});
it('should load an empty value from a cleaned up address', function () {
(T.Float64.load(backing, address) === T.Float64.emptyValue()).should.equal(true);
});
});
describe('.hashValue()', function () {
it('should hash a value', function () {
T.Float64.hashValue(123).should.be.above(-1);
});
it('should hash an empty value', function () {
T.Float64.hashValue(T.Float64.emptyValue()).should.be.above(-1);
});
});
});