dictionary 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +789 -0
- data/HISTORY +10 -0
- data/MANIFEST +21 -0
- data/README +62 -0
- data/RELEASE +10 -0
- data/lib/dictionary.rb +422 -0
- data/meta/authors +5 -0
- data/meta/contact +1 -0
- data/meta/created +1 -0
- data/meta/description +2 -0
- data/meta/homepage +1 -0
- data/meta/license +1 -0
- data/meta/package +1 -0
- data/meta/project +1 -0
- data/meta/released +1 -0
- data/meta/repository +1 -0
- data/meta/title +1 -0
- data/meta/version +1 -0
- data/test/test_dictionary.rb +142 -0
- metadata +88 -0
data/meta/authors
ADDED
data/meta/contact
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
trans <transfire@gmail.com>
|
data/meta/created
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2005-05-15
|
data/meta/description
ADDED
data/meta/homepage
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
http://death.rubyforge.org
|
data/meta/license
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
LGPL v3
|
data/meta/package
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
dictionary
|
data/meta/project
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
death
|
data/meta/released
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2009-07-19
|
data/meta/repository
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
http://death.rubyforge.org/svn/dictionary
|
data/meta/title
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dictionary
|
data/meta/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'dictionary.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TC_Dictionary < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_create
|
7
|
+
d = Dictionary['z', 1, 'a', 2, 'c', 3]
|
8
|
+
assert_equal( ['z','a','c'], d.keys )
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_op_store
|
12
|
+
d = Dictionary.new
|
13
|
+
d['z'] = 1
|
14
|
+
d['a'] = 2
|
15
|
+
d['c'] = 3
|
16
|
+
assert_equal( ['z','a','c'], d.keys )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_push
|
20
|
+
d = Dictionary['a', 1, 'c', 2, 'z', 3]
|
21
|
+
assert( d.push('end', 15) )
|
22
|
+
assert_equal( 15, d['end'] )
|
23
|
+
assert( ! d.push('end', 30) )
|
24
|
+
assert( d.unshift('begin', 50) )
|
25
|
+
assert_equal( 50, d['begin'] )
|
26
|
+
assert( ! d.unshift('begin', 60) )
|
27
|
+
assert_equal( ["begin", "a", "c", "z", "end"], d.keys )
|
28
|
+
assert_equal( ["end", 15], d.pop )
|
29
|
+
assert_equal( ["begin", "a", "c", "z"], d.keys )
|
30
|
+
assert_equal( ["begin", 50], d.shift )
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_insert
|
34
|
+
# front
|
35
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
36
|
+
r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3]
|
37
|
+
assert_equal( 4, d.insert(0,'d',4) )
|
38
|
+
assert_equal( r, d )
|
39
|
+
# back
|
40
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
41
|
+
r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
|
42
|
+
assert_equal( 4, d.insert(-1,'d',4) )
|
43
|
+
assert_equal( r, d )
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_update
|
47
|
+
# with other orderred hash
|
48
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
49
|
+
c = Dictionary['d', 4]
|
50
|
+
r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
|
51
|
+
assert_equal( r, d.update(c) )
|
52
|
+
assert_equal( r, d )
|
53
|
+
# with other hash
|
54
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
55
|
+
c = { 'd' => 4 }
|
56
|
+
r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
|
57
|
+
assert_equal( r, d.update(c) )
|
58
|
+
assert_equal( r, d )
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_merge
|
62
|
+
# with other orderred hash
|
63
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
64
|
+
c = Dictionary['d', 4]
|
65
|
+
r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
|
66
|
+
assert_equal( r, d.merge(c) )
|
67
|
+
# with other hash
|
68
|
+
d = Dictionary['a', 1, 'b', 2, 'c', 3]
|
69
|
+
c = { 'd' => 4 }
|
70
|
+
r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
|
71
|
+
assert_equal( r, d.merge(c) )
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_order_by
|
75
|
+
d = Dictionary['a', 3, 'b', 2, 'c', 1]
|
76
|
+
d.order_by{ |k,v| v }
|
77
|
+
assert_equal( [1,2,3], d.values )
|
78
|
+
assert_equal( ['c','b','a'], d.keys )
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_op_store_again
|
82
|
+
d = Dictionary[]
|
83
|
+
d[:a] = 1
|
84
|
+
d[:c] = 3
|
85
|
+
assert_equal( [1,3], d.values )
|
86
|
+
d[:b,1] = 2
|
87
|
+
assert_equal( [1,2,3], d.values )
|
88
|
+
assert_equal( [:a,:b,:c], d.keys )
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_reverse!
|
92
|
+
d = Dictionary['z', 1, 'a', 2, 'c', 3]
|
93
|
+
d.reverse!
|
94
|
+
assert_equal( ['c','a','z'], d.keys )
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_enumerable
|
98
|
+
d = Dictionary[]
|
99
|
+
d[:a] = "a"
|
100
|
+
d[:c] = "b"
|
101
|
+
assert_equal( ["A","B"], d.collect{|k,v| v.capitalize} )
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_autohash
|
105
|
+
d = Dictionary.new{ |hash,key| hash[key] = 0 }
|
106
|
+
d[:a] = 0
|
107
|
+
d[:b] += 1
|
108
|
+
assert_equal([0, 1], d.values)
|
109
|
+
assert_equal([:a,:b], d.keys)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_dup_with_array_values
|
113
|
+
d = Dictionary.new
|
114
|
+
d.dup
|
115
|
+
d[:a]=['t',5]
|
116
|
+
assert_equal(d, d.dup)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_first
|
120
|
+
d = Dictionary[]
|
121
|
+
d[:a] = "a"
|
122
|
+
d[:b] = "b"
|
123
|
+
d[:c] = "c"
|
124
|
+
assert_equal( "a" , d.first )
|
125
|
+
assert_equal( [] , d.first(0) )
|
126
|
+
assert_equal( ["a"] , d.first(1) )
|
127
|
+
assert_equal( ["a", "b"] , d.first(2) )
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_last
|
131
|
+
d = Dictionary[]
|
132
|
+
d[:a] = "a"
|
133
|
+
d[:b] = "b"
|
134
|
+
d[:c] = "c"
|
135
|
+
assert_equal( "c" , d.last )
|
136
|
+
assert_equal( [] , d.last(0) )
|
137
|
+
assert_equal( ["c"] , d.last(1) )
|
138
|
+
assert_equal( ["b", "c"] , d.last(2) )
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dictionary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- trans <transfire@gmail.com>
|
8
|
+
- "- Jan Molic"
|
9
|
+
- "- Andrew Johnson"
|
10
|
+
- "- Jeff Sharpe"
|
11
|
+
- "- Thomas Leitner"
|
12
|
+
- "- Trans"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2009-07-19 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
The Dictionary class is a type of ordered Hash,
|
23
|
+
which keeps it's contents in a customizable order.
|
24
|
+
email: transfire@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files:
|
30
|
+
- README
|
31
|
+
- MANIFEST
|
32
|
+
- RELEASE
|
33
|
+
- HISTORY
|
34
|
+
- COPYING
|
35
|
+
files:
|
36
|
+
- test/test_dictionary.rb
|
37
|
+
- RELEASE
|
38
|
+
- README
|
39
|
+
- HISTORY
|
40
|
+
- meta/created
|
41
|
+
- meta/repository
|
42
|
+
- meta/homepage
|
43
|
+
- meta/package
|
44
|
+
- meta/title
|
45
|
+
- meta/released
|
46
|
+
- meta/version
|
47
|
+
- meta/license
|
48
|
+
- meta/authors
|
49
|
+
- meta/project
|
50
|
+
- meta/description
|
51
|
+
- meta/contact
|
52
|
+
- lib/dictionary.rb
|
53
|
+
- COPYING
|
54
|
+
- MANIFEST
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://death.rubyforge.org
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --inline-source
|
62
|
+
- --title
|
63
|
+
- dictionary api
|
64
|
+
- --main
|
65
|
+
- README
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: death
|
83
|
+
rubygems_version: 1.3.4
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: The Dictionary class is a type of ordered Hash,
|
87
|
+
test_files:
|
88
|
+
- test/test_dictionary.rb
|