-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemory.test.js
More file actions
56 lines (41 loc) · 1.44 KB
/
memory.test.js
File metadata and controls
56 lines (41 loc) · 1.44 KB
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
const memoryJS = require('./memory')
test('creates new object in memory', () => {
const values = [5, 2, 6, 9, 7, 80]
values.forEach((value, index) => {
const ptr = memoryJS.publicMemoryObj.newobj(value)
expect(ptr.value()).toBe((index + 1).toString())
})
})
test('accesses the stored object from memory', () => {
const values = [5, 2, 6, 9, 7, 80]
values.forEach((value) => {
const ptr = memoryJS.publicMemoryObj.newobj(value)
expect(ptr.pointedTo()).toBe(value)
expect(ptr.point).toBe(value)
expect(memoryJS.publicMemoryObj.valueOf(ptr.value())).toBe(value)
})
})
test('changes the stored object in memory', () => {
const values = [5, 2, 6, 9, 7, 80]
const changeValues = values.reverse()
values.forEach((value, index) => {
const ptr = memoryJS.publicMemoryObj.newobj(value)
ptr.changeValue(changeValues[index])
expect(ptr.point).toBe(changeValues[index])
})
values.forEach((value, index) => {
const ptr = memoryJS.publicMemoryObj.newobj(value)
memoryJS.publicMemoryObj.changeValue(ptr.value(), changeValues[index])
expect(ptr.point).toBe(changeValues[index])
})
})
test('deletes an object from memory', () => {
const ptr = memoryJS.publicMemoryObj.newobj(55)
expect(ptr.free()).toBe(null)
})
test('encapsulates object content', () => {
const ptr = memoryJS.publicMemoryObj.newobj(55)
Object.keys(ptr).forEach((key) => {
expect(typeof ptr[key]).toBe('function')
})
})