File: decimal.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (115 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
env = require('test_run')
test_run = env.new()
engine = test_run:get_cfg('engine')

decimal = require('decimal')
ffi = require('ffi')

_ = box.schema.space.create('test', {engine=engine})
_ = box.space.test:create_index('pk')
box.space.test:insert{1, decimal.new(1.1)}
box.space.test:insert{2, decimal.new(2.2)}
box.space.test:insert{3, decimal.new(1.1)}
box.space.test:insert{4, decimal.new('1234567890123456789.9876543210987654321'), decimal.new(1.2345)}
box.space.test:select{}
a = box.space.test:get{4}
a:next()
a:next(1)
a:next(2)
a:slice(-2)
box.space.test:replace{3, decimal.new(3.3)}
box.space.test:select{}

box.space.test:drop()

-- check decimal indexes
_ = box.schema.space.create('test', {engine=engine})
_ = box.space.test:create_index('pk', {parts={1,'decimal'}})

test_run:cmd('setopt delimiter ";"')
for i = 0,16 do
    box.space.test:insert{decimal.new((i-8)/4)}
end;
test_run:cmd('setopt delimiter ""');

box.space.test:select{}

-- check invalid values
box.space.test:insert{1.23}
box.space.test:insert{'str'}
box.space.test:insert{ffi.new('uint64_t', 0)}
-- check duplicates
box.space.test:insert{decimal.new(0)}

box.space.test.index.pk:drop()

_ = box.space.test:create_index('pk', {parts={1, 'number'}})

test_run:cmd('setopt delimiter ";"')
for i = 0, 32 do
    local val = (i - 16) / 8
    if i % 2 == 1 then val = decimal.new(val) end
    box.space.test:insert{val}
end;
test_run:cmd('setopt delimiter ""');

box.space.test:select{}

-- check duplicates
box.space.test:insert{-2}
box.space.test:insert{decimal.new(-2)}
box.space.test:insert{decimal.new(-1.875)}
box.space.test:insert{-1.875}

box.space.test.index.pk:drop()

_ = box.space.test:create_index('pk')
test_run:cmd('setopt delimiter ";"')
for i = 1,10 do
    box.space.test:insert{i, decimal.new(i/10)}
end;
test_run:cmd('setopt delimiter ""');

-- a bigger test with a secondary index this time.
box.space.test:insert{11, 'str'}
box.space.test:insert{12, 0.63}
box.space.test:insert{13, 0.57}
box.space.test:insert{14, 0.33}
box.space.test:insert{16, 0.71}

_ = box.space.test:create_index('sk', {parts={2, 'scalar'}})
box.space.test.index.sk:select{}

box.space.test:drop()

-- check index alter
_ = box.schema.space.create('test', {engine=engine})
_ = box.space.test:create_index('pk')
_ = box.space.test:create_index('sk', {parts={2, 'number'}})
box.space.test:insert{1, decimal.new(-2)}
box.space.test:insert{2, -5}
-- failure
box.space.test.index.sk:alter{parts={2, 'decimal'}}
_ = box.space.test:delete{2}
box.space.test.index.sk:alter{parts={2, 'decimal'}}
box.space.test:insert{3, decimal.new(3)}
--failure
box.space.test:insert{4, 'string'}
-- failure
box.space.test:insert{2, -5}
box.space.test.index.sk:alter{parts={2, 'number'}}
box.space.test:insert{2, -5}
box.space.test.index.sk:select{}

box.space.test:truncate()

-- test update operations
box.space.test:insert{1, decimal.new(1.10)}
box.space.test:insert{2, 2}
box.space.test:update(1, {{'+', 2, 3.1}})
box.space.test.index.sk:select{}
box.space.test:update(1, {{'-', 2, decimal.new(3.3)}})
box.space.test:update(2, {{'+', 2, decimal.new(0.1)}})
box.space.test.index.sk:select{}

box.space.test:drop()