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
fd4e3740
Unverified
Commit
fd4e3740
authored
Jul 08, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jul 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4557 from shuujii/fix-Numeric-step-to-infinity
Fix `Numeric#step` to infinity; ref. #4555
parents
519f3963
32c2aa10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
27 deletions
+69
-27
mrblib/numeric.rb
mrblib/numeric.rb
+4
-4
test/t/numeric.rb
test/t/numeric.rb
+65
-23
No files found.
mrblib/numeric.rb
View file @
fd4e3740
...
...
@@ -105,14 +105,14 @@ module Integral
return
to_enum
(
:step
,
num
,
step
)
unless
block
i
=
__coerce_step_counter
(
num
,
step
)
if
num
==
nil
if
num
==
self
||
step
.
infinite?
block
.
call
(
i
)
if
step
>
0
&&
i
<=
(
num
||
i
)
||
step
<
0
&&
i
>=
(
num
||-
i
)
elsif
num
==
nil
while
true
block
.
call
(
i
)
i
+=
step
end
return
self
end
if
step
>
0
elsif
step
>
0
while
i
<=
num
block
.
call
(
i
)
i
+=
step
...
...
test/t/numeric.rb
View file @
fd4e3740
##
# Numeric ISO Test
def
assert_step
(
exp
,
receiver
,
args
,
inf:
false
)
act
=
[]
ret
=
receiver
.
step
(
*
args
)
do
|
i
|
act
<<
i
break
if
inf
&&
exp
.
size
==
act
.
size
end
expr
=
"
#{
receiver
.
inspect
}
.step(
#{
args
.
map
(
&
:inspect
).
join
(
', '
)
}
)"
assert
do
assert_true
(
exp
.
eql?
(
act
),
"
#{
expr
}
: counters"
,
assertion_diff
(
exp
,
act
))
assert_same
(
receiver
,
ret
,
"
#{
expr
}
: return value"
)
unless
inf
end
end
assert
(
'Numeric'
,
'15.2.7'
)
do
assert_equal
(
Class
,
Numeric
.
class
)
end
...
...
@@ -42,31 +55,60 @@ assert('Numeric#**') do
end
assert
(
'Numeric#step'
)
do
assert_step
=
->
(
exp
,
receiver
,
args
)
do
inf
=
!
args
[
0
]
act
=
[]
ret
=
receiver
.
step
(
*
args
)
do
|
i
|
act
<<
i
break
if
inf
&&
exp
.
size
==
act
.
size
end
expr
=
"
#{
receiver
.
inspect
}
.step(
#{
args
.
map
(
&
:inspect
).
join
(
', '
)
}
)"
assert_true
(
exp
.
eql?
(
act
),
"
#{
expr
}
: counters"
,
assertion_diff
(
exp
,
act
))
assert_same
(
receiver
,
ret
,
"
#{
expr
}
: return value"
)
unless
inf
end
assert_raise
(
ArgumentError
)
{
1
.
step
(
2
,
0
)
{
break
}
}
assert_step
.
([
2
,
3
,
4
],
2
,
[
4
])
assert_step
.
([
10
,
8
,
6
,
4
,
2
],
10
,
[
1
,
-
2
])
assert_step
.
([],
2
,
[
1
,
3
])
assert_step
.
([],
-
2
,
[
-
1
,
-
3
])
assert_step
.
([
10
,
11
,
12
,
13
],
10
,
[]
)
assert_step
.
([
10
,
7
,
4
],
10
,
[
nil
,
-
3
]
)
assert_step
([
2
,
3
,
4
],
2
,
[
4
])
assert_step
([
10
,
8
,
6
,
4
,
2
],
10
,
[
1
,
-
2
])
assert_step
([],
2
,
[
1
,
3
])
assert_step
([],
-
2
,
[
-
1
,
-
3
])
assert_step
([
10
,
11
,
12
,
13
],
10
,
[],
inf:
true
)
assert_step
([
10
,
7
,
4
],
10
,
[
nil
,
-
3
],
inf:
true
)
skip
unless
Object
.
const_defined?
(
:Float
)
inf
=
Float
::
INFINITY
assert_raise
(
ArgumentError
)
{
1
.
step
(
2
,
0.0
)
{
break
}
}
assert_step
.
([
2.0
,
3.0
,
4.0
],
2
,
[
4.0
])
assert_step
.
([
7.0
,
4.0
,
1.0
,
-
2.0
],
7
,
[
-
4
,
-
3.0
])
assert_step
.
([
2.0
,
3.0
,
4.0
],
2.0
,
[
4
])
assert_step
.
([
10.0
,
11.0
,
12.0
,
13.0
],
10.0
,
[])
assert_step
.
([
10.0
,
7.0
,
4.0
],
10
,
[
nil
,
-
3.0
])
assert_step
([
2.0
,
3.0
,
4.0
],
2
,
[
4.0
])
assert_step
([
7.0
,
4.0
,
1.0
,
-
2.0
],
7
,
[
-
4
,
-
3.0
])
assert_step
([
2.0
,
3.0
,
4.0
],
2.0
,
[
4
])
assert_step
([
10.0
,
11.0
,
12.0
,
13.0
],
10.0
,
[],
inf:
true
)
assert_step
([
10.0
,
7.0
,
4.0
],
10
,
[
nil
,
-
3.0
],
inf:
true
)
assert_step
([
1.0
],
1
,
[
nil
,
inf
])
assert_step
([
1.0
],
1
,
[
nil
,
-
inf
])
assert_step
([
1.0
],
1
,
[
3
,
inf
])
assert_step
([],
1
,
[
-
3
,
inf
])
assert_step
([],
1
,
[
3
,
-
inf
])
assert_step
([
1.0
],
1
,
[
-
3
,
-
inf
])
assert_step
([
1.0
],
1
,
[
inf
,
inf
])
assert_step
([],
1
,
[
inf
,
-
inf
])
assert_step
([],
1
,
[
-
inf
,
inf
])
assert_step
([
1.0
],
1
,
[
-
inf
,
-
inf
])
assert_step
([],
inf
,
[
2
])
assert_step
([],
inf
,
[
-
2
])
assert_step
([],
inf
,
[
2
,
3
])
assert_step
([
inf
,
inf
,
inf
],
inf
,
[
2
,
-
3
],
inf:
true
)
assert_step
([],
inf
,
[
2
,
inf
])
assert_step
([
inf
],
inf
,
[
2
,
-
inf
])
assert_step
([],
inf
,
[
-
2
,
inf
])
assert_step
([
inf
],
inf
,
[
-
2
,
-
inf
])
assert_step
([],
inf
,
[
-
2
,
3
])
assert_step
([
inf
,
inf
,
inf
],
inf
,
[
-
2
,
-
3
],
inf:
true
)
assert_step
([
inf
],
inf
,
[
inf
])
assert_step
([],
inf
,
[
-
inf
])
assert_step
([
inf
],
inf
,
[
inf
,
inf
])
assert_step
([
inf
],
inf
,
[
inf
,
-
inf
])
assert_step
([
inf
],
inf
,
[
-
inf
,
-
inf
])
assert_step
([
-
inf
,
-
inf
,
-
inf
],
-
inf
,
[
2
],
inf:
true
)
assert_step
([
-
inf
,
-
inf
,
-
inf
],
-
inf
,
[
-
2
],
inf:
true
)
assert_step
([
-
inf
,
-
inf
,
-
inf
],
-
inf
,
[
2
,
3
],
inf:
true
)
assert_step
([],
-
inf
,
[
2
,
-
3
])
assert_step
([
-
inf
],
-
inf
,
[
2
,
inf
])
assert_step
([],
-
inf
,
[
2
,
-
inf
])
assert_step
([
-
inf
],
-
inf
,
[
-
2
,
inf
])
assert_step
([],
-
inf
,
[
-
2
,
-
inf
])
assert_step
([
-
inf
,
-
inf
,
-
inf
],
-
inf
,
[
-
2
,
3
],
inf:
true
)
assert_step
([],
-
inf
,
[
-
2
,
-
3
])
assert_step
([
-
inf
,
-
inf
,
-
inf
],
-
inf
,
[
inf
],
inf:
true
)
assert_step
([
-
inf
],
-
inf
,
[
-
inf
])
assert_step
([
-
inf
],
-
inf
,
[
inf
,
inf
])
assert_step
([],
-
inf
,
[
inf
,
-
inf
])
assert_step
([
-
inf
],
-
inf
,
[
-
inf
,
-
inf
])
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