remove gcc for MacOS in conan.yml
[liba.git] / lua / test / complex.lua
blob913921ea11a673b72daf75127fdca8f6153af96b
1 #!/usr/bin/env lua
3 package.path = arg[0]:sub(0, -arg[0]:match("([^/\\]*)$"):len() - 1) .. "?.lua;" .. package.path
4 local test = require("test")
5 local a = require("liba")
6 test.dir(a.complex)
7 local x = a.complex.new(1, 2)
8 local y = a.complex.rect(2, 1)
9 local z = a.complex.polar(1, math.pi)
10 test.dir(getmetatable(z))
11 test.log(z:proj(), z:conj(), z.rho, z.theta)
12 z.real, z.imag = math.pi, math.pi
13 test.log("- " .. tostring(x) .. " = " .. tostring(-x))
14 test.log(tostring(x) .. " + " .. tostring(y) .. " = " .. tostring(x + y))
15 test.log(tostring(x) .. " - " .. tostring(y) .. " = " .. tostring(x - y))
16 test.log(tostring(x) .. " * " .. tostring(y) .. " = " .. tostring(x * y))
17 test.log(tostring(x) .. " / " .. tostring(y) .. " = " .. tostring(x / y))
18 test.log("- " .. tostring(x) .. " = " .. tostring(x:unm()))
19 test.log(tostring(x) .. " + " .. tostring(y) .. " = " .. tostring(x:add(y)))
20 test.log(tostring(x) .. " - " .. tostring(y) .. " = " .. tostring(x:sub(y)))
21 test.log(tostring(x) .. " * " .. tostring(y) .. " = " .. tostring(x:mul(y)))
22 test.log(tostring(x) .. " / " .. tostring(y) .. " = " .. tostring(x:div(y)))
24 assert(a.complex.exp(z))
25 assert(z:exp())
26 assert(a.complex.log(z))
27 assert(z:log())
28 assert(a.complex.sqrt(z))
29 assert(z:sqrt())
30 assert(a.complex.log2(z))
31 assert(z:log2())
32 assert(a.complex.log10(z))
33 assert(z:log10())
34 assert(a.complex.sin(z))
35 assert(z:sin())
36 assert(a.complex.cos(z))
37 assert(z:cos())
38 assert(a.complex.tan(z))
39 assert(z:tan())
40 assert(a.complex.sec(z))
41 assert(z:sec())
42 assert(a.complex.csc(z))
43 assert(z:csc())
44 assert(a.complex.cot(z))
45 assert(z:cot())
46 assert(a.complex.asin(z))
47 assert(z:asin())
48 assert(a.complex.acos(z))
49 assert(z:acos())
50 assert(a.complex.atan(z))
51 assert(z:atan())
52 assert(a.complex.asec(z))
53 assert(z:asec())
54 assert(a.complex.acsc(z))
55 assert(z:acsc())
56 assert(a.complex.acot(z))
57 assert(z:acot())
58 assert(a.complex.sinh(z))
59 assert(z:sinh())
60 assert(a.complex.cosh(z))
61 assert(z:cosh())
62 assert(a.complex.tanh(z))
63 assert(z:tanh())
64 assert(a.complex.sech(z))
65 assert(z:sech())
66 assert(a.complex.csch(z))
67 assert(z:csch())
68 assert(a.complex.coth(z))
69 assert(z:coth())
70 assert(a.complex.asinh(z))
71 assert(z:asinh())
72 assert(a.complex.acosh(z))
73 assert(z:acosh())
74 assert(a.complex.atanh(z))
75 assert(z:atanh())
76 assert(a.complex.asech(z))
77 assert(z:asech())
78 assert(a.complex.acsch(z))
79 assert(z:acsch())
80 assert(a.complex.acoth(z))
81 assert(z:acoth())
82 z.__unm = nil
83 assert(z.__unm)
84 z.__add = nil
85 assert(z.__add)
86 z.__sub = nil
87 assert(z.__sub)
88 z.__mul = nil
89 assert(z.__mul)
90 z.__div = nil
91 assert(z.__div)
92 z.__pow = nil
93 assert(z.__pow)
94 z.__len = nil
95 assert(z.__len)
96 z.__name = nil
97 assert(z.__name)
98 z.__index = nil
99 assert(z.__index)
100 z.__newindex = nil
101 assert(z.__newindex)
102 ---@class a.complex
103 ---@field __unm function
104 ---@field __add function
105 ---@field __sub function
106 ---@field __mul function
107 ---@field __div function
108 ---@field __pow function
109 ---@field __len function
110 ---@field __name string
111 ---@field __index table
112 ---@field __newindex table