forked from ammarhakim/gkyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ProtoObjectWrapper.lua
47 lines (37 loc) · 1.26 KB
/
test_ProtoObjectWrapper.lua
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
-- Gkyl ------------------------------------------------------------------------
--
-- Test for prototype wrapper
-- _______ ___
-- + 6 @ |||| # P ||| +
--------------------------------------------------------------------------------
local ffi = require "ffi"
local Unit = require "Unit"
local Proto = require "Lib.Proto"
local ProtoObjectWrapper = require "Lib.ProtoObjectWrapper"
local assert_equal = Unit.assert_equal
local stats = Unit.stats
function test_1()
local Particle = Proto()
function Particle:init(tbl)
self.x = tbl.x
self.y = tbl.y
end
-- create wrapper
local ParticleWrapper = ProtoObjectWrapper(Particle)
-- partial creation of object
local PartialParticle = ParticleWrapper { x = 1.0 }
-- finish creation of particle
local p = PartialParticle { y = 2.0 }
assert_equal(1.0, p.x, "Checking value of x")
assert_equal(2.0, p.y, "Checking value of y")
local q = PartialParticle { y = 3.0 }
assert_equal(1.0, q.x, "Checking value of x")
assert_equal(3.0, q.y, "Checking value of y")
end
test_1()
if stats.fail > 0 then
print(string.format("\nPASSED %d tests", stats.pass))
print(string.format("**** FAILED %d tests", stats.fail))
else
print(string.format("PASSED ALL %d tests!", stats.pass))
end