constants 0.1.0 → 0.1.1
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/MIT-LICENSE +0 -2
- data/Rakefile +29 -28
- metadata +14 -14
- data/test/constants/constant_library_test.rb +0 -304
- data/test/constants/constant_test.rb +0 -77
- data/test/constants/libraries/element_test.rb +0 -207
- data/test/constants/libraries/particle_test.rb +0 -43
- data/test/constants/libraries/physical_test.rb +0 -32
- data/test/constants/library_test.rb +0 -125
- data/test/constants/stash_test.rb +0 -99
- data/test/constants_test_helper.rb +0 -51
- data/test/constants_test_suite.rb +0 -3
- data/test/readme_doc_test.rb +0 -58
data/MIT-LICENSE
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
Copyright (c) 2006-2008, Regents of the University of Colorado.
|
2
|
-
Developer:: Simon Chiang, Biomolecular Structure Program
|
3
|
-
Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
|
4
2
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
6
4
|
software and associated documentation files (the "Software"), to deal in the Software
|
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ desc 'Run tests.'
|
|
12
12
|
Rake::TestTask.new(:test) do |t|
|
13
13
|
t.libs << 'lib'
|
14
14
|
t.pattern = File.join('test', ENV['subset'] || '', ENV['pattern'] || '**/*_test.rb')
|
15
|
+
t.warning = true
|
15
16
|
t.verbose = true
|
16
17
|
end
|
17
18
|
|
@@ -25,35 +26,35 @@ def gemspec
|
|
25
26
|
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
26
27
|
spec
|
27
28
|
end
|
28
|
-
|
29
|
-
Rake::GemPackageTask.new(gemspec) do |pkg|
|
30
|
-
pkg.need_tar = true
|
31
|
-
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
30
|
+
Rake::GemPackageTask.new(gemspec) do |pkg|
|
31
|
+
pkg.need_tar = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :print_manifest do
|
35
|
+
# collect files from the gemspec, labeling
|
36
|
+
# with true or false corresponding to the
|
37
|
+
# file existing or not
|
38
|
+
files = gemspec.files.inject({}) do |files, file|
|
39
|
+
files[File.expand_path(file)] = [File.exists?(file), file]
|
40
|
+
files
|
41
|
+
end
|
42
|
+
|
43
|
+
# gather non-rdoc/pkg files for the project
|
44
|
+
# and add to the files list if they are not
|
45
|
+
# included already (marking by the absence
|
46
|
+
# of a label)
|
47
|
+
Dir.glob("**/*").each do |file|
|
48
|
+
next if file =~ /^(rdoc|pkg)/ || File.directory?(file)
|
49
|
+
|
50
|
+
path = File.expand_path(file)
|
51
|
+
files[path] = ["", file] unless files.has_key?(path)
|
52
|
+
end
|
53
|
+
|
54
|
+
# sort and output the results
|
55
|
+
files.values.sort_by {|exists, file| file }.each do |entry|
|
56
|
+
puts "%-5s : %s" % entry
|
57
|
+
end
|
57
58
|
end
|
58
59
|
|
59
60
|
desc 'Generate documentation.'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Chiang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-13 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.1.3
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: tap
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.8
|
34
|
+
version:
|
25
35
|
description:
|
26
36
|
email: simon.a.chiang@gmail.com
|
27
37
|
executables: []
|
@@ -44,16 +54,6 @@ files:
|
|
44
54
|
- lib/constants/stash.rb
|
45
55
|
- lib/constants/uncertainty.rb
|
46
56
|
- lib/constants.rb
|
47
|
-
- test/constants/constant_library_test.rb
|
48
|
-
- test/constants/constant_test.rb
|
49
|
-
- test/constants/libraries/element_test.rb
|
50
|
-
- test/constants/libraries/particle_test.rb
|
51
|
-
- test/constants/libraries/physical_test.rb
|
52
|
-
- test/constants/library_test.rb
|
53
|
-
- test/constants/stash_test.rb
|
54
|
-
- test/constants_test_helper.rb
|
55
|
-
- test/constants_test_suite.rb
|
56
|
-
- test/readme_doc_test.rb
|
57
57
|
has_rdoc: true
|
58
58
|
homepage: http://bioactive.rubyforge.org/constants/
|
59
59
|
post_install_message:
|
@@ -80,5 +80,5 @@ rubygems_version: 1.2.0
|
|
80
80
|
signing_key:
|
81
81
|
specification_version: 2
|
82
82
|
summary: Libraries of constants. Includes libraries for elements, particles, and physical constants.
|
83
|
-
test_files:
|
84
|
-
|
83
|
+
test_files: []
|
84
|
+
|
@@ -1,304 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../constants_test_helper.rb')
|
2
|
-
require 'constants/constant_library'
|
3
|
-
|
4
|
-
class ConstantLibraryTest < Test::Unit::TestCase
|
5
|
-
include Constants
|
6
|
-
|
7
|
-
attr_accessor :lib
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@lib = ConstantLibrary.new 'one', 'two', :one
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
# documentation test
|
15
|
-
#
|
16
|
-
|
17
|
-
def test_documentation
|
18
|
-
lib = ConstantLibrary.new('one', 'two', :three)
|
19
|
-
lib.index_by('upcase') {|value| value.to_s.upcase }
|
20
|
-
assert_equal({'ONE' => 'one', 'TWO' => 'two', 'THREE' => :three}, lib.indicies['upcase'])
|
21
|
-
|
22
|
-
lib.collect("string") {|value| value.to_s }
|
23
|
-
assert_equal(['one', 'two', 'three'], lib.collections['string'])
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# initialize test
|
28
|
-
#
|
29
|
-
|
30
|
-
def test_initialize
|
31
|
-
lib = ConstantLibrary.new
|
32
|
-
|
33
|
-
assert_equal([], lib.values)
|
34
|
-
assert_equal({}, lib.indicies)
|
35
|
-
assert_equal({}, lib.collections)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_initialize_with_values
|
39
|
-
assert_equal(['one', 'two', :one], lib.values)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_initialize_removes_duplicate_values
|
43
|
-
lib = ConstantLibrary.new 'one', 'two', 'one'
|
44
|
-
assert_equal(['one', 'two'], lib.values)
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# index_by test
|
49
|
-
#
|
50
|
-
|
51
|
-
def test_index_by_documentation
|
52
|
-
lib = ConstantLibrary.new('one', 'two', :one)
|
53
|
-
lib.index_by("string") {|value| value.to_s }
|
54
|
-
assert_equal({
|
55
|
-
'one' => ['one', :one],
|
56
|
-
'two' => 'two'},
|
57
|
-
lib.indicies['string'])
|
58
|
-
|
59
|
-
lib = ConstantLibrary.new(1,2,nil)
|
60
|
-
assert_raise(ArgumentError) { lib.index_by("error", false, nil) {|value| value } }
|
61
|
-
|
62
|
-
|
63
|
-
obj = Object.new
|
64
|
-
index = lib.index_by("ok", false, obj) {|value| value }
|
65
|
-
assert_equal 1, index[1]
|
66
|
-
assert_equal nil, index[nil]
|
67
|
-
|
68
|
-
assert_equal obj, index['non-existant']
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_index_by_creates_a_new_index_for_the_specified_inputs
|
72
|
-
block = lambda {|v| }
|
73
|
-
lib.index_by("name", "nil", "nil_value", &block)
|
74
|
-
|
75
|
-
assert lib.indicies.has_key?('name')
|
76
|
-
index = lib.indicies['name']
|
77
|
-
|
78
|
-
assert_equal ConstantLibrary::Index, index.class
|
79
|
-
assert_equal "nil", index.exclusion_value
|
80
|
-
assert_equal "nil_value", index.nil_value
|
81
|
-
assert_equal block, index.block
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_index_by_uses_name_as_indicies_key
|
85
|
-
lib.index_by(:sym) {|v| v.to_s }
|
86
|
-
assert lib.indicies.has_key?(:sym)
|
87
|
-
assert !lib.indicies.has_key?('sym')
|
88
|
-
|
89
|
-
lib.index_by('str') {|v| v.to_s }
|
90
|
-
assert !lib.indicies.has_key?(:str)
|
91
|
-
assert lib.indicies.has_key?('str')
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_index_stashes_values_by_block
|
95
|
-
lib.index_by("string") {|v| v.to_s }
|
96
|
-
assert_equal({'one' => ['one', :one], 'two' => 'two'}, lib.indicies["string"])
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_index_stashes_key_value_pairs_if_returned
|
100
|
-
lib.index_by("pairs") {|v| [v, v.to_s.upcase] }
|
101
|
-
assert_equal({'one' => 'ONE', :one => 'ONE', 'two' => 'TWO'}, lib.indicies["pairs"])
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_index_excludes_values_which_return_the_exclusion_value
|
105
|
-
lib.index_by("exclusion", nil) do |v|
|
106
|
-
v.kind_of?(String) ? nil : [v, v.to_s.upcase]
|
107
|
-
end
|
108
|
-
|
109
|
-
assert_equal({:one => 'ONE'}, lib.indicies["exclusion"])
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_index_by_default_exclusion_value_is_nil
|
113
|
-
lib.index_by("name") {|v|}
|
114
|
-
assert_equal nil, lib.indicies['name'].exclusion_value
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_index_by_raises_error_for_no_block_given
|
118
|
-
assert_raise(ArgumentError) { lib.index_by('name') }
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_index_by_returns_index
|
122
|
-
result = lib.index_by("name") {|v|}
|
123
|
-
assert_equal(lib.indicies['name'], result)
|
124
|
-
end
|
125
|
-
|
126
|
-
#
|
127
|
-
# index_by_attribute test
|
128
|
-
#
|
129
|
-
|
130
|
-
def test_index_by_attribute_stashes_values_by_method_value
|
131
|
-
lib.index_by_attribute("to_s")
|
132
|
-
assert_equal({'one' => ['one', :one], 'two' => 'two'}, lib.indicies["to_s"])
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_index_by_attribute_returns_index
|
136
|
-
result = lib.index_by_attribute("object_id")
|
137
|
-
assert_equal(lib.indicies['object_id'], result)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_index_by_attribute_raises_error_if_objects_dont_respond_to_attribute
|
141
|
-
assert_raise(NoMethodError) { lib.index_by_attribute("non_existant") }
|
142
|
-
end
|
143
|
-
|
144
|
-
#
|
145
|
-
# collect test
|
146
|
-
#
|
147
|
-
|
148
|
-
def test_collect_documentation
|
149
|
-
lib = ConstantLibrary.new('one', 'two', :three)
|
150
|
-
lib.collect("string") {|value| value.to_s }
|
151
|
-
assert_equal ['one', 'two', 'three'], lib.collections['string']
|
152
|
-
|
153
|
-
lib.collect("length") {|value| [value, value.to_s.length] }
|
154
|
-
assert_equal [nil, nil, nil, ['one', 'two'], nil, :three], lib.collections['length']
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_collect_creates_a_new_collection_for_the_specified_inputs
|
158
|
-
block = lambda {|v| }
|
159
|
-
lib.collect("name", &block)
|
160
|
-
|
161
|
-
assert lib.collections.has_key?('name')
|
162
|
-
collection = lib.collections['name']
|
163
|
-
|
164
|
-
assert_equal ConstantLibrary::Collection, collection.class
|
165
|
-
assert_equal nil, collection.nil_value
|
166
|
-
assert_equal block, collection.block
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_collect_uses_name_as_collections_key
|
170
|
-
lib.collect(:sym) {|v| v.to_s }
|
171
|
-
assert lib.collections.has_key?(:sym)
|
172
|
-
assert !lib.collections.has_key?('sym')
|
173
|
-
|
174
|
-
lib.collect('str') {|v| v.to_s }
|
175
|
-
assert !lib.collections.has_key?(:str)
|
176
|
-
assert lib.collections.has_key?('str')
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_collection_stashes_block_value
|
180
|
-
lib.collect("string") {|v| v.to_s }
|
181
|
-
assert_equal(['one', 'two', 'one'], lib.collections["string"])
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_collection_stashes_values_index_pairs_if_returned
|
185
|
-
map = {'one' => 2, 'two' => 0}
|
186
|
-
|
187
|
-
lib.collect("pairs") {|v| [v, map[v.to_s]] }
|
188
|
-
assert_equal(['two', nil, ['one', :one]], lib.collections["pairs"])
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_collection_excludes_values_which_return_nil
|
192
|
-
lib.collect("exclusion") do |v|
|
193
|
-
v.kind_of?(String) ? nil : v
|
194
|
-
end
|
195
|
-
assert_equal([:one], lib.collections["exclusion"])
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_collect_raises_error_for_no_block_given
|
199
|
-
assert_raise(ArgumentError) { lib.collect('name') }
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_collect_returns_collection
|
203
|
-
result = lib.collect("name") {|v|}
|
204
|
-
assert_equal(lib.collections['name'], result)
|
205
|
-
end
|
206
|
-
|
207
|
-
#
|
208
|
-
# collect_attribute test
|
209
|
-
#
|
210
|
-
|
211
|
-
def test_collect_attribute_collects_attribute_values
|
212
|
-
lib.collect_attribute("to_s")
|
213
|
-
assert_equal(['one', 'two', 'one'], lib.collections["to_s"])
|
214
|
-
end
|
215
|
-
|
216
|
-
#
|
217
|
-
# [] test
|
218
|
-
#
|
219
|
-
|
220
|
-
def test_get_searches_all_indicies_match
|
221
|
-
lib.index_by("string") {|v| v.to_s }
|
222
|
-
lib.index_by("strlen") {|v| v.to_s.length }
|
223
|
-
|
224
|
-
assert_equal ['one', :one], lib['one']
|
225
|
-
assert_equal ['one', 'two', :one], lib[3]
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_get_returns_nil_if_no_matches_are_found
|
229
|
-
assert_equal nil, lib['three']
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_get_returns_first_match_only
|
233
|
-
lib.index_by("str1") {|v| v.to_s }
|
234
|
-
lib.index_by("str2") {|v| [v.to_s, v.to_s.upcase] }
|
235
|
-
|
236
|
-
assert lib.indicies['str1'].has_key?('one')
|
237
|
-
assert lib.indicies['str2'].has_key?('one')
|
238
|
-
|
239
|
-
assert_not_equal lib.indicies['str1']['one'], lib.indicies['str2']['one']
|
240
|
-
assert_equal lib.indicies['str1']['one'], lib['one']
|
241
|
-
end
|
242
|
-
|
243
|
-
#
|
244
|
-
# clear test
|
245
|
-
#
|
246
|
-
|
247
|
-
def test_clear_clears_all_values_from_lib_indicies_and_collections
|
248
|
-
lib.index_by("str") {|v| v.to_s }
|
249
|
-
lib.collect("str") {|v| v.to_s }
|
250
|
-
|
251
|
-
assert !lib.values.empty?
|
252
|
-
assert !lib.indicies['str'].empty?
|
253
|
-
assert !lib.collections['str'].empty?
|
254
|
-
|
255
|
-
lib.clear
|
256
|
-
|
257
|
-
assert lib.values.empty?
|
258
|
-
assert lib.indicies['str'].empty?
|
259
|
-
assert lib.collections['str'].empty?
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_clear_only_removes_indicies_and_collections_if_specified
|
263
|
-
lib.index_by("str") {|v| v.to_s }
|
264
|
-
lib.collect("str") {|v| v.to_s }
|
265
|
-
|
266
|
-
lib.clear
|
267
|
-
|
268
|
-
assert !lib.indicies.empty?
|
269
|
-
assert !lib.collections.empty?
|
270
|
-
|
271
|
-
lib.clear(true)
|
272
|
-
|
273
|
-
assert lib.indicies.empty?
|
274
|
-
assert lib.collections.empty?
|
275
|
-
end
|
276
|
-
|
277
|
-
#
|
278
|
-
# add test
|
279
|
-
#
|
280
|
-
|
281
|
-
def test_add_adds_new_values
|
282
|
-
lib.add(:two, 'three')
|
283
|
-
assert_equal ['one', 'two', :one, :two, 'three'], lib.values
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_add_does_not_add_duplicate_values
|
287
|
-
lib.add(:one, :two, 'two', 'three')
|
288
|
-
assert_equal ['one', 'two', :one, :two, 'three'], lib.values
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_add_returns_newly_added_values
|
292
|
-
assert_equal [:two, 'three'], lib.add(:one, :two, 'two', 'three')
|
293
|
-
end
|
294
|
-
|
295
|
-
def test_add_incorporates_new_values_into_existing_indicies_and_collections
|
296
|
-
lib.index_by("str") {|v| v.to_s }
|
297
|
-
lib.collect("length") {|v| [v, v.to_s.length] }
|
298
|
-
|
299
|
-
lib.add(:one, :two, 'two', 'three')
|
300
|
-
assert_equal({'one' => ['one', :one], 'two' => ['two', :two], 'three' => 'three'}, lib.indicies['str'])
|
301
|
-
assert_equal([nil,nil,nil,['one', 'two', :one, :two], nil, 'three'], lib.collections['length'])
|
302
|
-
end
|
303
|
-
|
304
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../constants_test_helper.rb')
|
2
|
-
require 'constants/constant'
|
3
|
-
|
4
|
-
class ConstantTest < Test::Unit::TestCase
|
5
|
-
include Constants
|
6
|
-
|
7
|
-
#
|
8
|
-
# parse test
|
9
|
-
#
|
10
|
-
|
11
|
-
def test_parse_documentation
|
12
|
-
assert_equal [1.0, 0.2], Constant.parse("1.0(2)").to_a
|
13
|
-
assert_equal [1.0078250321, 1/2500000000], Constant.parse("1.007 825 032 1(4)").to_a
|
14
|
-
assert_equal [6.62606896, nil], Constant.parse("6.626 068 96").to_a
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_parse
|
18
|
-
assert_equal [1.0, nil], Constant.parse("1.0").to_a
|
19
|
-
assert_equal [1.0, 0], Constant.parse("1.0(0)").to_a
|
20
|
-
assert_equal [1.0, 0.1], Constant.parse("1.0(1)").to_a
|
21
|
-
assert_equal [100, 1], Constant.parse("100(1)").to_a
|
22
|
-
assert_equal [100, 11], Constant.parse("100(11)").to_a
|
23
|
-
assert_equal [1234.54789, 0.00011], Constant.parse("1234.54789(11)").to_a
|
24
|
-
assert_equal [1234.54789, 0.00011], Constant.parse("1234.547 89 (11)").to_a
|
25
|
-
assert_equal [1000, 100], Constant.parse("1.0(1)e3").to_a
|
26
|
-
assert_equal [0.001, 0.0001], Constant.parse("1.0(1)e-3").to_a
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# == test
|
31
|
-
#
|
32
|
-
|
33
|
-
def test_equal_compares_Numerics_with_value
|
34
|
-
c = Constant.new(1.23)
|
35
|
-
assert c == 1.23
|
36
|
-
assert c != 1.24
|
37
|
-
|
38
|
-
assert_equal 1.23, c
|
39
|
-
assert_not_equal 1.24, c
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_equal_compares_non_Numerics_directly
|
43
|
-
c1 = Constant.new(1.23)
|
44
|
-
c2 = Constant.new(1.23)
|
45
|
-
c3 = Constant.new(1.24)
|
46
|
-
|
47
|
-
assert c1 == c2
|
48
|
-
assert c1 != c3
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# <=> test
|
53
|
-
#
|
54
|
-
|
55
|
-
def test_compare_compares_on_value
|
56
|
-
c1 = Constant.new(1.23)
|
57
|
-
c2 = Constant.new(1.23)
|
58
|
-
c3 = Constant.new(1.24)
|
59
|
-
|
60
|
-
assert_equal 0, c1 <=> c2
|
61
|
-
assert_equal -1, c1 <=> c3
|
62
|
-
assert_equal 1, c3 <=> c1
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# to_a test
|
67
|
-
#
|
68
|
-
|
69
|
-
def test_to_a_returns_value_uncertainty_array
|
70
|
-
c = Constant.new(1.23)
|
71
|
-
assert_equal [1.23, nil], c.to_a
|
72
|
-
|
73
|
-
c = Constant.new(1.23, nil, 0.03)
|
74
|
-
assert_equal [1.23, 0.03], c.to_a
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
@@ -1,207 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../constants_test_helper.rb')
|
2
|
-
require 'constants/libraries/element'
|
3
|
-
|
4
|
-
class ElementTest < Test::Unit::TestCase
|
5
|
-
include Constants::Libraries
|
6
|
-
|
7
|
-
#
|
8
|
-
# documentation test
|
9
|
-
#
|
10
|
-
|
11
|
-
def test_documentation
|
12
|
-
e = Element::He
|
13
|
-
assert_equal "Helium", e.name
|
14
|
-
assert_equal "He", e.symbol
|
15
|
-
assert_equal 2, e.atomic_number
|
16
|
-
assert_equal 4.0026032497, e.mass
|
17
|
-
assert_equal [3, 4], e.isotopes
|
18
|
-
assert_equal [0.000137, 99.999863], e.abundances
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# initialize test
|
23
|
-
#
|
24
|
-
|
25
|
-
def test_initialize
|
26
|
-
c = Element::C
|
27
|
-
|
28
|
-
assert_equal "C", c.symbol
|
29
|
-
assert_equal "Carbon", c.name
|
30
|
-
assert_equal 6, c.atomic_number
|
31
|
-
assert_equal [12, 13], c.isotopes
|
32
|
-
assert_equal [[12.0, 0], [13.0033548378, 0.000000001]], c.masses.collect {|m| m.to_a}
|
33
|
-
assert_equal [[98.93, 0.08], [1.07, 0.08]], c.abundances.collect {|m| m.to_a}
|
34
|
-
assert_equal 0, c.index_max_abundance
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# lookup test
|
39
|
-
#
|
40
|
-
|
41
|
-
def test_lookup
|
42
|
-
c = Element::C
|
43
|
-
assert_equal c, Element['C']
|
44
|
-
assert_equal c, Element['Carbon']
|
45
|
-
assert_equal c, Element[6]
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_lookup_is_nil_for_undefined_elements
|
49
|
-
assert_nil Element['Q']
|
50
|
-
assert_nil Element["Madeupium"]
|
51
|
-
assert_nil Element[102]
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# methods test
|
56
|
-
#
|
57
|
-
|
58
|
-
def test_has_isotope?
|
59
|
-
assert Element::C.has_isotope?(12)
|
60
|
-
assert Element::C.has_isotope?(13)
|
61
|
-
assert !Element::C.has_isotope?(8)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_index_isotope
|
65
|
-
assert_equal 0, Element::C.index_isotope(12)
|
66
|
-
assert_equal 1, Element::C.index_isotope(13)
|
67
|
-
assert_equal nil, Element::C.index_isotope(8)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_mass
|
71
|
-
assert_equal 12, Element::C.mass
|
72
|
-
assert_equal 12, Element::C.mass(12)
|
73
|
-
assert_equal 13.0033548378, Element::C.mass(13)
|
74
|
-
assert_equal nil, Element::C.mass(8)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_abundance
|
78
|
-
assert_equal 98.93, Element::C.abundance
|
79
|
-
assert_equal 98.93, Element::C.abundance(12)
|
80
|
-
assert_equal 1.07, Element::C.abundance(13)
|
81
|
-
assert_equal nil, Element::C.abundance(8)
|
82
|
-
end
|
83
|
-
|
84
|
-
# vs the Proteome Commons Atom Reference, 2008-01-11
|
85
|
-
# http://www.proteomecommons.org/archive/1129086318745/docs/atom-reference.html
|
86
|
-
#
|
87
|
-
# The website states 'These values are taken from the NIST's list, http://physics.nist.gov'
|
88
|
-
def test_mass_values_vs_proteome_commons
|
89
|
-
str = %Q{
|
90
|
-
H 1.0078250321 0.999885
|
91
|
-
H2 2.014101778 1.15E-4
|
92
|
-
O 15.9949146221 0.9975700000000001
|
93
|
-
O17 16.9991315 3.7999999999999997E-4
|
94
|
-
O18 17.9991604 0.0020499999999999997
|
95
|
-
N14 14.0030740052 0.9963200000000001
|
96
|
-
N15 15.0001088984 0.00368
|
97
|
-
C12 12.0 0.9893000000000001
|
98
|
-
C13 13.0033548378 0.010700000000000001
|
99
|
-
P31 30.97376151 1.0
|
100
|
-
S32 31.97207069 0.9493
|
101
|
-
S33 32.9714585 0.0076
|
102
|
-
S34 33.96786683 0.0429
|
103
|
-
S36 35.96708088 2.0E-4}
|
104
|
-
|
105
|
-
atoms = str.split(/\n/)
|
106
|
-
atoms.each do |atom_str|
|
107
|
-
next if atom_str.empty?
|
108
|
-
|
109
|
-
name, mass, abundance = atom_str.split(/\s+/)
|
110
|
-
name =~ /(\w)(\d*)/
|
111
|
-
symbol = $1
|
112
|
-
isotope = $2.empty? ? nil : $2.to_i
|
113
|
-
mass = mass.to_f
|
114
|
-
abundance = abundance.to_f * 100
|
115
|
-
|
116
|
-
element = Element[symbol]
|
117
|
-
assert_not_nil element, atom_str
|
118
|
-
assert element.has_isotope?(isotope), atom_str unless isotope == nil
|
119
|
-
|
120
|
-
assert_in_delta mass, element.mass(isotope), delta_mass, atom_str
|
121
|
-
assert_in_delta abundance, element.abundance(isotope), delta_abundance, atom_str
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# vs the Unimod Symbols and Mass Values, 2008-01-11
|
126
|
-
# http://www.unimod.org/masses.html
|
127
|
-
#
|
128
|
-
# The website states 'All mass values in Unimod are calculated
|
129
|
-
# from the IUPAC atomic weights and isotopic abundances
|
130
|
-
# tabulated by WebElements'
|
131
|
-
#
|
132
|
-
def test_mass_values_vs_unimod
|
133
|
-
str = %Q{
|
134
|
-
H Hydrogen 1.007825035 1.00794
|
135
|
-
2H Deuterium 2.014101779 2.014101779
|
136
|
-
Li Lithium 7.016003 6.941
|
137
|
-
C Carbon 12 12.0107
|
138
|
-
13C Carbon13 13.00335483 13.00335483
|
139
|
-
N Nitrogen 14.003074 14.0067
|
140
|
-
15N Nitrogen15 15.00010897 15.00010897
|
141
|
-
O Oxygen 15.99491463 15.9994
|
142
|
-
18O Oxygen18 17.9991603 17.9991603
|
143
|
-
F Fluorine 18.99840322 18.9984032
|
144
|
-
Na Sodium 22.9897677 22.98977
|
145
|
-
P Phosphorous 30.973762 30.973761
|
146
|
-
S Sulfur 31.9720707 32.065
|
147
|
-
Cl Chlorine 34.96885272 35.453
|
148
|
-
K Potassium 38.9637074 39.0983
|
149
|
-
Ca Calcium 39.9625906 40.078
|
150
|
-
Fe Iron 55.9349393 55.845
|
151
|
-
Ni Nickel 57.9353462 58.6934
|
152
|
-
Cu Copper 62.9295989 63.546
|
153
|
-
Zn Zinc 63.9291448 65.409
|
154
|
-
Br Bromine 78.9183361 79.904
|
155
|
-
Se Selenium 79.9165196 78.96
|
156
|
-
Mo Molybdenum 97.9054073 95.94
|
157
|
-
Ag Silver 106.905092 107.8682
|
158
|
-
I Iodine 126.904473 126.90447
|
159
|
-
Au Gold 196.966543 196.96655
|
160
|
-
Hg Mercury 201.970617 200.59}
|
161
|
-
|
162
|
-
atoms = str.split(/\n/)
|
163
|
-
atoms.each do |atom_str|
|
164
|
-
next if atom_str.empty?
|
165
|
-
|
166
|
-
symbol, name, monoisotopic, average = atom_str.split(/\s+/)
|
167
|
-
symbol =~ /(\d*)(\w+)/
|
168
|
-
isotope = $1.empty? ? nil : $1.to_i
|
169
|
-
symbol = $2
|
170
|
-
monoisotopic = monoisotopic.to_f
|
171
|
-
average = average.to_f
|
172
|
-
|
173
|
-
element = Element[symbol]
|
174
|
-
assert_not_nil element, atom_str
|
175
|
-
assert element.has_isotope?(isotope), atom_str unless isotope == nil
|
176
|
-
|
177
|
-
assert_in_delta monoisotopic, element.mass(isotope), delta_mass, atom_str
|
178
|
-
# TODO -- check average mass
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# vs the VG Analytical Organic Mass Spectrometry reference, reference date unknown (prior to 2005)
|
183
|
-
# the data from the data sheet was copied manually to doc/VG Analytical DataSheet.txt
|
184
|
-
def test_mass_values_vs_vg_analytical
|
185
|
-
str = %Q{
|
186
|
-
H 1.0078250 1.00794
|
187
|
-
C 12 12.011
|
188
|
-
N 14.0030740 14.0067
|
189
|
-
O 15.9949146 15.9994
|
190
|
-
S 31.9720718 32.06}
|
191
|
-
|
192
|
-
atoms = str.split(/\n/)
|
193
|
-
atoms.each do |atom_str|
|
194
|
-
next if atom_str.empty?
|
195
|
-
|
196
|
-
symbol, monoisotopic, average = atom_str.split(/\s+/)
|
197
|
-
monoisotopic = monoisotopic.to_f
|
198
|
-
average = average.to_f
|
199
|
-
|
200
|
-
element = Element[symbol]
|
201
|
-
assert_not_nil element, atom_str
|
202
|
-
assert_in_delta monoisotopic, element.mass, delta_mass, atom_str
|
203
|
-
# TODO -- check average mass
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../constants_test_helper.rb')
|
2
|
-
require 'constants/libraries/particle'
|
3
|
-
|
4
|
-
class ParticleTest < Test::Unit::TestCase
|
5
|
-
include Constants::Libraries
|
6
|
-
|
7
|
-
#
|
8
|
-
# initialize test
|
9
|
-
#
|
10
|
-
|
11
|
-
def test_initialize
|
12
|
-
c = Particle::CHARM
|
13
|
-
|
14
|
-
assert_equal "Charm", c.name
|
15
|
-
assert_equal "Fermion", c.family
|
16
|
-
assert_equal "Quark", c.group
|
17
|
-
assert_equal "Second", c.generation
|
18
|
-
assert_equal 2.0/3, c.charge
|
19
|
-
assert_equal 0.5, c.spin
|
20
|
-
|
21
|
-
t = Particle::ANTITAU
|
22
|
-
|
23
|
-
assert_equal "Anti-Tau", t.name
|
24
|
-
assert_equal "Fermion", t.family
|
25
|
-
assert_equal "Lepton", t.group
|
26
|
-
assert_equal "Third", t.generation
|
27
|
-
assert_equal -1, t.charge
|
28
|
-
assert_equal 0.5, t.spin
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# lookup test
|
33
|
-
#
|
34
|
-
|
35
|
-
def test_lookup
|
36
|
-
c = Particle::CHARM
|
37
|
-
assert_equal c, Particle['Charm']
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_lookup_is_nil_for_undefined_particles
|
41
|
-
assert_nil Particle['Blop']
|
42
|
-
end
|
43
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../../constants_test_helper.rb')
|
2
|
-
require 'constants/libraries/physical'
|
3
|
-
|
4
|
-
class PhysicalTest < Test::Unit::TestCase
|
5
|
-
include Constants::Libraries
|
6
|
-
|
7
|
-
#
|
8
|
-
# initialize test
|
9
|
-
#
|
10
|
-
|
11
|
-
def test_initialize
|
12
|
-
c = Physical::SPEED_OF_LIGHT_IN_VACUUM
|
13
|
-
|
14
|
-
assert_equal "speed of light in vacuum", c.name
|
15
|
-
assert_equal 299792458, c.value
|
16
|
-
assert_equal 0, c.uncertainty
|
17
|
-
assert_equal Unit.new("m/s"), c.unit
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# lookup test
|
22
|
-
#
|
23
|
-
|
24
|
-
def test_lookup
|
25
|
-
c = Physical::SPEED_OF_LIGHT_IN_VACUUM
|
26
|
-
assert_equal c, Physical["speed of light in vacuum"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_lookup_is_nil_for_undefined_constants
|
30
|
-
assert_nil Physical["made up blah in a blah"]
|
31
|
-
end
|
32
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../constants_test_helper.rb')
|
2
|
-
require 'constants/library'
|
3
|
-
|
4
|
-
class Constants::LibraryTest < Test::Unit::TestCase
|
5
|
-
include Constants
|
6
|
-
|
7
|
-
#
|
8
|
-
# documentation test
|
9
|
-
#
|
10
|
-
|
11
|
-
module Color
|
12
|
-
RED = 'red'
|
13
|
-
GREEN = 'green'
|
14
|
-
BLUE = 'blue'
|
15
|
-
GREY = 'grey'
|
16
|
-
|
17
|
-
include Constants::Library
|
18
|
-
library.index_by('name') {|c| c }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_documentation
|
22
|
-
###
|
23
|
-
assert_equal({
|
24
|
-
'red' => Color::RED,
|
25
|
-
'blue' => Color::BLUE,
|
26
|
-
'green' => Color::GREEN,
|
27
|
-
'grey' => Color::GREY},
|
28
|
-
Color.index('name'))
|
29
|
-
|
30
|
-
assert_equal Color::RED, Color['red']
|
31
|
-
|
32
|
-
###
|
33
|
-
Color.library.index_by_attribute 'length'
|
34
|
-
const_ordered_assert_equal({
|
35
|
-
3 => Color::RED,
|
36
|
-
4 => [Color::BLUE, Color::GREY],
|
37
|
-
5 => Color::GREEN},
|
38
|
-
Color.index('length'))
|
39
|
-
|
40
|
-
const_ordered_assert_equal [Color::BLUE, Color::GREY], Color[4]
|
41
|
-
|
42
|
-
###
|
43
|
-
Color.library.collect('gstar') {|c| c =~ /^g/ ? c : nil }
|
44
|
-
const_ordered_assert_equal [Color::GREEN, Color::GREY], Color.collection('gstar')
|
45
|
-
|
46
|
-
Color.library.collect_attribute 'length'
|
47
|
-
const_ordered_assert_equal [3,5,4,4], Color.collection('length')
|
48
|
-
|
49
|
-
###
|
50
|
-
Color.library.add('yellow')
|
51
|
-
const_ordered_assert_equal({
|
52
|
-
3 => Color::RED,
|
53
|
-
4 => [Color::BLUE, Color::GREY],
|
54
|
-
5 => Color::GREEN,
|
55
|
-
6 => 'yellow'},
|
56
|
-
Color.index('length'))
|
57
|
-
|
58
|
-
Color.module_eval %Q{
|
59
|
-
ORANGE = 'orange'
|
60
|
-
reset_library
|
61
|
-
}
|
62
|
-
|
63
|
-
const_ordered_assert_equal({
|
64
|
-
3 => Color::RED,
|
65
|
-
4 => [Color::BLUE, Color::GREY],
|
66
|
-
5 => Color::GREEN,
|
67
|
-
6 => Color::ORANGE},
|
68
|
-
Color.index('length'))
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# extend test
|
73
|
-
#
|
74
|
-
|
75
|
-
module ExtendModule
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_extend_initializes_library
|
79
|
-
ExtendModule.extend Library
|
80
|
-
assert ExtendModule.respond_to?(:library)
|
81
|
-
assert ExtendModule.library.kind_of?(ConstantLibrary)
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# include test
|
86
|
-
#
|
87
|
-
|
88
|
-
module IncludeModule
|
89
|
-
include Constants::Library
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_include_initializes_library
|
93
|
-
assert IncludeModule.respond_to?(:library)
|
94
|
-
assert IncludeModule.library.kind_of?(ConstantLibrary)
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# benchmark tests
|
99
|
-
#
|
100
|
-
|
101
|
-
module BenchmarkModule
|
102
|
-
include Constants::Library
|
103
|
-
A = 'A'
|
104
|
-
|
105
|
-
library.index_by("name") {|value| value}
|
106
|
-
reset_library
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_access_speed
|
110
|
-
benchmark_test(24) do |x|
|
111
|
-
n = 100
|
112
|
-
x.report("#{n}k BenchmarkModule::A") do
|
113
|
-
(n*10**3).times { BenchmarkModule::A }
|
114
|
-
end
|
115
|
-
|
116
|
-
x.report("#{n}k ['A']") do
|
117
|
-
(n*10**3).times { BenchmarkModule['A'] }
|
118
|
-
end
|
119
|
-
|
120
|
-
x.report("#{n}k index('name')['A']") do
|
121
|
-
(n*10**3).times { BenchmarkModule.index('name')['A'] }
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../constants_test_helper.rb')
|
2
|
-
require 'constants/stash'
|
3
|
-
|
4
|
-
class StashTest < Test::Unit::TestCase
|
5
|
-
include Constants
|
6
|
-
|
7
|
-
class StashingHash < Hash
|
8
|
-
include Constants::Stash
|
9
|
-
|
10
|
-
def initialize(*args)
|
11
|
-
super(*args)
|
12
|
-
@nil_value = nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_reader :s
|
17
|
-
|
18
|
-
def setup
|
19
|
-
@s = StashingHash.new
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# documentation test
|
24
|
-
#
|
25
|
-
|
26
|
-
def test_documentation
|
27
|
-
s = StashingHash.new
|
28
|
-
|
29
|
-
s.stash('key', 'one')
|
30
|
-
assert_equal 'one', s['key']
|
31
|
-
|
32
|
-
s.stash('key', 'two')
|
33
|
-
assert_equal ['one' , 'two'], s['key']
|
34
|
-
assert_equal Constants::Stash::StashArray, s['key'].class
|
35
|
-
|
36
|
-
###
|
37
|
-
s = StashingHash.new
|
38
|
-
assert_nil s['key']
|
39
|
-
assert_nil s.nil_value
|
40
|
-
|
41
|
-
s.stash('key', 1)
|
42
|
-
assert_equal 1, s['key']
|
43
|
-
|
44
|
-
s.stash('key', 2)
|
45
|
-
assert_equal [1, 2], s['key']
|
46
|
-
|
47
|
-
###
|
48
|
-
assert_raise(ArgumentError) { s.stash('key', nil) }
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# initialization test
|
53
|
-
#
|
54
|
-
|
55
|
-
def test_initialization_sets_nil_value
|
56
|
-
s = StashingHash.new
|
57
|
-
assert_equal({}, s)
|
58
|
-
assert_equal(nil, s.nil_value)
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# stash test
|
63
|
-
#
|
64
|
-
|
65
|
-
def test_stash_stores_new_values_at_key
|
66
|
-
s.stash('key', 'one')
|
67
|
-
assert_equal({'key' => 'one'}, s)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_stash_stores_addition_values_in_a_StashArray
|
71
|
-
s.stash('key', 'one')
|
72
|
-
s.stash('key', 'two')
|
73
|
-
s.stash('key', 'three')
|
74
|
-
|
75
|
-
assert_equal({'key' => ['one', 'two', 'three']}, s)
|
76
|
-
assert_equal Constants::Stash::StashArray, s['key'].class
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_stash_handles_array_values_properly
|
80
|
-
s.stash('key', ['one'])
|
81
|
-
assert_equal({'key' => ['one']}, s)
|
82
|
-
|
83
|
-
s.stash('key', ['two'])
|
84
|
-
assert_equal({'key' => [['one'], ['two']]}, s)
|
85
|
-
|
86
|
-
s.stash('key', ['three'])
|
87
|
-
assert_equal({'key' => [['one'], ['two'], ['three']]}, s)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_stash_raises_error_for_nil_value_and_StashArray_values
|
91
|
-
assert_raise(ArgumentError) { s.stash('key', s.nil_value) }
|
92
|
-
assert_raise(ArgumentError) { s.stash('key', Stash::StashArray.new) }
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_stash_returns_self
|
96
|
-
assert_equal s, s.stash('key', 'value')
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'benchmark'
|
4
|
-
require 'pp'
|
5
|
-
|
6
|
-
class Test::Unit::TestCase
|
7
|
-
include Benchmark
|
8
|
-
|
9
|
-
#
|
10
|
-
# mass tests
|
11
|
-
#
|
12
|
-
|
13
|
-
def delta_mass
|
14
|
-
10**-5
|
15
|
-
end
|
16
|
-
|
17
|
-
def delta_abundance
|
18
|
-
10**-1
|
19
|
-
end
|
20
|
-
|
21
|
-
def benchmark_test(length=10, &block)
|
22
|
-
if ENV["benchmark"] =~ /true/i
|
23
|
-
puts
|
24
|
-
puts method_name
|
25
|
-
bm(length, &block)
|
26
|
-
else
|
27
|
-
print 'b'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def const_ordered_assert_equal(a,b, msg=nil)
|
32
|
-
if RUBY_VERSION =~ /^1.8/
|
33
|
-
print "*"
|
34
|
-
|
35
|
-
case a
|
36
|
-
when Array
|
37
|
-
assert_equal a.sort, b.sort, msg
|
38
|
-
when Hash
|
39
|
-
[a,b].each do |hash|
|
40
|
-
hash.each_pair do |key, value|
|
41
|
-
value.sort! if value.kind_of?(Array)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
assert_equal a, b, msg
|
45
|
-
end
|
46
|
-
else
|
47
|
-
assert_equal a, b, msg
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
data/test/readme_doc_test.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'constants_test_helper.rb')
|
2
|
-
require 'constants'
|
3
|
-
|
4
|
-
class ReadMeDocTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include Constants::Libraries
|
7
|
-
|
8
|
-
# A library of amino acid residues.
|
9
|
-
class Residue
|
10
|
-
attr_reader :letter, :abbr, :name
|
11
|
-
|
12
|
-
def initialize(letter, abbr, name)
|
13
|
-
@letter = letter
|
14
|
-
@abbr = abbr
|
15
|
-
@name = name
|
16
|
-
end
|
17
|
-
|
18
|
-
A = Residue.new('A', "Ala", "Alanine")
|
19
|
-
C = Residue.new('C', "Cys", "Cysteine")
|
20
|
-
D = Residue.new('D', "Asp", "Aspartic Acid")
|
21
|
-
# ... normally you'd add the rest here ...
|
22
|
-
|
23
|
-
include Constants::Library
|
24
|
-
|
25
|
-
# add an index by an attribute or method
|
26
|
-
library.index_by_attribute :letter
|
27
|
-
|
28
|
-
# add an index where keys are calculated by a block
|
29
|
-
library.index_by 'upcase abbr' do |residue|
|
30
|
-
residue.abbr.upcase
|
31
|
-
end
|
32
|
-
|
33
|
-
# add a collection (same basic idea, but using an array)
|
34
|
-
library.collect_attribute 'name'
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_documentation
|
38
|
-
# Element predefines all chemical elements
|
39
|
-
c = Element::C
|
40
|
-
assert_equal "Carbon", c.name
|
41
|
-
assert_equal "C", c.symbol
|
42
|
-
assert_equal 6, c.atomic_number
|
43
|
-
assert_equal 12.0, c.mass
|
44
|
-
assert_equal 13.0033548378, c.mass(13)
|
45
|
-
|
46
|
-
assert c == Element['Carbon']
|
47
|
-
assert c == Element['C']
|
48
|
-
assert c == Element[6]
|
49
|
-
|
50
|
-
###
|
51
|
-
assert_equal Residue::D, Residue['D']
|
52
|
-
assert_equal Residue::A, Residue['ALA']
|
53
|
-
|
54
|
-
assert_equal({'ALA' => Residue::A, 'CYS' => Residue::C, 'ASP' => Residue::D}, Residue.index('upcase abbr'))
|
55
|
-
const_ordered_assert_equal(["Alanine", "Cysteine", "Aspartic Acid"], Residue.collection('name'))
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|