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 @@
# Hash ISO Test
assert
(
'Hash'
,
'15.2.13'
)
do
Hash
.
class
==
Class
assert_equal
Hash
.
class
,
Class
end
assert
(
'Hash superclass'
,
'15.2.13.2'
)
do
Hash
.
superclass
==
Object
assert_equal
Hash
.
superclass
,
Object
end
assert
(
'Hash#=='
,
'15.2.13.4.1'
)
do
({
'abc'
=>
'abc'
}
==
{
'abc'
=>
'abc'
})
and
not
({
'abc'
=>
'abc'
}
==
{
'cba'
=>
'cba'
})
assert_true
({
'abc'
=>
'abc'
}
==
{
'abc'
=>
'abc'
})
assert_false
({
'abc'
=>
'abc'
}
==
{
'cba'
=>
'cba'
})
end
assert
(
'Hash#[]'
,
'15.2.13.4.2'
)
do
a
=
{
'abc'
=>
'abc'
}
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
assert
(
'Hash#[]='
,
'15.2.13.4.3'
)
do
a
=
Hash
.
new
a
[
'abc'
]
=
'abc'
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
assert
(
'Hash#clear'
,
'15.2.13.4.4'
)
do
a
=
{
'abc'
=>
'abc'
}
a
.
clear
a
==
{
}
a
ssert_equal
a
,
{
}
end
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'
)
c
=
Hash
.
new
{
|
s
,
k
|
s
[
k
]
=
k
}
a
.
default
==
nil
and
b
.
default
==
'abc'
and
c
.
default
==
nil
and
c
.
default
(
'abc'
)
==
'abc'
assert_nil
a
.
default
assert_equal
b
.
default
,
'abc'
assert_nil
c
.
default
assert_equal
c
.
default
(
'abc'
),
'abc'
end
assert
(
'Hash#default='
,
'15.2.13.4.6'
)
do
a
=
{
'abc'
=>
'abc'
}
a
.
default
=
'cba'
a
[
'abc'
]
==
'abc'
and
a
[
'notexist'
]
==
'cba'
assert_equal
a
[
'abc'
],
'abc'
assert_equal
a
[
'notexist'
],
'cba'
end
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
]
d
=
b
[
'cat'
]
a
.
default_proc
==
nil
and
b
.
default_proc
.
class
==
Proc
and
c
=
4
and
d
=
'catcat'
assert_nil
a
.
default_proc
assert_equal
b
.
default_proc
.
class
,
Proc
assert_equal
c
,
4
assert_equal
d
,
'catcat'
end
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
end
a
.
delete
(
'cba'
)
==
nil
and
not
a
.
has_key?
(
'abc'
)
and
not
b_tmp_1
and
b_tmp_2
assert_nil
a
.
delete
(
'cba'
)
assert_false
a
.
has_key?
(
'abc'
)
assert_false
b_tmp_1
assert_true
b_tmp_2
end
assert
(
'Hash#each'
,
'15.2.13.4.9'
)
do
...
...
@@ -88,7 +95,8 @@ assert('Hash#each', '15.2.13.4.9') do
value
=
v
end
key
==
'abc_key'
and
value
==
'abc_value'
assert_equal
key
,
'abc_key'
assert_equal
value
,
'abc_value'
end
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
end
key
==
'abc_key'
assert_equal
key
,
'abc_key'
end
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
end
value
==
'abc_value'
assert_equal
value
,
'abc_value'
end
assert
(
'Hash#empty?'
,
'15.2.13.4.12'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
not
a
.
empty?
and
b
.
empty?
assert_false
a
.
empty?
assert_true
b
.
empty?
end
assert
(
'Hash#has_key?'
,
'15.2.13.4.13'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
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
assert
(
'Hash#has_value?'
,
'15.2.13.4.14'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
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
assert
(
'Hash#include?'
,
'15.2.13.4.15'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
include?
(
'abc_key'
)
and
not
b
.
include?
(
'cba'
)
assert_true
a
.
include?
(
'abc_key'
)
assert_false
b
.
include?
(
'cba'
)
end
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
h2
=
Hash
.
new
(
:not_found
)
h
.
is_a?
Hash
and
h
==
{
}
and
h
[
"hello"
]
==
nil
and
h2
[
"hello"
]
==
:not_found
assert_true
h
.
is_a?
Hash
assert_equal
h
,
{
}
assert_nil
h
[
"hello"
]
assert_equal
h2
[
"hello"
],
:not_found
end
assert
(
'Hash#initialize_copy'
,
'15.2.13.4.17'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
.
initialize_copy
(
a
)
b
==
{
'abc_key'
=>
'abc_value'
}
assert_equal
b
,
{
'abc_key'
=>
'abc_value'
}
end
assert
(
'Hash#key?'
,
'15.2.13.4.18'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
key?
(
'abc_key'
)
and
not
b
.
key?
(
'cba'
)
assert_true
a
.
key?
(
'abc_key'
)
assert_false
b
.
key?
(
'cba'
)
end
assert
(
'Hash#keys'
,
'15.2.13.4.19'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
.
keys
==
[
'abc_key'
]
a
ssert_equal
a
.
keys
,
[
'abc_key'
]
end
assert
(
'Hash#length'
,
'15.2.13.4.20'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
length
==
1
and
b
.
length
==
0
assert_equal
a
.
length
,
1
assert_equal
b
.
length
,
0
end
assert
(
'Hash#member?'
,
'15.2.13.4.21'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
member?
(
'abc_key'
)
and
not
b
.
member?
(
'cba'
)
assert_true
a
.
member?
(
'abc_key'
)
assert_false
b
.
member?
(
'cba'
)
end
assert
(
'Hash#merge'
,
'15.2.13.4.22'
)
do
...
...
@@ -195,9 +210,9 @@ assert('Hash#merge', '15.2.13.4.22') do
original
end
result_1
==
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'XXX'
,
'xyz_key'
=>
'xyz_value'
}
and
result_2
==
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
assert_equal
result_1
,
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'XXX'
,
'xyz_key'
=>
'xyz_value'
}
assert_equal
result_2
,
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
,
'xyz_key'
=>
'xyz_value'
}
end
...
...
@@ -205,42 +220,44 @@ assert('Hash#replace', '15.2.13.4.23') do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
.
replace
(
a
)
b
==
{
'abc_key'
=>
'abc_value'
}
assert_equal
b
,
{
'abc_key'
=>
'abc_value'
}
end
assert
(
'Hash#shift'
,
'15.2.13.4.24'
)
do
a
=
{
'abc_key'
=>
'abc_value'
,
'cba_key'
=>
'cba_value'
}
b
=
a
.
shift
a
==
{
'abc_key'
=>
'abc_value'
}
and
b
==
[
'cba_key'
,
'cba_value'
]
a
ssert_equal
a
,
{
'abc_key'
=>
'abc_value'
}
assert_equal
b
,
[
'cba_key'
,
'cba_value'
]
end
assert
(
'Hash#size'
,
'15.2.13.4.25'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
size
==
1
and
b
.
size
==
0
assert_equal
a
.
size
,
1
assert_equal
b
.
size
,
0
end
assert
(
'Hash#store'
,
'15.2.13.4.26'
)
do
a
=
Hash
.
new
a
.
store
(
'abc'
,
'abc'
)
a
[
'abc'
]
==
'abc'
a
ssert_equal
a
[
'abc'
],
'abc'
end
assert
(
'Hash#value?'
,
'15.2.13.4.27'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
b
=
Hash
.
new
a
.
value?
(
'abc_value'
)
and
not
b
.
value?
(
'cba'
)
assert_true
a
.
value?
(
'abc_value'
)
assert_false
b
.
value?
(
'cba'
)
end
assert
(
'Hash#values'
,
'15.2.13.4.28'
)
do
a
=
{
'abc_key'
=>
'abc_value'
}
a
.
values
==
[
'abc_value'
]
a
ssert_equal
a
.
values
,
[
'abc_value'
]
end
# Not ISO specified
...
...
@@ -250,8 +267,8 @@ assert('Hash#reject') do
ret
=
h
.
reject
do
|
k
,
v
|
v
%
2
==
0
end
ret
==
{
:one
=>
1
,
:three
=>
3
}
and
h
==
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
assert_equal
ret
,
{
:one
=>
1
,
:three
=>
3
}
assert_equal
h
,
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
end
assert
(
'Hash#reject!'
)
do
...
...
@@ -259,8 +276,8 @@ assert('Hash#reject!') do
ret
=
h
.
reject!
do
|
k
,
v
|
v
%
2
==
0
end
ret
==
{
:one
=>
1
,
:three
=>
3
}
and
h
==
{
:one
=>
1
,
:three
=>
3
}
assert_equal
ret
,
{
:one
=>
1
,
:three
=>
3
}
assert_equal
h
,
{
:one
=>
1
,
:three
=>
3
}
end
assert
(
'Hash#select'
)
do
...
...
@@ -268,8 +285,8 @@ assert('Hash#select') do
ret
=
h
.
select
do
|
k
,
v
|
v
%
2
==
0
end
ret
==
{
:two
=>
2
,
:four
=>
4
}
and
h
==
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
assert_equal
ret
,
{
:two
=>
2
,
:four
=>
4
}
assert_equal
h
,
{
:one
=>
1
,
:two
=>
2
,
:three
=>
3
,
:four
=>
4
}
end
assert
(
'Hash#select!'
)
do
...
...
@@ -277,8 +294,8 @@ assert('Hash#select!') do
ret
=
h
.
select!
do
|
k
,
v
|
v
%
2
==
0
end
ret
==
{
:two
=>
2
,
:four
=>
4
}
and
h
==
{
:two
=>
2
,
:four
=>
4
}
assert_equal
ret
,
{
:two
=>
2
,
:four
=>
4
}
assert_equal
h
,
{
:two
=>
2
,
:four
=>
4
}
end
# Not ISO specified
...
...
@@ -287,5 +304,7 @@ assert('Hash#inspect') do
h
=
{
"c"
=>
300
,
"a"
=>
100
,
"d"
=>
400
,
"c"
=>
300
}
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
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