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
381a6ddd
Unverified
Commit
381a6ddd
authored
Jul 26, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jul 26, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4595 from shuujii/refine-Array-permutation-combination-test
Refine `Array#(permutation|combination) test`
parents
5779464e
87cc58ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
20 deletions
+26
-20
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
+26
-20
No files found.
mrbgems/mruby-array-ext/test/array.rb
View file @
381a6ddd
##
# Array(Ext) Test
def
assert_permutation_combination
(
exp
,
receiver
,
meth
,
*
args
)
act
=
[]
receiver
.
__send__
(
meth
,
*
args
)
{
|
v
|
act
<<
v
}
assert_equal
(
exp
,
act
.
sort
)
end
def
assert_permutation
(
exp
,
receiver
,
*
args
)
assert_permutation_combination
(
exp
,
receiver
,
:permutation
,
*
args
)
end
def
assert_combination
(
exp
,
receiver
,
*
args
)
assert_permutation_combination
(
exp
,
receiver
,
:combination
,
*
args
)
end
assert
(
"Array#assoc"
)
do
s1
=
[
"colors"
,
"red"
,
"blue"
,
"green"
]
s2
=
[
"letters"
,
"a"
,
"b"
,
"c"
]
...
...
@@ -369,30 +383,22 @@ end
assert
(
"Array#permutation"
)
do
a
=
[
1
,
2
,
3
]
assert_equal
([[
1
,
2
,
3
],[
1
,
3
,
2
],[
2
,
1
,
3
],[
2
,
3
,
1
],[
3
,
1
,
2
],[
3
,
2
,
1
]],
a
.
permutation
.
to_a
)
assert_equal
([[
1
],[
2
],[
3
]],
a
.
permutation
(
1
).
to_a
)
assert_equal
([[
1
,
2
],[
1
,
3
],[
2
,
1
],[
2
,
3
],[
3
,
1
],[
3
,
2
]],
a
.
permutation
(
2
).
to_a
)
assert_equal
([[
1
,
2
,
3
],[
1
,
3
,
2
],[
2
,
1
,
3
],[
2
,
3
,
1
],[
3
,
1
,
2
],[
3
,
2
,
1
]],
a
.
permutation
(
3
).
to_a
)
assert_equal
([[]],
a
.
permutation
(
0
).
to_a
)
assert_equal
([],
a
.
permutation
(
4
).
to_a
)
assert_permutation
([[
1
,
2
,
3
],[
1
,
3
,
2
],[
2
,
1
,
3
],[
2
,
3
,
1
],[
3
,
1
,
2
],[
3
,
2
,
1
]],
a
)
assert_permutation
([[
1
],[
2
],[
3
]],
a
,
1
)
assert_permutation
([[
1
,
2
],[
1
,
3
],[
2
,
1
],[
2
,
3
],[
3
,
1
],[
3
,
2
]],
a
,
2
)
assert_permutation
([[
1
,
2
,
3
],[
1
,
3
,
2
],[
2
,
1
,
3
],[
2
,
3
,
1
],[
3
,
1
,
2
],[
3
,
2
,
1
]],
a
,
3
)
assert_permutation
([[]],
a
,
0
)
assert_permutation
([],
a
,
4
)
end
assert
(
"Array#combination"
)
do
a
=
[
1
,
2
,
3
,
4
]
assert_equal
([[
1
],[
2
],[
3
],[
4
]],
a
.
combination
(
1
).
to_a
)
assert_equal
([[
1
,
2
],[
1
,
3
],[
1
,
4
],[
2
,
3
],[
2
,
4
],[
3
,
4
]],
a
.
combination
(
2
).
to_a
)
assert_equal
([[
1
,
2
,
3
],[
1
,
2
,
4
],[
1
,
3
,
4
],[
2
,
3
,
4
]],
a
.
combination
(
3
).
to_a
)
assert_equal
([[
1
,
2
,
3
,
4
]],
a
.
combination
(
4
).
to_a
)
assert_equal
([[]],
a
.
combination
(
0
).
to_a
)
assert_equal
([],
a
.
combination
(
5
).
to_a
)
assert_combination
([[
1
],[
2
],[
3
],[
4
]],
a
,
1
)
assert_combination
([[
1
,
2
],[
1
,
3
],[
1
,
4
],[
2
,
3
],[
2
,
4
],[
3
,
4
]],
a
,
2
)
assert_combination
([[
1
,
2
,
3
],[
1
,
2
,
4
],[
1
,
3
,
4
],[
2
,
3
,
4
]],
a
,
3
)
assert_combination
([[
1
,
2
,
3
,
4
]],
a
,
4
)
assert_combination
([[]],
a
,
0
)
assert_combination
([],
a
,
5
)
end
assert
(
'Array#transpose'
)
do
...
...
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