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
4e3e4260
Unverified
Commit
4e3e4260
authored
Apr 16, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Apr 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4381 from shuujii/fix-missing-assertions-in-mruby-random-test
Fix missing assertions in `mruby-random` test
parents
6b8d3c70
d53eb8a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
25 deletions
+45
-25
mrbgems/mruby-random/test/random.rb
mrbgems/mruby-random/test/random.rb
+45
-25
No files found.
mrbgems/mruby-random/test/random.rb
View file @
4e3e4260
##
# Random Test
assert
(
"Random
#srand
"
)
do
assert
(
"Random
.new
"
)
do
r1
=
Random
.
new
(
123
)
r2
=
Random
.
new
(
123
)
r1
.
rand
==
r2
.
rand
r3
=
Random
.
new
(
124
)
assert_equal
(
r1
.
rand
,
r2
.
rand
)
assert_not_equal
(
r1
.
rand
,
r3
.
rand
)
end
assert
(
"Kernel
::
srand"
)
do
assert
(
"Kernel
.
srand"
)
do
srand
(
234
)
r1
=
rand
srand
(
234
)
r2
=
rand
r1
==
r2
srand
(
235
)
r3
=
rand
assert_equal
(
r1
,
r2
)
assert_not_equal
(
r1
,
r3
)
end
assert
(
"Random
::
srand"
)
do
assert
(
"Random
.
srand"
)
do
Random
.
srand
(
345
)
r1
=
rand
srand
(
345
)
r2
=
Random
.
rand
r1
==
r2
Random
.
srand
(
346
)
r3
=
rand
assert_equal
(
r1
,
r2
)
assert_not_equal
(
r1
,
r3
)
end
assert
(
"fixnum"
)
do
rand
(
3
).
class
==
Fixnum
end
assert
(
"float"
)
do
rand
.
class
==
Float
assert
(
"return class of Kernel.rand"
)
do
assert_kind_of
(
Fixnum
,
rand
(
3
))
assert_kind_of
(
Fixnum
,
rand
(
1.5
))
assert_kind_of
(
Float
,
rand
)
assert_kind_of
(
Float
,
rand
(
0.5
))
end
assert
(
"Array#shuffle"
)
do
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
orig
=
ary
.
dup
shuffled
=
ary
.
shuffle
ary
==
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
shuffled
!=
ary
and
10
.
times
{
|
x
|
ary
.
include?
x
}
assert_equal
(
orig
,
ary
)
assert_not_equal
(
ary
,
shuffled
)
assert_equal
(
ary
.
size
,
shuffled
.
size
)
shuffled
.
each
do
|
x
|
assert_include
(
ary
,
x
)
ary
.
delete
(
x
)
end
end
assert
(
'Array#shuffle!'
)
do
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary
.
shuffle!
ary
!=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
10
.
times
{
|
x
|
ary
.
include?
x
}
orig
=
ary
.
dup
assert_same
(
ary
,
ary
.
shuffle!
)
assert_not_equal
(
orig
,
ary
)
assert_equal
(
orig
.
size
,
ary
.
size
)
ary
.
each
do
|
x
|
assert_include
(
orig
,
x
)
orig
.
delete
(
x
)
end
end
assert
(
"Array#shuffle(random)"
)
do
...
...
@@ -52,12 +70,12 @@ assert("Array#shuffle(random)") do
end
# verify that the same seed causes the same results
ary
1
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
1
=
ary1
.
shuffle
Random
.
new
345
ary2
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
2
=
ary2
.
shuffle
Random
.
new
345
a
ry1
!=
shuffle1
and
10
.
times
{
|
x
|
shuffle1
.
include?
x
}
and
shuffle1
==
shuffle2
ary
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
shuffle
d1
=
ary
.
shuffle
Random
.
new
345
shuffled2
=
ary
.
shuffle
Random
.
new
345
shuffle
d3
=
ary
.
shuffle
Random
.
new
346
assert_equal
(
shuffled1
,
shuffled2
)
a
ssert_not_equal
(
shuffled1
,
shuffled3
)
end
assert
(
'Array#shuffle!(random)'
)
do
...
...
@@ -71,6 +89,8 @@ assert('Array#shuffle!(random)') do
ary1
.
shuffle!
Random
.
new
345
ary2
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary2
.
shuffle!
Random
.
new
345
ary1
!=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
and
10
.
times
{
|
x
|
ary1
.
include?
x
}
and
ary1
==
ary2
ary3
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
ary3
.
shuffle!
Random
.
new
346
assert_equal
(
ary1
,
ary2
)
assert_not_equal
(
ary1
,
ary3
)
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