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
b1c309cc
Commit
b1c309cc
authored
Jun 15, 2013
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Hash Tests
parent
409541d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
49 deletions
+68
-49
test/t/hash.rb
test/t/hash.rb
+68
-49
No files found.
test/t/hash.rb
View file @
b1c309cc
...
@@ -2,36 +2,36 @@
...
@@ -2,36 +2,36 @@
# Hash ISO Test
# Hash ISO Test
assert
(
'Hash'
,
'15.2.13'
)
do
assert
(
'Hash'
,
'15.2.13'
)
do
Hash
.
class
==
Class
assert_equal
Hash
.
class
,
Class
end
end
assert
(
'Hash superclass'
,
'15.2.13.2'
)
do
assert
(
'Hash superclass'
,
'15.2.13.2'
)
do
Hash
.
superclass
==
Object
assert_equal
Hash
.
superclass
,
Object
end
end
assert
(
'Hash#=='
,
'15.2.13.4.1'
)
do
assert
(
'Hash#=='
,
'15.2.13.4.1'
)
do
({
'abc'
=>
'abc'
}
==
{
'abc'
=>
'abc'
})
and
assert_true
({
'abc'
=>
'abc'
}
==
{
'abc'
=>
'abc'
})
not
({
'abc'
=>
'abc'
}
==
{
'cba'
=>
'cba'
})
assert_false
({
'abc'
=>
'abc'
}
==
{
'cba'
=>
'cba'
})
end
end
assert
(
'Hash#[]'
,
'15.2.13.4.2'
)
do
assert
(
'Hash#[]'
,
'15.2.13.4.2'
)
do
a
=
{
'abc'
=>
'abc'
}
a
=
{
'abc'
=>
'abc'
}
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
end
assert
(
'Hash#[]='
,
'15.2.13.4.3'
)
do
assert
(
'Hash#[]='
,
'15.2.13.4.3'
)
do
a
=
Hash
.
new
a
=
Hash
.
new
a
[
'abc'
]
=
'abc'
a
[
'abc'
]
=
'abc'
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
end
assert
(
'Hash#clear'
,
'15.2.13.4.4'
)
do
assert
(
'Hash#clear'
,
'15.2.13.4.4'
)
do
a
=
{
'abc'
=>
'abc'
}
a
=
{
'abc'
=>
'abc'
}
a
.
clear
a
.
clear
a
==
{
}
a
ssert_equal
a
,
{
}
end
end
assert
(
'Hash#default'
,
'15.2.13.4.5'
)
do
assert
(
'Hash#default'
,
'15.2.13.4.5'
)
do
...
@@ -39,15 +39,18 @@ assert('Hash#default', '15.2.13.4.5') do
...
@@ -39,15 +39,18 @@ assert('Hash#default', '15.2.13.4.5') do
b
=
Hash
.
new
(
'abc'
)
b
=
Hash
.
new
(
'abc'
)
c
=
Hash
.
new
{
|
s
,
k
|
s
[
k
]
=
k
}
c
=
Hash
.
new
{
|
s
,
k
|
s
[
k
]
=
k
}
a
.
default
==
nil
and
b
.
default
==
'abc'
and
assert_nil
a
.
default
c
.
default
==
nil
and
c
.
default
(
'abc'
)
==
'abc'
assert_equal
b
.
default
,
'abc'
assert_nil
c
.
default
assert_equal
c
.
default
(
'abc'
),
'abc'
end
end
assert
(
'Hash#default='
,
'15.2.13.4.6'
)
do
assert
(
'Hash#default='
,
'15.2.13.4.6'
)
do
a
=
{
'abc'
=>
'abc'
}
a
=
{
'abc'
=>
'abc'
}
a
.
default
=
'cba'
a
.
default
=
'cba'
a
[
'abc'
]
==
'abc'
and
a
[
'notexist'
]
==
'cba'
assert_equal
a
[
'abc'
],
'abc'
assert_equal
a
[
'notexist'
],
'cba'
end
end
assert
(
'Hash#default_proc'
,
'15.2.13.4.7'
)
do
assert
(
'Hash#default_proc'
,
'15.2.13.4.7'
)
do
...
@@ -56,8 +59,10 @@ assert('Hash#default_proc', '15.2.13.4.7') do
...
@@ -56,8 +59,10 @@ assert('Hash#default_proc', '15.2.13.4.7') do
c
=
b
[
2
]
c
=
b
[
2
]
d
=
b
[
'cat'
]
d
=
b
[
'cat'
]
a
.
default_proc
==
nil
and
b
.
default_proc
.
class
==
Proc
and
assert_nil
a
.
default_proc
c
=
4
and
d
=
'catcat'
assert_equal
b
.
default_proc
.
class
,
Proc
assert_equal
c
,
4
assert_equal
d
,
'catcat'
end
end
assert
(
'Hash#delete'
,
'15.2.13.4.8'
)
do
assert
(
'Hash#delete'
,
'15.2.13.4.8'
)
do
...
@@ -74,8 +79,10 @@ assert('Hash#delete', '15.2.13.4.8') do
...
@@ -74,8 +79,10 @@ assert('Hash#delete', '15.2.13.4.8') do
b_tmp_2
=
true
b_tmp_2
=
true
end
end
a
.
delete
(
'cba'
)
==
nil
and
not
a
.
has_key?
(
'abc'
)
and
assert_nil
a
.
delete
(
'cba'
)
not
b_tmp_1
and
b_tmp_2
assert_false
a
.
has_key?
(
'abc'
)
assert_false
b_tmp_1
assert_true
b_tmp_2
end
end
assert
(
'Hash#each'
,
'15.2.13.4.9'
)
do
assert
(
'Hash#each'
,
'15.2.13.4.9'
)
do
...
@@ -88,7 +95,8 @@ assert('Hash#each', '15.2.13.4.9') do
...
@@ -88,7 +95,8 @@ assert('Hash#each', '15.2.13.4.9') do
value
=
v
value
=
v
end
end
key
==
'abc_key'
and
value
==
'abc_value'
assert_equal
key
,
'abc_key'
assert_equal
value
,
'abc_value'
end
end
assert
(
'Hash#each_key'
,
'15.2.13.4.10'
)
do
assert
(
'Hash#each_key'
,
'15.2.13.4.10'
)
do
...
@@ -99,7 +107,7 @@ assert('Hash#each_key', '15.2.13.4.10') do
...
@@ -99,7 +107,7 @@ assert('Hash#each_key', '15.2.13.4.10') do
key
=
k
key
=
k
end
end
key
==
'abc_key'
assert_equal
key
,
'abc_key'
end
end
assert
(
'Hash#each_value'
,
'15.2.13.4.11'
)
do
assert
(
'Hash#each_value'
,
'15.2.13.4.11'
)
do
...
@@ -110,35 +118,39 @@ assert('Hash#each_value', '15.2.13.4.11') do
...
@@ -110,35 +118,39 @@ assert('Hash#each_value', '15.2.13.4.11') do
value
=
v
value
=
v
end
end
value
==
'abc_value'
assert_equal
value
,
'abc_value'
end
end
assert
(
'Hash#empty?'
,
'15.2.13.4.12'
)
do
assert
(
'Hash#empty?'
,
'15.2.13.4.12'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
not
a
.
empty?
and
b
.
empty?
assert_false
a
.
empty?
assert_true
b
.
empty?
end
end
assert
(
'Hash#has_key?'
,
'15.2.13.4.13'
)
do
assert
(
'Hash#has_key?'
,
'15.2.13.4.13'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
has_key?
(
'abc_key'
)
and
not
b
.
has_key?
(
'cba'
)
assert_true
a
.
has_key?
(
'abc_key'
)
assert_false
b
.
has_key?
(
'cba'
)
end
end
assert
(
'Hash#has_value?'
,
'15.2.13.4.14'
)
do
assert
(
'Hash#has_value?'
,
'15.2.13.4.14'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
has_value?
(
'abc_value'
)
and
not
b
.
has_value?
(
'cba'
)
assert_true
a
.
has_value?
(
'abc_value'
)
assert_false
b
.
has_value?
(
'cba'
)
end
end
assert
(
'Hash#include?'
,
'15.2.13.4.15'
)
do
assert
(
'Hash#include?'
,
'15.2.13.4.15'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
include?
(
'abc_key'
)
and
not
b
.
include?
(
'cba'
)
assert_true
a
.
include?
(
'abc_key'
)
assert_false
b
.
include?
(
'cba'
)
end
end
assert
(
'Hash#initialize'
,
'15.2.13.4.16'
)
do
assert
(
'Hash#initialize'
,
'15.2.13.4.16'
)
do
...
@@ -146,44 +158,47 @@ assert('Hash#initialize', '15.2.13.4.16') do
...
@@ -146,44 +158,47 @@ assert('Hash#initialize', '15.2.13.4.16') do
h
=
Hash
.
new
h
=
Hash
.
new
h2
=
Hash
.
new
(
:not_found
)
h2
=
Hash
.
new
(
:not_found
)
h
.
is_a?
Hash
and
assert_true
h
.
is_a?
Hash
h
==
{
}
and
assert_equal
h
,
{
}
h
[
"hello"
]
==
nil
and
assert_nil
h
[
"hello"
]
h2
[
"hello"
]
==
:not_found
assert_equal
h2
[
"hello"
],
:not_found
end
end
assert
(
'Hash#initialize_copy'
,
'15.2.13.4.17'
)
do
assert
(
'Hash#initialize_copy'
,
'15.2.13.4.17'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
.
initialize_copy
(
a
)
b
=
Hash
.
new
.
initialize_copy
(
a
)
b
==
{
'abc_key'
=>
'abc_value'
}
assert_equal
b
,
{
'abc_key'
=>
'abc_value'
}
end
end
assert
(
'Hash#key?'
,
'15.2.13.4.18'
)
do
assert
(
'Hash#key?'
,
'15.2.13.4.18'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
key?
(
'abc_key'
)
and
not
b
.
key?
(
'cba'
)
assert_true
a
.
key?
(
'abc_key'
)
assert_false
b
.
key?
(
'cba'
)
end
end
assert
(
'Hash#keys'
,
'15.2.13.4.19'
)
do
assert
(
'Hash#keys'
,
'15.2.13.4.19'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
a
.
keys
==
[
'abc_key'
]
a
ssert_equal
a
.
keys
,
[
'abc_key'
]
end
end
assert
(
'Hash#length'
,
'15.2.13.4.20'
)
do
assert
(
'Hash#length'
,
'15.2.13.4.20'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
length
==
1
and
b
.
length
==
0
assert_equal
a
.
length
,
1
assert_equal
b
.
length
,
0
end
end
assert
(
'Hash#member?'
,
'15.2.13.4.21'
)
do
assert
(
'Hash#member?'
,
'15.2.13.4.21'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
member?
(
'abc_key'
)
and
not
b
.
member?
(
'cba'
)
assert_true
a
.
member?
(
'abc_key'
)
assert_false
b
.
member?
(
'cba'
)
end
end
assert
(
'Hash#merge'
,
'15.2.13.4.22'
)
do
assert
(
'Hash#merge'
,
'15.2.13.4.22'
)
do
...
@@ -195,9 +210,9 @@ assert('Hash#merge', '15.2.13.4.22') do
...
@@ -195,9 +210,9 @@ assert('Hash#merge', '15.2.13.4.22') do
original
original
end
end
result_1
==
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'XXX'
,
assert_equal
result_1
,
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'XXX'
,
'xyz_key'
=>
'xyz_value'
}
and
'xyz_key'
=>
'xyz_value'
}
result_2
==
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
assert_equal
result_2
,
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
'xyz_key'
=>
'xyz_value'
}
'xyz_key'
=>
'xyz_value'
}
end
end
...
@@ -205,42 +220,44 @@ assert('Hash#replace', '15.2.13.4.23') do
...
@@ -205,42 +220,44 @@ assert('Hash#replace', '15.2.13.4.23') do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
.
replace
(
a
)
b
=
Hash
.
new
.
replace
(
a
)
b
==
{
'abc_key'
=>
'abc_value'
}
assert_equal
b
,
{
'abc_key'
=>
'abc_value'
}
end
end
assert
(
'Hash#shift'
,
'15.2.13.4.24'
)
do
assert
(
'Hash#shift'
,
'15.2.13.4.24'
)
do
a
=
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
}
a
=
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
}
b
=
a
.
shift
b
=
a
.
shift
a
==
{
'abc_key'
=>
'abc_value'
}
and
a
ssert_equal
a
,
{
'abc_key'
=>
'abc_value'
}
b
==
[
'cba_key'
,
'cba_value'
]
assert_equal
b
,
[
'cba_key'
,
'cba_value'
]
end
end
assert
(
'Hash#size'
,
'15.2.13.4.25'
)
do
assert
(
'Hash#size'
,
'15.2.13.4.25'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
size
==
1
and
b
.
size
==
0
assert_equal
a
.
size
,
1
assert_equal
b
.
size
,
0
end
end
assert
(
'Hash#store'
,
'15.2.13.4.26'
)
do
assert
(
'Hash#store'
,
'15.2.13.4.26'
)
do
a
=
Hash
.
new
a
=
Hash
.
new
a
.
store
(
'abc'
,
'abc'
)
a
.
store
(
'abc'
,
'abc'
)
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
end
assert
(
'Hash#value?'
,
'15.2.13.4.27'
)
do
assert
(
'Hash#value?'
,
'15.2.13.4.27'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
b
=
Hash
.
new
a
.
value?
(
'abc_value'
)
and
not
b
.
value?
(
'cba'
)
assert_true
a
.
value?
(
'abc_value'
)
assert_false
b
.
value?
(
'cba'
)
end
end
assert
(
'Hash#values'
,
'15.2.13.4.28'
)
do
assert
(
'Hash#values'
,
'15.2.13.4.28'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
=
{
'abc_key'
=>
'abc_value'
}
a
.
values
==
[
'abc_value'
]
a
ssert_equal
a
.
values
,
[
'abc_value'
]
end
end
# Not ISO specified
# Not ISO specified
...
@@ -250,8 +267,8 @@ assert('Hash#reject') do
...
@@ -250,8 +267,8 @@ assert('Hash#reject') do
ret
=
h
.
reject
do
|
k
,
v
|
ret
=
h
.
reject
do
|
k
,
v
|
v
%
2
==
0
v
%
2
==
0
end
end
ret
==
{
:one
=>
1
,
:three
=>
3
}
and
assert_equal
ret
,
{
:one
=>
1
,
:three
=>
3
}
h
==
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
assert_equal
h
,
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
end
end
assert
(
'Hash#reject!'
)
do
assert
(
'Hash#reject!'
)
do
...
@@ -259,8 +276,8 @@ assert('Hash#reject!') do
...
@@ -259,8 +276,8 @@ assert('Hash#reject!') do
ret
=
h
.
reject!
do
|
k
,
v
|
ret
=
h
.
reject!
do
|
k
,
v
|
v
%
2
==
0
v
%
2
==
0
end
end
ret
==
{
:one
=>
1
,
:three
=>
3
}
and
assert_equal
ret
,
{
:one
=>
1
,
:three
=>
3
}
h
==
{
:one
=>
1
,
:three
=>
3
}
assert_equal
h
,
{
:one
=>
1
,
:three
=>
3
}
end
end
assert
(
'Hash#select'
)
do
assert
(
'Hash#select'
)
do
...
@@ -268,8 +285,8 @@ assert('Hash#select') do
...
@@ -268,8 +285,8 @@ assert('Hash#select') do
ret
=
h
.
select
do
|
k
,
v
|
ret
=
h
.
select
do
|
k
,
v
|
v
%
2
==
0
v
%
2
==
0
end
end
ret
==
{
:two
=>
2
,
:four
=>
4
}
and
assert_equal
ret
,
{
:two
=>
2
,
:four
=>
4
}
h
==
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
assert_equal
h
,
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
end
end
assert
(
'Hash#select!'
)
do
assert
(
'Hash#select!'
)
do
...
@@ -277,8 +294,8 @@ assert('Hash#select!') do
...
@@ -277,8 +294,8 @@ assert('Hash#select!') do
ret
=
h
.
select!
do
|
k
,
v
|
ret
=
h
.
select!
do
|
k
,
v
|
v
%
2
==
0
v
%
2
==
0
end
end
ret
==
{
:two
=>
2
,
:four
=>
4
}
and
assert_equal
ret
,
{
:two
=>
2
,
:four
=>
4
}
h
==
{
:two
=>
2
,
:four
=>
4
}
assert_equal
h
,
{
:two
=>
2
,
:four
=>
4
}
end
end
# Not ISO specified
# Not ISO specified
...
@@ -287,5 +304,7 @@ assert('Hash#inspect') do
...
@@ -287,5 +304,7 @@ assert('Hash#inspect') do
h
=
{
"c"
=>
300
,
"a"
=>
100
,
"d"
=>
400
,
"c"
=>
300
}
h
=
{
"c"
=>
300
,
"a"
=>
100
,
"d"
=>
400
,
"c"
=>
300
}
ret
=
h
.
to_s
ret
=
h
.
to_s
ret
=
"{
\"
c
\"
=>300,
\"
a
\"
=>100,
\"
d
\"
=>400}"
assert_include
ret
,
'"c"=>300'
assert_include
ret
,
'"a"=>100'
assert_include
ret
,
'"d"=>400'
end
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