taxonifi 0.1.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/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +155 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/assessor/assessor.rb +31 -0
- data/lib/assessor/base.rb +17 -0
- data/lib/assessor/row_assessor.rb +131 -0
- data/lib/export/export.rb +9 -0
- data/lib/export/format/base.rb +43 -0
- data/lib/export/format/species_file.rb +341 -0
- data/lib/lumper/lumper.rb +334 -0
- data/lib/lumper/lumps/parent_child_name_collection.rb +84 -0
- data/lib/models/author_year.rb +39 -0
- data/lib/models/base.rb +73 -0
- data/lib/models/collection.rb +92 -0
- data/lib/models/generic_object.rb +15 -0
- data/lib/models/geog.rb +59 -0
- data/lib/models/geog_collection.rb +28 -0
- data/lib/models/name.rb +206 -0
- data/lib/models/name_collection.rb +149 -0
- data/lib/models/person.rb +49 -0
- data/lib/models/ref.rb +85 -0
- data/lib/models/ref_collection.rb +106 -0
- data/lib/models/species_name.rb +85 -0
- data/lib/splitter/builder.rb +26 -0
- data/lib/splitter/lexer.rb +70 -0
- data/lib/splitter/parser.rb +54 -0
- data/lib/splitter/splitter.rb +45 -0
- data/lib/splitter/tokens.rb +322 -0
- data/lib/taxonifi.rb +36 -0
- data/test/file_fixtures/Lygaeoidea.csv +801 -0
- data/test/helper.rb +38 -0
- data/test/test_exporter.rb +32 -0
- data/test/test_lumper_geogs.rb +59 -0
- data/test/test_lumper_hierarchical_collection.rb +88 -0
- data/test/test_lumper_names.rb +119 -0
- data/test/test_lumper_parent_child_name_collection.rb +41 -0
- data/test/test_lumper_refs.rb +91 -0
- data/test/test_parser.rb +34 -0
- data/test/test_splitter.rb +27 -0
- data/test/test_splitter_tokens.rb +403 -0
- data/test/test_taxonifi.rb +11 -0
- data/test/test_taxonifi_accessor.rb +61 -0
- data/test/test_taxonifi_geog.rb +51 -0
- data/test/test_taxonifi_name.rb +186 -0
- data/test/test_taxonifi_name_collection.rb +158 -0
- data/test/test_taxonifi_ref.rb +90 -0
- data/test/test_taxonifi_ref_collection.rb +69 -0
- data/test/test_taxonifi_species_name.rb +95 -0
- metadata +167 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/name'))
|
3
|
+
|
4
|
+
class TestTaxonifiName < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_truth
|
7
|
+
assert(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_new_name
|
11
|
+
assert n = Taxonifi::Model::Name.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_name_has_a_name
|
15
|
+
n = Taxonifi::Model::Name.new()
|
16
|
+
assert n.respond_to?(:name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_name_has_an_id
|
20
|
+
n = Taxonifi::Model::Name.new()
|
21
|
+
assert n.respond_to?(:id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_that_name_has_a_parent
|
25
|
+
n = Taxonifi::Model::Name.new()
|
26
|
+
assert n.respond_to?(:parent)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_that_name_has_a_rank
|
30
|
+
n = Taxonifi::Model::Name.new()
|
31
|
+
assert n.respond_to?(:rank)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_that_name_has_an_author
|
35
|
+
n = Taxonifi::Model::Name.new()
|
36
|
+
assert n.respond_to?(:author)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_that_name_has_a_year
|
40
|
+
n = Taxonifi::Model::Name.new()
|
41
|
+
assert n.respond_to?(:year)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_that_name_returns_false_with_bad_rank
|
45
|
+
n = Taxonifi::Model::Name.new()
|
46
|
+
assert_raise Taxonifi::NameError do
|
47
|
+
n.rank = "FOO"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_that_name_allows_legal_rank
|
52
|
+
n = Taxonifi::Model::Name.new()
|
53
|
+
assert n.rank = "genus"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_that_name_rank_is_case_insensitive
|
57
|
+
n = Taxonifi::Model::Name.new()
|
58
|
+
assert n.rank = "Genus"
|
59
|
+
assert n.rank = "GENUS"
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_that_rank_is_required_before_parent
|
63
|
+
n = Taxonifi::Model::Name.new()
|
64
|
+
assert_raise Taxonifi::NameError do
|
65
|
+
n.parent = Taxonifi::Model::Name.new()
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_that_parent_is_a_taxonifi_name
|
70
|
+
n = Taxonifi::Model::Name.new()
|
71
|
+
n.rank = "genus" # avoid that raise
|
72
|
+
assert_raise Taxonifi::NameError do
|
73
|
+
n.parent = "foo"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_that_rank_can_be_set
|
78
|
+
n = Taxonifi::Model::Name.new()
|
79
|
+
n.rank = "family"
|
80
|
+
assert_equal "family", n.rank
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def test_that_parent_is_higher_rank_than_child
|
85
|
+
n = Taxonifi::Model::Name.new()
|
86
|
+
n.rank = "genus"
|
87
|
+
p = Taxonifi::Model::Name.new()
|
88
|
+
p.rank = "species"
|
89
|
+
assert_raise Taxonifi::NameError do
|
90
|
+
n.parent = p
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_that_parent_can_be_set
|
95
|
+
n = Taxonifi::Model::Name.new()
|
96
|
+
n.rank = "genus"
|
97
|
+
p = Taxonifi::Model::Name.new()
|
98
|
+
p.rank = "species"
|
99
|
+
assert p.parent = n
|
100
|
+
assert_equal "genus", p.parent.rank
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_that_attributes_can_be_assigned_on_new
|
104
|
+
n0 = Taxonifi::Model::Name.new(:name => "Baridae", :rank => "Family")
|
105
|
+
n = Taxonifi::Model::Name.new(:name => "Foo", :rank => "Genus", :author => "Frank", :year => 2020, :parent => n0)
|
106
|
+
assert_equal "Foo", n.name
|
107
|
+
assert_equal "genus", n.rank
|
108
|
+
assert_equal 2020, n.year
|
109
|
+
assert_equal "Frank", n.author
|
110
|
+
assert_equal n0, n.parent
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_a_few_names
|
114
|
+
@n0 = Taxonifi::Model::Name.new(:name => "Baridae", :rank => "Family", :id => 2)
|
115
|
+
@n1 = Taxonifi::Model::Name.new(:name => "Barinae", :rank => "Subfamily", :id => 15, :parent => @n0)
|
116
|
+
@n2 = Taxonifi::Model::Name.new(:name => "Foo", :rank => "Genus", :author => "Frank", :year => 2020, :id => 14, :parent => @n1 )
|
117
|
+
@n3 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "Subgenus", :author => "Frank", :year => 2020, :id => 19, :parent => @n2 )
|
118
|
+
@n4 = Taxonifi::Model::Name.new(:name => "boo", :rank => "Species", :author => "Frank", :year => 2020, :id => 11, :parent => @n3 )
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_ancestors
|
122
|
+
create_a_few_names
|
123
|
+
assert_equal [@n0, @n1], @n2.ancestors
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_ancestor_ids
|
127
|
+
create_a_few_names
|
128
|
+
assert_equal [2,15], @n2.ancestor_ids
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_parent_ids_sf_style
|
132
|
+
create_a_few_names
|
133
|
+
assert_equal '2-15-14g-19s-11', @n4.parent_ids_sf_style
|
134
|
+
assert_equal '2-15-14g-19s', @n3.parent_ids_sf_style
|
135
|
+
assert_equal '2-15-14g', @n2.parent_ids_sf_style
|
136
|
+
assert_equal '2-15', @n1.parent_ids_sf_style
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_author_year_index
|
140
|
+
n = Taxonifi::Model::Name.new(author_year: 'Smith and Jones, 1920')
|
141
|
+
assert_equal '1920-||smith|-||jones|', n.author_year_index
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# ICZN Subclass
|
146
|
+
#
|
147
|
+
|
148
|
+
def test_that_iczn_family_ends_in_idae
|
149
|
+
n = Taxonifi::Model::IcznName.new
|
150
|
+
assert_raise Taxonifi::NameError do
|
151
|
+
n.rank = "family"
|
152
|
+
n.name = "Foo"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_that_iczn_subfamily_ends_in_inae
|
157
|
+
n = Taxonifi::Model::IcznName.new
|
158
|
+
assert_raise Taxonifi::NameError do
|
159
|
+
n.rank = "subfamily"
|
160
|
+
n.name = "Foo"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_that_iczn_tribe_ends_in_ini
|
165
|
+
n = Taxonifi::Model::IcznName.new
|
166
|
+
assert_raise Taxonifi::NameError do
|
167
|
+
n.rank = "tribe"
|
168
|
+
n.name = "Foo"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_that_iczn_subtribe_ends_in_ina
|
173
|
+
n = Taxonifi::Model::IcznName.new
|
174
|
+
assert_raise Taxonifi::NameError do
|
175
|
+
n.rank = "subtribe"
|
176
|
+
n.name = "Foo"
|
177
|
+
end
|
178
|
+
|
179
|
+
assert n.name = "Fooina"
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/name_collection'))
|
3
|
+
|
4
|
+
class TestTaxonifiNameCollection < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_add_objects_adds_to_collection
|
7
|
+
c = Taxonifi::Model::NameCollection.new
|
8
|
+
n = Taxonifi::Model::Name.new
|
9
|
+
assert c.add_object(n)
|
10
|
+
assert_equal(1, c.collection.size)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_name_collections_have_collections
|
14
|
+
c = Taxonifi::Model::NameCollection.new
|
15
|
+
assert c.respond_to?(:collection)
|
16
|
+
assert_equal([], c.collection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_name_collection_returns_encompassing_rank
|
20
|
+
c = Taxonifi::Model::NameCollection.new
|
21
|
+
n = Taxonifi::Model::Name.new
|
22
|
+
n.rank = 'species'
|
23
|
+
c.add_object(n)
|
24
|
+
assert_equal 'subgenus', c.encompassing_rank
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_names_at_rank_returns_names
|
28
|
+
c = Taxonifi::Model::NameCollection.new
|
29
|
+
n = Taxonifi::Model::Name.new
|
30
|
+
n.rank = 'species'
|
31
|
+
c.add_object(n)
|
32
|
+
|
33
|
+
n1 = Taxonifi::Model::Name.new
|
34
|
+
n1.rank = 'species'
|
35
|
+
c.add_object(n1)
|
36
|
+
|
37
|
+
assert_equal 2, c.names_at_rank('species').size
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_that_add_objects_tests_for_existing_name_id_and_raises
|
41
|
+
c = Taxonifi::Model::NameCollection.new
|
42
|
+
n = Taxonifi::Model::Name.new
|
43
|
+
n.rank = 'species'
|
44
|
+
n.id = 1
|
45
|
+
assert_raise Taxonifi::CollectionError do
|
46
|
+
c.add_object(n)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_that_current_free_id_is_incremented
|
51
|
+
c = Taxonifi::Model::NameCollection.new
|
52
|
+
n = Taxonifi::Model::Name.new
|
53
|
+
assert_equal 0, c.current_free_id
|
54
|
+
c.add_object(n)
|
55
|
+
assert_equal 1, c.current_free_id
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_that_by_id_index_is_built
|
59
|
+
c = Taxonifi::Model::NameCollection.new
|
60
|
+
n = Taxonifi::Model::Name.new
|
61
|
+
assert_equal 0, c.current_free_id
|
62
|
+
c.add_object(n)
|
63
|
+
assert_equal ({0 => n}), c.by_id_index
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_that_object_by_id_returns
|
67
|
+
c = Taxonifi::Model::NameCollection.new
|
68
|
+
n = Taxonifi::Model::Name.new
|
69
|
+
n.rank = 'species'
|
70
|
+
id = c.add_object(n).id
|
71
|
+
assert_equal id, c.object_by_id(id).id
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_that_parent_id_vector_returns_a_id_vector
|
75
|
+
c = Taxonifi::Model::NameCollection.new
|
76
|
+
|
77
|
+
n1 = Taxonifi::Model::Name.new(:name => "Fooidae", :rank => "family")
|
78
|
+
n2 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "genus")
|
79
|
+
n3 = Taxonifi::Model::Name.new(:name => "blorf", :rank => "species")
|
80
|
+
|
81
|
+
assert_equal "family", n1.rank
|
82
|
+
assert_equal "genus", n2.rank
|
83
|
+
assert_equal "species", n3.rank
|
84
|
+
|
85
|
+
c.add_object(n1)
|
86
|
+
c.add_object(n2)
|
87
|
+
c.add_object(n3)
|
88
|
+
|
89
|
+
assert_equal 0, n1.id
|
90
|
+
assert_equal 1, n2.id
|
91
|
+
assert_equal 2, n3.id
|
92
|
+
|
93
|
+
|
94
|
+
n3.parent = n2
|
95
|
+
n2.parent = n1
|
96
|
+
|
97
|
+
# c.object_by_id(2).parent = c.object_by_id(1)
|
98
|
+
# c.object_by_id(1).parent = c.object_by_id(0)
|
99
|
+
|
100
|
+
assert_equal [0,1], c.parent_id_vector(2)
|
101
|
+
assert_equal [0], c.parent_id_vector(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_that_name_collection_indexes_by_name_as_well_as_id
|
105
|
+
c = Taxonifi::Model::NameCollection.new
|
106
|
+
n1 = Taxonifi::Model::Name.new(:name => "Fooidae", :rank => "family")
|
107
|
+
c.add_object(n1)
|
108
|
+
assert_equal "Fooidae", c.by_name_index['family'].keys.first
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_name_exists?
|
112
|
+
c = Taxonifi::Model::NameCollection.new
|
113
|
+
n1 = Taxonifi::Model::Name.new(:name => "Fooidae", :rank => "family")
|
114
|
+
n2 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "genus", :parent => n1)
|
115
|
+
n3 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "genus", :parent => n1)
|
116
|
+
n4 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "subgenus", :parent => n2)
|
117
|
+
n5 = Taxonifi::Model::Name.new(:name => "foo", :rank => "species", :parent => n2)
|
118
|
+
n6 = Taxonifi::Model::Name.new(:name => "foo", :rank => "species", :parent => n2)
|
119
|
+
c.add_object(n1)
|
120
|
+
c.add_object(n2)
|
121
|
+
c.add_object(n5)
|
122
|
+
assert c.name_exists?(n3), "Name exists, but not caught."
|
123
|
+
assert c.name_exists?(n6), "Name exists, but not caught."
|
124
|
+
assert !c.name_exists?(n4), "Name doesn't exist, but asserted to."
|
125
|
+
assert_equal n2.id, c.name_exists?(n3)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_that_name_collection_generate_ref_collection
|
129
|
+
c = Taxonifi::Model::NameCollection.new
|
130
|
+
c.generate_ref_collection
|
131
|
+
assert rc = c.ref_collection
|
132
|
+
assert_equal Taxonifi::Model::RefCollection, rc.class
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_that_name_collection_populates_ref_collection
|
136
|
+
c = Taxonifi::Model::NameCollection.new
|
137
|
+
n1 = Taxonifi::Model::Name.new(:name => "Fooidae", :rank => "family", :author => "Smith and Jones", :year => 2002)
|
138
|
+
n2 = Taxonifi::Model::Name.new(:name => "Bar", :rank => "genus", :parent => n1)
|
139
|
+
n3 = Taxonifi::Model::Name.new(:name => "foo", :rank => "species", :parent => n2, :author => "Smith, Jones and Simon", :year => 2012)
|
140
|
+
n4 = Taxonifi::Model::Name.new(:name => "bar", :rank => "species", :parent => n2, :author => "Jones", :year => 2011)
|
141
|
+
n5 = Taxonifi::Model::Name.new(:name => "blorf", :rank => "species", :parent => n2, :author => "Jones", :year => 2011)
|
142
|
+
|
143
|
+
[n1,n2,n3,n4].each do |n|
|
144
|
+
c.add_object(n)
|
145
|
+
end
|
146
|
+
|
147
|
+
c.generate_ref_collection
|
148
|
+
assert_equal 3, c.ref_collection.collection.size
|
149
|
+
# References are sorted
|
150
|
+
assert_equal ['Jones'], c.ref_collection.collection.first.authors.collect{|r| r.last_name}
|
151
|
+
assert_equal ['Smith', 'Jones'], c.ref_collection.collection[1].authors.collect{|r| r.last_name}
|
152
|
+
assert_equal ['Smith', 'Jones', 'Simon'], c.ref_collection.collection.last.authors.collect{|r| r.last_name}
|
153
|
+
assert_equal 2011, c.ref_collection.collection.first.year
|
154
|
+
foo = 1
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/ref'))
|
3
|
+
|
4
|
+
class TestTaxonifiRef < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_new_ref
|
7
|
+
assert n = Taxonifi::Model::Ref.new()
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_that_a_ref_has_authors
|
11
|
+
n = Taxonifi::Model::Ref.new()
|
12
|
+
assert n.respond_to?(:authors)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_that_a_ref_has_title
|
16
|
+
n = Taxonifi::Model::Ref.new()
|
17
|
+
assert n.respond_to?(:title)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_a_ref_has_year
|
21
|
+
n = Taxonifi::Model::Ref.new()
|
22
|
+
assert n.respond_to?(:year)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_that_a_ref_has_publication
|
26
|
+
n = Taxonifi::Model::Ref.new()
|
27
|
+
assert n.respond_to?(:publication)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_that_a_ref_has_volume_year
|
31
|
+
n = Taxonifi::Model::Ref.new()
|
32
|
+
assert n.respond_to?(:volume)
|
33
|
+
assert n.respond_to?(:year)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_that_a_ref_has_page_fields
|
37
|
+
n = Taxonifi::Model::Ref.new()
|
38
|
+
assert n.respond_to?(:pg_start)
|
39
|
+
assert n.respond_to?(:pg_end)
|
40
|
+
assert n.respond_to?(:pages)
|
41
|
+
assert n.respond_to?(:cited_page)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_a_ref
|
45
|
+
@ref = Taxonifi::Model::Ref.new(
|
46
|
+
:authors => [Taxonifi::Model::Person.new(:last_name => "Foo", :initials => "AC")],
|
47
|
+
:year => 2012,
|
48
|
+
:title => "Place to be",
|
49
|
+
:publication => "Journal Du Jour",
|
50
|
+
:pg_start => 1,
|
51
|
+
:pg_end => 2,
|
52
|
+
:volume => 3,
|
53
|
+
:number => 4
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_identical?
|
58
|
+
create_a_ref
|
59
|
+
foo = @ref.clone
|
60
|
+
bar = @ref.clone
|
61
|
+
assert foo.identical?(bar)
|
62
|
+
bar.title = "Foo"
|
63
|
+
assert !foo.identical?(bar)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_that_ref_assigns_passed_options
|
67
|
+
create_a_ref
|
68
|
+
assert_equal "Place to be", @ref.title
|
69
|
+
assert_equal 4, @ref.number
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_that_compact_string_is_compact
|
73
|
+
create_a_ref
|
74
|
+
assert_equal '|ac|foo||2012|placetobe|journaldujour|3|4||1|2|', @ref.compact_string
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_that_author_year_strings_translate_to_author_years
|
78
|
+
r = Taxonifi::Model::Ref.new(:author_year => 'Smith and Jones, 1920')
|
79
|
+
assert_equal 2, r.authors.size
|
80
|
+
assert_equal 1920, r.year
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_author_year_index
|
84
|
+
r = Taxonifi::Model::Ref.new(:author_year => 'Smith and Jones, 1920')
|
85
|
+
assert_equal '1920-||smith|-||jones|', r.author_year_index
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/ref_collection'))
|
3
|
+
|
4
|
+
class TestTaxonifiCollection < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_add_objects_adds_refs
|
7
|
+
c = Taxonifi::Model::RefCollection.new
|
8
|
+
n = Taxonifi::Model::Ref.new
|
9
|
+
assert c.add_object(n)
|
10
|
+
assert_equal(1, c.collection.size)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_ref_collections_have_refs
|
14
|
+
c = Taxonifi::Model::RefCollection.new
|
15
|
+
assert c.respond_to?(:collection)
|
16
|
+
assert_equal([], c.collection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_add_objects_tests_for_existing_ref_id_and_raises
|
20
|
+
c = Taxonifi::Model::RefCollection.new
|
21
|
+
n = Taxonifi::Model::Ref.new
|
22
|
+
n.id = 1
|
23
|
+
assert_raise Taxonifi::CollectionError do
|
24
|
+
c.add_object(n)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_that_current_free_id_is_incremented
|
29
|
+
c = Taxonifi::Model::RefCollection.new
|
30
|
+
n = Taxonifi::Model::Ref.new
|
31
|
+
assert_equal 0, c.current_free_id
|
32
|
+
c.add_object(n)
|
33
|
+
assert_equal 1, c.current_free_id
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_that_by_id_index_is_built
|
37
|
+
c = Taxonifi::Model::RefCollection.new
|
38
|
+
n = Taxonifi::Model::Ref.new
|
39
|
+
assert_equal 0, c.current_free_id
|
40
|
+
c.add_object(n)
|
41
|
+
assert_equal ({0 => n}), c.by_id_index
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_that_object_by_id_returns
|
45
|
+
c = Taxonifi::Model::RefCollection.new
|
46
|
+
n = Taxonifi::Model::Ref.new
|
47
|
+
id = c.add_object(n).id
|
48
|
+
assert_equal id, c.object_by_id(id).id
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_uniquify_authors
|
52
|
+
c = Taxonifi::Model::RefCollection.new
|
53
|
+
['Smith, A.R. 1920', 'Jones, A.R. and Smith, A.R. 1940', 'Jones, B. 1999', 'Jones, A. R. 1922', 'Jones, A. R., Smith, A.R. and Frank, A. 1943'].each do |a|
|
54
|
+
n = Taxonifi::Model::Ref.new(:author_year => a)
|
55
|
+
c.add_object(n)
|
56
|
+
end
|
57
|
+
assert_equal 4, c.unique_authors.size
|
58
|
+
assert_not_equal c.collection.first.authors.first, c.collection[1].authors.last
|
59
|
+
c.uniquify_authors(5)
|
60
|
+
assert_equal c.collection.first.authors.first, c.collection[1].authors.last
|
61
|
+
assert_equal c.collection.first.authors.first, c.collection[4].authors[1]
|
62
|
+
assert_equal c.collection[1].authors.first, c.collection[3].authors.first
|
63
|
+
assert_equal 5, c.collection.first.authors.first.id
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/models/species_name'))
|
3
|
+
|
4
|
+
class TestTaxonifiSpeciesName < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_truth
|
7
|
+
assert(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_new_name
|
11
|
+
assert n = Taxonifi::Model::SpeciesName.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_name_has_a_genus
|
15
|
+
assert n = Taxonifi::Model::SpeciesName.new()
|
16
|
+
assert n.respond_to?(:genus)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_that_name_has_a_subgenus
|
20
|
+
assert n = Taxonifi::Model::SpeciesName.new()
|
21
|
+
assert n.respond_to?(:subgenus)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_that_name_has_a_species
|
25
|
+
assert n = Taxonifi::Model::SpeciesName.new()
|
26
|
+
assert n.respond_to?(:species)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_that_name_has_a_sub_species
|
30
|
+
assert n = Taxonifi::Model::SpeciesName.new()
|
31
|
+
assert n.respond_to?(:subspecies)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_that_parent_is_a_taxonifi_name
|
35
|
+
n = Taxonifi::Model::SpeciesName.new()
|
36
|
+
assert_raise Taxonifi::SpeciesNameError do
|
37
|
+
n.parent = "foo"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_that_parent_rank_must_be_higher_than_genus
|
42
|
+
n = Taxonifi::Model::SpeciesName.new()
|
43
|
+
p = Taxonifi::Model::Name.new()
|
44
|
+
p.rank = "species"
|
45
|
+
assert_raise Taxonifi::SpeciesNameError do
|
46
|
+
n.parent = p
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_that_names_are_taxonifi_names
|
51
|
+
p = Taxonifi::Model::Name.new()
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_that_genus_must_be_assigned_before_species
|
55
|
+
n = Taxonifi::Model::Name.new(:rank => 'species', :name => "foo")
|
56
|
+
|
57
|
+
assert_raise Taxonifi::SpeciesNameError do
|
58
|
+
sn = Taxonifi::Model::SpeciesName.new(:species => n)
|
59
|
+
end
|
60
|
+
|
61
|
+
n.rank = 'genus'
|
62
|
+
n.name = 'Foo'
|
63
|
+
|
64
|
+
assert sn = Taxonifi::Model::SpeciesName.new(:genus => n)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_that_species_must_be_assigned_before_subspecies
|
68
|
+
n = Taxonifi::Model::Name.new(:rank => 'subspecies', :name => "foo")
|
69
|
+
g = Taxonifi::Model::Name.new(:rank => 'genus', :name => "species")
|
70
|
+
|
71
|
+
assert_raise Taxonifi::SpeciesNameError do
|
72
|
+
sn = Taxonifi::Model::SpeciesName.new(:subspecies => n, :genus => g)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_display_name_formatting
|
77
|
+
g = Taxonifi::Model::Name.new(:rank => 'genus', :name => "Foo")
|
78
|
+
sg = Taxonifi::Model::Name.new(:rank => 'subgenus', :name => "Bar")
|
79
|
+
s = Taxonifi::Model::Name.new(:rank => 'species', :name => "stuff")
|
80
|
+
ss = Taxonifi::Model::Name.new(:rank => 'subspecies', :name => "things", :author => "Jones", :year => 2012 )
|
81
|
+
|
82
|
+
sn1 = Taxonifi::Model::SpeciesName.new(:genus => g, :species => s)
|
83
|
+
assert_equal "Foo stuff", sn1.display_name
|
84
|
+
|
85
|
+
sn2 = Taxonifi::Model::SpeciesName.new(:genus => g, :subgenus => sg, :species => s)
|
86
|
+
assert_equal "Foo (Bar) stuff", sn2.display_name
|
87
|
+
|
88
|
+
sn3 = Taxonifi::Model::SpeciesName.new(:genus => g, :subgenus => sg, :species => s, :subspecies => ss)
|
89
|
+
assert_equal "Foo (Bar) stuff things Jones, 2012", sn3.display_name
|
90
|
+
|
91
|
+
ss.parens = false
|
92
|
+
assert_equal "Foo (Bar) stuff things (Jones, 2012)", sn3.display_name
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|