aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/deps/lua/test
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
commitdcacc00e3750300617ba6e16eb346713f91a783a (patch)
tree38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/deps/lua/test
parent58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff)
downloadcrep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz
Remove testing data
Diffstat (limited to 'examples/redis-unstable/deps/lua/test')
-rw-r--r--examples/redis-unstable/deps/lua/test/README26
-rw-r--r--examples/redis-unstable/deps/lua/test/bisect.lua27
-rw-r--r--examples/redis-unstable/deps/lua/test/cf.lua16
-rw-r--r--examples/redis-unstable/deps/lua/test/echo.lua5
-rw-r--r--examples/redis-unstable/deps/lua/test/env.lua7
-rw-r--r--examples/redis-unstable/deps/lua/test/factorial.lua32
-rw-r--r--examples/redis-unstable/deps/lua/test/fib.lua40
-rw-r--r--examples/redis-unstable/deps/lua/test/fibfor.lua13
-rw-r--r--examples/redis-unstable/deps/lua/test/globals.lua13
-rw-r--r--examples/redis-unstable/deps/lua/test/hello.lua3
-rw-r--r--examples/redis-unstable/deps/lua/test/life.lua111
-rw-r--r--examples/redis-unstable/deps/lua/test/luac.lua7
-rw-r--r--examples/redis-unstable/deps/lua/test/printf.lua7
-rw-r--r--examples/redis-unstable/deps/lua/test/readonly.lua12
-rw-r--r--examples/redis-unstable/deps/lua/test/sieve.lua29
-rw-r--r--examples/redis-unstable/deps/lua/test/sort.lua66
-rw-r--r--examples/redis-unstable/deps/lua/test/table.lua12
-rw-r--r--examples/redis-unstable/deps/lua/test/trace-calls.lua32
-rw-r--r--examples/redis-unstable/deps/lua/test/trace-globals.lua38
-rw-r--r--examples/redis-unstable/deps/lua/test/xd.lua14
20 files changed, 0 insertions, 510 deletions
diff --git a/examples/redis-unstable/deps/lua/test/README b/examples/redis-unstable/deps/lua/test/README
deleted file mode 100644
index 0c7f38b..0000000
--- a/examples/redis-unstable/deps/lua/test/README
+++ /dev/null
@@ -1,26 +0,0 @@
1These are simple tests for Lua. Some of them contain useful code.
2They are meant to be run to make sure Lua is built correctly and also
3to be read, to see how Lua programs look.
4
5Here is a one-line summary of each program:
6
7 bisect.lua bisection method for solving non-linear equations
8 cf.lua temperature conversion table (celsius to farenheit)
9 echo.lua echo command line arguments
10 env.lua environment variables as automatic global variables
11 factorial.lua factorial without recursion
12 fib.lua fibonacci function with cache
13 fibfor.lua fibonacci numbers with coroutines and generators
14 globals.lua report global variable usage
15 hello.lua the first program in every language
16 life.lua Conway's Game of Life
17 luac.lua bare-bones luac
18 printf.lua an implementation of printf
19 readonly.lua make global variables readonly
20 sieve.lua the sieve of of Eratosthenes programmed with coroutines
21 sort.lua two implementations of a sort function
22 table.lua make table, grouping all data for the same item
23 trace-calls.lua trace calls
24 trace-globals.lua trace assigments to global variables
25 xd.lua hex dump
26
diff --git a/examples/redis-unstable/deps/lua/test/bisect.lua b/examples/redis-unstable/deps/lua/test/bisect.lua
deleted file mode 100644
index f91e69b..0000000
--- a/examples/redis-unstable/deps/lua/test/bisect.lua
+++ /dev/null
@@ -1,27 +0,0 @@
1-- bisection method for solving non-linear equations
2
3delta=1e-6 -- tolerance
4
5function bisect(f,a,b,fa,fb)
6 local c=(a+b)/2
7 io.write(n," c=",c," a=",a," b=",b,"\n")
8 if c==a or c==b or math.abs(a-b)<delta then return c,b-a end
9 n=n+1
10 local fc=f(c)
11 if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end
12end
13
14-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0
15function solve(f,a,b)
16 n=0
17 local z,e=bisect(f,a,b,f(a),f(b))
18 io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))
19end
20
21-- our function
22function f(x)
23 return x*x*x-x-1
24end
25
26-- find zero in [1,2]
27solve(f,1,2)
diff --git a/examples/redis-unstable/deps/lua/test/cf.lua b/examples/redis-unstable/deps/lua/test/cf.lua
deleted file mode 100644
index 8cda54b..0000000
--- a/examples/redis-unstable/deps/lua/test/cf.lua
+++ /dev/null
@@ -1,16 +0,0 @@
1-- temperature conversion table (celsius to farenheit)
2
3for c0=-20,50-1,10 do
4 io.write("C ")
5 for c=c0,c0+10-1 do
6 io.write(string.format("%3.0f ",c))
7 end
8 io.write("\n")
9
10 io.write("F ")
11 for c=c0,c0+10-1 do
12 f=(9/5)*c+32
13 io.write(string.format("%3.0f ",f))
14 end
15 io.write("\n\n")
16end
diff --git a/examples/redis-unstable/deps/lua/test/echo.lua b/examples/redis-unstable/deps/lua/test/echo.lua
deleted file mode 100644
index 4313439..0000000
--- a/examples/redis-unstable/deps/lua/test/echo.lua
+++ /dev/null
@@ -1,5 +0,0 @@
1-- echo command line arguments
2
3for i=0,table.getn(arg) do
4 print(i,arg[i])
5end
diff --git a/examples/redis-unstable/deps/lua/test/env.lua b/examples/redis-unstable/deps/lua/test/env.lua
deleted file mode 100644
index 9e62a57..0000000
--- a/examples/redis-unstable/deps/lua/test/env.lua
+++ /dev/null
@@ -1,7 +0,0 @@
1-- read environment variables as if they were global variables
2
3local f=function (t,i) return os.getenv(i) end
4setmetatable(getfenv(),{__index=f})
5
6-- an example
7print(a,USER,PATH)
diff --git a/examples/redis-unstable/deps/lua/test/factorial.lua b/examples/redis-unstable/deps/lua/test/factorial.lua
deleted file mode 100644
index 7c4cf0f..0000000
--- a/examples/redis-unstable/deps/lua/test/factorial.lua
+++ /dev/null
@@ -1,32 +0,0 @@
1-- function closures are powerful
2
3-- traditional fixed-point operator from functional programming
4Y = function (g)
5 local a = function (f) return f(f) end
6 return a(function (f)
7 return g(function (x)
8 local c=f(f)
9 return c(x)
10 end)
11 end)
12end
13
14
15-- factorial without recursion
16F = function (f)
17 return function (n)
18 if n == 0 then return 1
19 else return n*f(n-1) end
20 end
21 end
22
23factorial = Y(F) -- factorial is the fixed point of F
24
25-- now test it
26function test(x)
27 io.write(x,"! = ",factorial(x),"\n")
28end
29
30for n=0,16 do
31 test(n)
32end
diff --git a/examples/redis-unstable/deps/lua/test/fib.lua b/examples/redis-unstable/deps/lua/test/fib.lua
deleted file mode 100644
index 97a921b..0000000
--- a/examples/redis-unstable/deps/lua/test/fib.lua
+++ /dev/null
@@ -1,40 +0,0 @@
1-- fibonacci function with cache
2
3-- very inefficient fibonacci function
4function fib(n)
5 N=N+1
6 if n<2 then
7 return n
8 else
9 return fib(n-1)+fib(n-2)
10 end
11end
12
13-- a general-purpose value cache
14function cache(f)
15 local c={}
16 return function (x)
17 local y=c[x]
18 if not y then
19 y=f(x)
20 c[x]=y
21 end
22 return y
23 end
24end
25
26-- run and time it
27function test(s,f)
28 N=0
29 local c=os.clock()
30 local v=f(n)
31 local t=os.clock()-c
32 print(s,n,v,t,N)
33end
34
35n=arg[1] or 24 -- for other values, do lua fib.lua XX
36n=tonumber(n)
37print("","n","value","time","evals")
38test("plain",fib)
39fib=cache(fib)
40test("cached",fib)
diff --git a/examples/redis-unstable/deps/lua/test/fibfor.lua b/examples/redis-unstable/deps/lua/test/fibfor.lua
deleted file mode 100644
index 8bbba39..0000000
--- a/examples/redis-unstable/deps/lua/test/fibfor.lua
+++ /dev/null
@@ -1,13 +0,0 @@
1-- example of for with generator functions
2
3function generatefib (n)
4 return coroutine.wrap(function ()
5 local a,b = 1, 1
6 while a <= n do
7 coroutine.yield(a)
8 a, b = b, a+b
9 end
10 end)
11end
12
13for i in generatefib(1000) do print(i) end
diff --git a/examples/redis-unstable/deps/lua/test/globals.lua b/examples/redis-unstable/deps/lua/test/globals.lua
deleted file mode 100644
index d4c20e1..0000000
--- a/examples/redis-unstable/deps/lua/test/globals.lua
+++ /dev/null
@@ -1,13 +0,0 @@
1-- reads luac listings and reports global variable usage
2-- lines where a global is written to are marked with "*"
3-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua
4
5while 1 do
6 local s=io.read()
7 if s==nil then break end
8 local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$")
9 if ok then
10 if op=="S" then op="*" else op="" end
11 io.write(g,"\t",l,op,"\n")
12 end
13end
diff --git a/examples/redis-unstable/deps/lua/test/hello.lua b/examples/redis-unstable/deps/lua/test/hello.lua
deleted file mode 100644
index 0925498..0000000
--- a/examples/redis-unstable/deps/lua/test/hello.lua
+++ /dev/null
@@ -1,3 +0,0 @@
1-- the first program in every language
2
3io.write("Hello world, from ",_VERSION,"!\n")
diff --git a/examples/redis-unstable/deps/lua/test/life.lua b/examples/redis-unstable/deps/lua/test/life.lua
deleted file mode 100644
index 911d9fe..0000000
--- a/examples/redis-unstable/deps/lua/test/life.lua
+++ /dev/null
@@ -1,111 +0,0 @@
1-- life.lua
2-- original by Dave Bollinger <DBollinger@compuserve.com> posted to lua-l
3-- modified to use ANSI terminal escape sequences
4-- modified to use for instead of while
5
6local write=io.write
7
8ALIVE="¥" DEAD="þ"
9ALIVE="O" DEAD="-"
10
11function delay() -- NOTE: SYSTEM-DEPENDENT, adjust as necessary
12 for i=1,10000 do end
13 -- local i=os.clock()+1 while(os.clock()<i) do end
14end
15
16function ARRAY2D(w,h)
17 local t = {w=w,h=h}
18 for y=1,h do
19 t[y] = {}
20 for x=1,w do
21 t[y][x]=0
22 end
23 end
24 return t
25end
26
27_CELLS = {}
28
29-- give birth to a "shape" within the cell array
30function _CELLS:spawn(shape,left,top)
31 for y=0,shape.h-1 do
32 for x=0,shape.w-1 do
33 self[top+y][left+x] = shape[y*shape.w+x+1]
34 end
35 end
36end
37
38-- run the CA and produce the next generation
39function _CELLS:evolve(next)
40 local ym1,y,yp1,yi=self.h-1,self.h,1,self.h
41 while yi > 0 do
42 local xm1,x,xp1,xi=self.w-1,self.w,1,self.w
43 while xi > 0 do
44 local sum = self[ym1][xm1] + self[ym1][x] + self[ym1][xp1] +
45 self[y][xm1] + self[y][xp1] +
46 self[yp1][xm1] + self[yp1][x] + self[yp1][xp1]
47 next[y][x] = ((sum==2) and self[y][x]) or ((sum==3) and 1) or 0
48 xm1,x,xp1,xi = x,xp1,xp1+1,xi-1
49 end
50 ym1,y,yp1,yi = y,yp1,yp1+1,yi-1
51 end
52end
53
54-- output the array to screen
55function _CELLS:draw()
56 local out="" -- accumulate to reduce flicker
57 for y=1,self.h do
58 for x=1,self.w do
59 out=out..(((self[y][x]>0) and ALIVE) or DEAD)
60 end
61 out=out.."\n"
62 end
63 write(out)
64end
65
66-- constructor
67function CELLS(w,h)
68 local c = ARRAY2D(w,h)
69 c.spawn = _CELLS.spawn
70 c.evolve = _CELLS.evolve
71 c.draw = _CELLS.draw
72 return c
73end
74
75--
76-- shapes suitable for use with spawn() above
77--
78HEART = { 1,0,1,1,0,1,1,1,1; w=3,h=3 }
79GLIDER = { 0,0,1,1,0,1,0,1,1; w=3,h=3 }
80EXPLODE = { 0,1,0,1,1,1,1,0,1,0,1,0; w=3,h=4 }
81FISH = { 0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0; w=5,h=4 }
82BUTTERFLY = { 1,0,0,0,1,0,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1; w=5,h=5 }
83
84-- the main routine
85function LIFE(w,h)
86 -- create two arrays
87 local thisgen = CELLS(w,h)
88 local nextgen = CELLS(w,h)
89
90 -- create some life
91 -- about 1000 generations of fun, then a glider steady-state
92 thisgen:spawn(GLIDER,5,4)
93 thisgen:spawn(EXPLODE,25,10)
94 thisgen:spawn(FISH,4,12)
95
96 -- run until break
97 local gen=1
98 write("\027[2J") -- ANSI clear screen
99 while 1 do
100 thisgen:evolve(nextgen)
101 thisgen,nextgen = nextgen,thisgen
102 write("\027[H") -- ANSI home cursor
103 thisgen:draw()
104 write("Life - generation ",gen,"\n")
105 gen=gen+1
106 if gen>2000 then break end
107 --delay() -- no delay
108 end
109end
110
111LIFE(40,20)
diff --git a/examples/redis-unstable/deps/lua/test/luac.lua b/examples/redis-unstable/deps/lua/test/luac.lua
deleted file mode 100644
index 96a0a97..0000000
--- a/examples/redis-unstable/deps/lua/test/luac.lua
+++ /dev/null
@@ -1,7 +0,0 @@
1-- bare-bones luac in Lua
2-- usage: lua luac.lua file.lua
3
4assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
5f=assert(io.open("luac.out","wb"))
6assert(f:write(string.dump(assert(loadfile(arg[1])))))
7assert(f:close())
diff --git a/examples/redis-unstable/deps/lua/test/printf.lua b/examples/redis-unstable/deps/lua/test/printf.lua
deleted file mode 100644
index 58c63ff..0000000
--- a/examples/redis-unstable/deps/lua/test/printf.lua
+++ /dev/null
@@ -1,7 +0,0 @@
1-- an implementation of printf
2
3function printf(...)
4 io.write(string.format(...))
5end
6
7printf("Hello %s from %s on %s\n",os.getenv"USER" or "there",_VERSION,os.date())
diff --git a/examples/redis-unstable/deps/lua/test/readonly.lua b/examples/redis-unstable/deps/lua/test/readonly.lua
deleted file mode 100644
index 85c0b4e..0000000
--- a/examples/redis-unstable/deps/lua/test/readonly.lua
+++ /dev/null
@@ -1,12 +0,0 @@
1-- make global variables readonly
2
3local f=function (t,i) error("cannot redefine global variable `"..i.."'",2) end
4local g={}
5local G=getfenv()
6setmetatable(g,{__index=G,__newindex=f})
7setfenv(1,g)
8
9-- an example
10rawset(g,"x",3)
11x=2
12y=1 -- cannot redefine `y'
diff --git a/examples/redis-unstable/deps/lua/test/sieve.lua b/examples/redis-unstable/deps/lua/test/sieve.lua
deleted file mode 100644
index 0871bb2..0000000
--- a/examples/redis-unstable/deps/lua/test/sieve.lua
+++ /dev/null
@@ -1,29 +0,0 @@
1-- the sieve of of Eratosthenes programmed with coroutines
2-- typical usage: lua -e N=1000 sieve.lua | column
3
4-- generate all the numbers from 2 to n
5function gen (n)
6 return coroutine.wrap(function ()
7 for i=2,n do coroutine.yield(i) end
8 end)
9end
10
11-- filter the numbers generated by `g', removing multiples of `p'
12function filter (p, g)
13 return coroutine.wrap(function ()
14 while 1 do
15 local n = g()
16 if n == nil then return end
17 if math.mod(n, p) ~= 0 then coroutine.yield(n) end
18 end
19 end)
20end
21
22N=N or 1000 -- from command line
23x = gen(N) -- generate primes up to N
24while 1 do
25 local n = x() -- pick a number until done
26 if n == nil then break end
27 print(n) -- must be a prime number
28 x = filter(n, x) -- now remove its multiples
29end
diff --git a/examples/redis-unstable/deps/lua/test/sort.lua b/examples/redis-unstable/deps/lua/test/sort.lua
deleted file mode 100644
index 0bcb15f..0000000
--- a/examples/redis-unstable/deps/lua/test/sort.lua
+++ /dev/null
@@ -1,66 +0,0 @@
1-- two implementations of a sort function
2-- this is an example only. Lua has now a built-in function "sort"
3
4-- extracted from Programming Pearls, page 110
5function qsort(x,l,u,f)
6 if l<u then
7 local m=math.random(u-(l-1))+l-1 -- choose a random pivot in range l..u
8 x[l],x[m]=x[m],x[l] -- swap pivot to first position
9 local t=x[l] -- pivot value
10 m=l
11 local i=l+1
12 while i<=u do
13 -- invariant: x[l+1..m] < t <= x[m+1..i-1]
14 if f(x[i],t) then
15 m=m+1
16 x[m],x[i]=x[i],x[m] -- swap x[i] and x[m]
17 end
18 i=i+1
19 end
20 x[l],x[m]=x[m],x[l] -- swap pivot to a valid place
21 -- x[l+1..m-1] < x[m] <= x[m+1..u]
22 qsort(x,l,m-1,f)
23 qsort(x,m+1,u,f)
24 end
25end
26
27function selectionsort(x,n,f)
28 local i=1
29 while i<=n do
30 local m,j=i,i+1
31 while j<=n do
32 if f(x[j],x[m]) then m=j end
33 j=j+1
34 end
35 x[i],x[m]=x[m],x[i] -- swap x[i] and x[m]
36 i=i+1
37 end
38end
39
40function show(m,x)
41 io.write(m,"\n\t")
42 local i=1
43 while x[i] do
44 io.write(x[i])
45 i=i+1
46 if x[i] then io.write(",") end
47 end
48 io.write("\n")
49end
50
51function testsorts(x)
52 local n=1
53 while x[n] do n=n+1 end; n=n-1 -- count elements
54 show("original",x)
55 qsort(x,1,n,function (x,y) return x<y end)
56 show("after quicksort",x)
57 selectionsort(x,n,function (x,y) return x>y end)
58 show("after reverse selection sort",x)
59 qsort(x,1,n,function (x,y) return x<y end)
60 show("after quicksort again",x)
61end
62
63-- array to be sorted
64x={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
65
66testsorts(x)
diff --git a/examples/redis-unstable/deps/lua/test/table.lua b/examples/redis-unstable/deps/lua/test/table.lua
deleted file mode 100644
index 235089c..0000000
--- a/examples/redis-unstable/deps/lua/test/table.lua
+++ /dev/null
@@ -1,12 +0,0 @@
1-- make table, grouping all data for the same item
2-- input is 2 columns (item, data)
3
4local A
5while 1 do
6 local l=io.read()
7 if l==nil then break end
8 local _,_,a,b=string.find(l,'"?([_%w]+)"?%s*(.*)$')
9 if a~=A then A=a io.write("\n",a,":") end
10 io.write(" ",b)
11end
12io.write("\n")
diff --git a/examples/redis-unstable/deps/lua/test/trace-calls.lua b/examples/redis-unstable/deps/lua/test/trace-calls.lua
deleted file mode 100644
index 6d7a7b3..0000000
--- a/examples/redis-unstable/deps/lua/test/trace-calls.lua
+++ /dev/null
@@ -1,32 +0,0 @@
1-- trace calls
2-- example: lua -ltrace-calls bisect.lua
3
4local level=0
5
6local function hook(event)
7 local t=debug.getinfo(3)
8 io.write(level," >>> ",string.rep(" ",level))
9 if t~=nil and t.currentline>=0 then io.write(t.short_src,":",t.currentline," ") end
10 t=debug.getinfo(2)
11 if event=="call" then
12 level=level+1
13 else
14 level=level-1 if level<0 then level=0 end
15 end
16 if t.what=="main" then
17 if event=="call" then
18 io.write("begin ",t.short_src)
19 else
20 io.write("end ",t.short_src)
21 end
22 elseif t.what=="Lua" then
23-- table.foreach(t,print)
24 io.write(event," ",t.name or "(Lua)"," <",t.linedefined,":",t.short_src,">")
25 else
26 io.write(event," ",t.name or "(C)"," [",t.what,"] ")
27 end
28 io.write("\n")
29end
30
31debug.sethook(hook,"cr")
32level=0
diff --git a/examples/redis-unstable/deps/lua/test/trace-globals.lua b/examples/redis-unstable/deps/lua/test/trace-globals.lua
deleted file mode 100644
index 295e670..0000000
--- a/examples/redis-unstable/deps/lua/test/trace-globals.lua
+++ /dev/null
@@ -1,38 +0,0 @@
1-- trace assigments to global variables
2
3do
4 -- a tostring that quotes strings. note the use of the original tostring.
5 local _tostring=tostring
6 local tostring=function(a)
7 if type(a)=="string" then
8 return string.format("%q",a)
9 else
10 return _tostring(a)
11 end
12 end
13
14 local log=function (name,old,new)
15 local t=debug.getinfo(3,"Sl")
16 local line=t.currentline
17 io.write(t.short_src)
18 if line>=0 then io.write(":",line) end
19 io.write(": ",name," is now ",tostring(new)," (was ",tostring(old),")","\n")
20 end
21
22 local g={}
23 local set=function (t,name,value)
24 log(name,g[name],value)
25 g[name]=value
26 end
27 setmetatable(getfenv(),{__index=g,__newindex=set})
28end
29
30-- an example
31
32a=1
33b=2
34a=10
35b=20
36b=nil
37b=200
38print(a,b,c)
diff --git a/examples/redis-unstable/deps/lua/test/xd.lua b/examples/redis-unstable/deps/lua/test/xd.lua
deleted file mode 100644
index ebc3eff..0000000
--- a/examples/redis-unstable/deps/lua/test/xd.lua
+++ /dev/null
@@ -1,14 +0,0 @@
1-- hex dump
2-- usage: lua xd.lua < file
3
4local offset=0
5while true do
6 local s=io.read(16)
7 if s==nil then return end
8 io.write(string.format("%08X ",offset))
9 string.gsub(s,"(.)",
10 function (c) io.write(string.format("%02X ",string.byte(c))) end)
11 io.write(string.rep(" ",3*(16-string.len(s))))
12 io.write(" ",string.gsub(s,"%c","."),"\n")
13 offset=offset+16
14end