change sizeof(a_cast) to sizeof(void*)
[liba.git] / lua / test / pid.lua
blobe4bcd6cad4069e215f36fd41154d67d3fc7e67da
1 #!/usr/bin/env lua
3 ---@diagnostic disable: redefined-local
4 package.path = arg[0]:sub(0, -arg[0]:match("([^/\\]*)$"):len() - 1) .. "?.lua;" .. package.path
5 local test = require("test")
6 local a = require("liba")
7 test.dir(getmetatable(a.pid))
8 local ctx = a.pid.new()
9 assert(ctx)
10 test.dir(getmetatable(ctx))
11 assert(type(a.pid.kpid(ctx, 10, 0.1, 1)) == "userdata")
12 assert(type(a.pid.run(ctx, 1, 0)) == "number")
13 assert(type(a.pid.pos(ctx, 1, 0)) == "number")
14 assert(type(a.pid.inc(ctx, 1, 0)) == "number")
15 assert(type(a.pid.zero(ctx)) == "userdata")
16 ctx:kpid(3, 2, 1):zero()
17 assert(type(ctx:run(1, 0)) == "number")
18 assert(type(ctx:pos(1, 0)) == "number")
19 assert(type(ctx:inc(1, 0)) == "number")
20 assert(type(ctx.kp) == "number")
21 assert(type(ctx.ki) == "number")
22 assert(type(ctx.kd) == "number")
23 assert(type(ctx.summax) == "number")
24 assert(type(ctx.summin) == "number")
25 assert(type(ctx.sum) == "number")
26 assert(type(ctx.outmax) == "number")
27 assert(type(ctx.outmin) == "number")
28 assert(type(ctx.out) == "number")
29 assert(type(ctx.fdb) == "number")
30 assert(type(ctx.err) == "number")
31 ctx.outmin = -10
32 ctx.outmax = 10
33 ctx.summin = -5
34 ctx.summax = 5
35 ctx.kp = 3
36 ctx.ki = 2
37 ctx.kd = 1
38 ctx.__name = nil
39 assert(ctx.__name)
40 ctx.__index = nil
41 assert(ctx.__index)
42 ctx.__newindex = nil
43 assert(ctx.__newindex)
44 ---@class a.pid
45 ---@field __name string
46 ---@field __index table
47 ---@field __newindex table