summaryrefslogtreecommitdiff
path: root/Examples/test-suite/lua/li_constraints_runme.lua
blob: c7577c2acc434c86e971303e30ef2019ff0cb05c (plain)
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
require('import')       -- the import fn
import('li_constraints') -- import lib into global
cn=li_constraints --alias

function check_func(except, f, val, name)
  actual, err = pcall(f, val);
  assert(actual == except, 'function perform exception wrongly');
  if name == nil then
    r = 'SWIG_ValueError:Received a NULL pointer.';
  else
    r = 'SWIG_ValueError:Expected a ' .. name .. ' value.';
  end
  if not actual then
    assert(err == r, 'function perform the wrong exception');
  end
end

check_func(true, cn.test_nonnegative, 10, 'non-negative');
check_func(true, cn.test_nonnegative, 0, 'non-negative');
check_func(false, cn.test_nonnegative, -10, 'non-negative');

check_func(false, cn.test_nonpositive, 10, 'non-positive');
check_func(true, cn.test_nonpositive, 0, 'non-positive');
check_func(true, cn.test_nonpositive, -10, 'non-positive');

check_func(true, cn.test_positive, 10, 'positive');
check_func(false, cn.test_positive, 0, 'positive');
check_func(false, cn.test_positive, -10, 'positive');

check_func(false, cn.test_negative, 10, 'negative');
check_func(false, cn.test_negative, 0, 'negative');
check_func(true, cn.test_negative, -10, 'negative');

check_func(true, cn.test_nonzero, 10, 'nonzero');
check_func(false, cn.test_nonzero, 0, 'nonzero');
check_func(true, cn.test_nonzero, -10, 'nonzero');

check_func(false, cn.test_nonnull, nil);
nonnull = cn.get_nonnull();
check_func(true, cn.test_nonnull, nonnull);