Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-math / test / math.rb
1 ##
2 # Math Test
3
4 assert('Math.sin 0') do
5   assert_float(0, Math.sin(0))
6 end
7
8 assert('Math.sin PI/2') do
9   assert_float(1, Math.sin(Math::PI / 2))
10 end
11
12 assert('Math.cos 0') do
13   assert_float(1, Math.cos(0))
14 end
15
16 assert('Math.cos PI/2') do
17   assert_float(0, Math.cos(Math::PI / 2))
18 end
19
20 assert('Math.tan 0') do
21   assert_float(0, Math.tan(0))
22 end
23
24 assert('Math.tan PI/4') do
25   assert_float(1, Math.tan(Math::PI / 4))
26 end
27
28 assert('Fundamental trig identities') do
29   N = 13
30   N.times do |i|
31     a  = Math::PI / N * i
32     ca = Math::PI / 2 - a
33     s  = Math.sin(a)
34     c  = Math.cos(a)
35     t  = Math.tan(a)
36     assert_float(Math.cos(ca), s)
37     assert_float(1 / Math.tan(ca), t)
38     assert_float(1, s ** 2 + c ** 2)
39     assert_float((1/c) ** 2, t ** 2 + 1)
40     assert_float((1/s) ** 2, (1/t) ** 2 + 1)
41   end
42 end
43
44 assert('Math.erf 0') do
45   assert_float(0, Math.erf(0))
46 end
47
48 assert('Math.exp 0') do
49   assert_float(1.0, Math.exp(0))
50 end
51
52 assert('Math.exp 1') do
53   assert_float(2.718281828459045, Math.exp(1))
54 end
55
56 assert('Math.exp 1.5') do
57   assert_float(4.4816890703380645, Math.exp(1.5))
58 end
59
60 assert('Math.log 1') do
61   assert_float(0, Math.log(1))
62 end
63
64 assert('Math.log E') do
65   assert_float(1.0, Math.log(Math::E))
66 end
67
68 assert('Math.log E**3') do
69   assert_float(3.0, Math.log(Math::E**3))
70 end
71
72 assert('Math.log2 1') do
73   assert_float(0.0, Math.log2(1))
74 end
75
76 assert('Math.log2 2') do
77   assert_float(1.0, Math.log2(2))
78 end
79
80 assert('Math.log10 1') do
81   assert_float(0.0, Math.log10(1))
82 end
83
84 assert('Math.log10 10') do
85   assert_float(1.0, Math.log10(10))
86 end
87
88 assert('Math.log10 10**100') do
89   assert_float(100.0, Math.log10(10**100))
90 end
91
92 assert('Math.sqrt') do
93   num = [0.0, 1.0, 2.0, 3.0, 4.0]
94   sqr = [0, 1, 4, 9, 16]
95   sqr.each_with_index do |v,i|
96     assert_float(num[i], Math.sqrt(v))
97   end
98 end
99
100 assert('Math.cbrt') do
101   num = [-2.0, -1.0, 0.0, 1.0, 2.0]
102   cub = [-8, -1, 0, 1, 8]
103   cub.each_with_index do |v,i|
104     assert_float(num[i], Math.cbrt(v))
105   end
106 end
107
108 assert('Math.hypot') do
109   assert_float(5.0, Math.hypot(3, 4))
110 end
111
112 assert('Math.frexp 1234') do
113   n = 1234
114   fraction, exponent = Math.frexp(n)
115   assert_float(n, Math.ldexp(fraction, exponent))
116 end
117
118 assert('Math.erf 1') do
119   assert_float(0.842700792949715, Math.erf(1))
120 end
121
122 assert('Math.erfc 1') do
123   assert_float(0.157299207050285, Math.erfc(1))
124 end
125
126 assert('Math.erf -1') do
127   assert_float(-0.8427007929497148, Math.erf(-1))
128 end
129
130 assert('Math.erfc -1') do
131   assert_float(1.8427007929497148, Math.erfc(-1))
132 end