-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_memory.p8
67 lines (50 loc) · 1.47 KB
/
test_memory.p8
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
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- Unit tests for the memory module
-- by sparr
-- to run the tests use `pico8 -x tests/test_memory.p8`
#include ../pico8lib/class.lua
#include ../pico8lib/strings.lua
#include ../pico8lib/log.lua
#include ../pico8lib/functions.lua
#include ../pico8lib/tables.lua
#include ../pico8lib/test.lua
#include ../pico8lib/memory.lua
local suite = TestSuite("memory.p8")
-- MemCpy functions
local MemCpy = TestCase("memcpy")
function MemCpy:test_assert_memcpy4_copies ()
memset(0x4300, 0, 0x40)
memcpy4(0x4300, 0x5F00, 0x40)
for i = 0, 0x3F, 4 do
self:assert_equal($(0x4300+i), $(0x5F00+i))
end
end
function MemCpy:test_assert_memcpy_copies ()
memset(0x4300, 0, 0x40)
memcpy(0x4301, 0x5F01, 0x3E)
for i = 1, 0x3E do
self:assert_equal(@(0x4300+i), @(0x5F00+i))
end
-- first and last byte should remain unchanged
self:assert_equal(@(0x4300+0x00), 0)
self:assert_equal(@(0x4300+0x3F), 0)
end
suite:add_test_case(MemCpy)
-- MemCmp functions
local MemCmp = TestCase("memcmp")
function MemCmp:test_assert_memcmp4_compares ()
memset(0x4300, 0, 0x40)
_memcpy(0x4300, 0x5F00, 0x40)
self:assert_true(memcmp4(0x4300,0x5F00, 0x40))
self:assert_false(memcmp4(0x4300,0x4400, 0x40))
end
function MemCmp:test_assert_memcmp_compares ()
memset(0x4300,0,0x40)
_memcpy(0x4301,0x5F01,0x3E)
self:assert_true(memcmp(0x4301, 0x5F01, 0x3E))
self:assert_false(memcmp(0x4300, 0x5F00, 0x40))
end
suite:add_test_case(MemCmp)
run_suites{suite}