Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
8bf21cde
Commit
8bf21cde
authored
May 19, 2012
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish all Float ISO Tests
parent
2331738c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
37 deletions
+139
-37
test/assert.rb
test/assert.rb
+13
-0
test/t/float.rb
test/t/float.rb
+102
-0
test/t/math.rb
test/t/math.rb
+24
-37
No files found.
test/assert.rb
View file @
8bf21cde
...
...
@@ -65,3 +65,16 @@ def report()
print
(
"
\n
"
)
end
##
# Performs fuzzy check for equality on methods returning floats
# on the basis of the Math::TOLERANCE constant.
def
check_float
(
a
,
b
)
a
=
a
.
to_f
b
=
b
.
to_f
if
a
.
finite?
and
b
.
finite?
(
a
-
b
).
abs
<
Math
::
TOLERANCE
else
true
end
end
test/t/float.rb
0 → 100644
View file @
8bf21cde
##
# Float ISO Test
assert
(
'Float'
,
'15.2.9'
)
do
Float
.
class
==
Class
end
assert
(
'Float#+'
,
'15.2.9.3.1'
)
do
a
=
3.123456788
+
0.000000001
b
=
3.123456789
+
1
check_float
(
a
,
3.123456789
)
and
check_float
(
b
,
4.123456789
)
end
assert
(
'Float#-'
,
'15.2.9.3.2'
)
do
a
=
3.123456790
-
0.000000001
b
=
5.123456789
-
1
check_float
(
a
,
3.123456789
)
and
check_float
(
b
,
4.123456789
)
end
assert
(
'Float#*'
,
'15.2.9.3.3'
)
do
a
=
3.123456789
*
3.123456789
b
=
3.123456789
*
1
check_float
(
a
,
9.75598231275019
)
and
check_float
(
b
,
3.123456789
)
end
assert
(
'Float#/'
,
'15.2.9.3.4'
)
do
a
=
3.123456789
/
3.123456789
b
=
3.123456789
/
1
check_float
(
a
,
1.0
)
and
check_float
(
b
,
3.123456789
)
end
assert
(
'Float#%'
,
'15.2.9.3.5'
)
do
a
=
3.123456789
%
3.123456789
b
=
3.123456789
%
1
check_float
(
a
,
0.0
)
and
check_float
(
b
,
0.123456789
)
end
assert
(
'Float#<=>'
,
'15.2.9.3.6'
)
do
a
=
3.123456789
<=>
3.123456788
b
=
3.123456789
<=>
3.123456789
c
=
3.123456789
<=>
3.123456790
a2
=
3.123456789
<=>
3
c2
=
3.123456789
<=>
4
a
==
1
and
b
==
0
and
c
==
-
1
and
a2
==
1
and
c2
==
-
1
end
assert
(
'Float#=='
,
'15.2.9.3.7'
)
do
3.1
==
3.1
and
not
(
3.1
==
3.2
)
end
assert
(
'Float#ceil'
,
'15.2.9.3.8'
)
do
3.123456789
.
ceil
==
4
end
assert
(
'Float#finite?'
,
'15.2.9.3.9'
)
do
3.123456789
.
finite?
and
not
(
1.0
/
0.0
).
finite?
end
assert
(
'Float#floor'
,
'15.2.9.3.10'
)
do
3.123456789
.
floor
==
3
end
assert
(
'Float#infinite?'
,
'15.2.9.3.11'
)
do
not
3.123456789
.
infinite?
and
(
1.0
/
0.0
).
infinite?
end
assert
(
'Float#round'
,
'15.2.9.3.12'
)
do
a
=
3.123456789
.
round
b
=
3.5
.
round
c
=
3.499999999
.
round
a
==
3
and
b
==
4
and
c
==
3
end
assert
(
'Float#to_f'
,
'15.2.9.3.13'
)
do
a
=
3.123456789
check_float
(
a
.
to_f
,
a
)
end
assert
(
'Float#to_i'
,
'15.2.9.3.14'
)
do
3.123456789
.
to_i
==
3
end
assert
(
'Float#truncate'
,
'15.2.9.3.15'
)
do
3.123456789
.
truncate
==
3
end
test/t/math.rb
View file @
8bf21cde
##
# Math Test
##
# Performs fuzzy check for equality on methods returning floats
# on the basis of the Math::TOLERANCE constant.
def
check
(
a
,
b
)
a
=
a
.
to_f
b
=
b
.
to_f
if
a
.
finite?
and
b
.
finite?
(
a
-
b
).
abs
<
Math
::
TOLERANCE
else
true
end
end
assert
(
'Math.sin 0'
)
do
check
(
Math
.
sin
(
0
),
0
)
check
_float
(
Math
.
sin
(
0
),
0
)
end
assert
(
'Math.sin PI/2'
)
do
check
(
Math
.
sin
(
Math
::
PI
/
2
),
1
)
check
_float
(
Math
.
sin
(
Math
::
PI
/
2
),
1
)
end
...
...
@@ -32,61 +19,61 @@ assert('Fundamental trig identities') do
s
=
Math
.
sin
(
a
)
c
=
Math
.
cos
(
a
)
t
=
Math
.
tan
(
a
)
result
&=
check
(
s
,
Math
.
cos
(
ca
))
result
&=
check
(
t
,
1
/
Math
.
tan
(
ca
))
result
&=
check
(
s
**
2
+
c
**
2
,
1
)
result
&=
check
(
t
**
2
+
1
,
(
1
/
c
)
**
2
)
result
&=
check
((
1
/
t
)
**
2
+
1
,
(
1
/
s
)
**
2
)
result
&=
check
_float
(
s
,
Math
.
cos
(
ca
))
result
&=
check
_float
(
t
,
1
/
Math
.
tan
(
ca
))
result
&=
check
_float
(
s
**
2
+
c
**
2
,
1
)
result
&=
check
_float
(
t
**
2
+
1
,
(
1
/
c
)
**
2
)
result
&=
check
_float
((
1
/
t
)
**
2
+
1
,
(
1
/
s
)
**
2
)
end
result
end
assert
(
'Math.erf 0'
)
do
check
(
Math
.
erf
(
0
),
0
)
check
_float
(
Math
.
erf
(
0
),
0
)
end
assert
(
'Math.exp 0'
)
do
check
(
Math
.
exp
(
0
),
1.0
)
check
_float
(
Math
.
exp
(
0
),
1.0
)
end
assert
(
'Math.exp 1'
)
do
check
(
Math
.
exp
(
1
),
2.718281828459045
)
check
_float
(
Math
.
exp
(
1
),
2.718281828459045
)
end
assert
(
'Math.exp 1.5'
)
do
check
(
Math
.
exp
(
1.5
),
4.4816890703380645
)
check
_float
(
Math
.
exp
(
1.5
),
4.4816890703380645
)
end
assert
(
'Math.log 1'
)
do
check
(
Math
.
log
(
1
),
0
)
check
_float
(
Math
.
log
(
1
),
0
)
end
assert
(
'Math.log E'
)
do
check
(
Math
.
log
(
Math
::
E
),
1.0
)
check
_float
(
Math
.
log
(
Math
::
E
),
1.0
)
end
assert
(
'Math.log E**3'
)
do
check
(
Math
.
log
(
Math
::
E
**
3
),
3.0
)
check
_float
(
Math
.
log
(
Math
::
E
**
3
),
3.0
)
end
assert
(
'Math.log2 1'
)
do
check
(
Math
.
log2
(
1
),
0.0
)
check
_float
(
Math
.
log2
(
1
),
0.0
)
end
assert
(
'Math.log2 2'
)
do
check
(
Math
.
log2
(
2
),
1.0
)
check
_float
(
Math
.
log2
(
2
),
1.0
)
end
assert
(
'Math.log10 1'
)
do
check
(
Math
.
log10
(
1
),
0.0
)
check
_float
(
Math
.
log10
(
1
),
0.0
)
end
assert
(
'Math.log10 10'
)
do
check
(
Math
.
log10
(
10
),
1.0
)
check
_float
(
Math
.
log10
(
10
),
1.0
)
end
assert
(
'Math.log10 10**100'
)
do
check
(
Math
.
log10
(
10
**
100
),
100.0
)
check
_float
(
Math
.
log10
(
10
**
100
),
100.0
)
end
assert
(
'Math.cbrt'
)
do
...
...
@@ -94,25 +81,25 @@ assert('Math.cbrt') do
cub
=
[
-
8
,
-
1
,
0
,
1
,
8
]
result
=
true
cub
.
each_with_index
do
|
v
,
i
|
result
&=
check
(
Math
.
cbrt
(
v
),
num
[
i
])
result
&=
check
_float
(
Math
.
cbrt
(
v
),
num
[
i
])
end
result
end
assert
(
'Math.hypot'
)
do
check
(
Math
.
hypot
(
3
,
4
),
5.0
)
check
_float
(
Math
.
hypot
(
3
,
4
),
5.0
)
end
assert
(
'Math.frexp 1234'
)
do
n
=
1234
fraction
,
exponent
=
Math
.
frexp
(
n
)
check
(
Math
.
ldexp
(
fraction
,
exponent
),
n
)
check
_float
(
Math
.
ldexp
(
fraction
,
exponent
),
n
)
end
assert
(
'Math.erf 1'
)
do
check
(
Math
.
erf
(
1
),
0.842700792949715
)
check
_float
(
Math
.
erf
(
1
),
0.842700792949715
)
end
assert
(
'Math.erfc 1'
)
do
check
(
Math
.
erfc
(
1
),
0.157299207050285
)
check
_float
(
Math
.
erfc
(
1
),
0.157299207050285
)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment