caruby-tissue 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/History.txt +4 -0
  2. data/README.md +6 -0
  3. data/lib/catissue/annotation/annotation_class.rb +1 -1
  4. data/lib/catissue/cli/migrate.rb +1 -0
  5. data/lib/catissue/domain/container.rb +13 -8
  6. data/lib/catissue/domain/specimen.rb +9 -3
  7. data/lib/catissue/domain/specimen_event_parameters.rb +1 -8
  8. data/lib/catissue/domain/specimen_requirement.rb +1 -1
  9. data/lib/catissue/domain/storage_container.rb +4 -3
  10. data/lib/catissue/domain/uniquify.rb +82 -0
  11. data/lib/catissue/migration/migrator.rb +15 -7
  12. data/lib/catissue/migration/uniquify.rb +2 -111
  13. data/lib/catissue/util/position.rb +14 -2
  14. data/lib/catissue/version.rb +1 -1
  15. data/test/fixtures/catissue/domain/conf/catissue_override.yaml +9 -0
  16. data/test/fixtures/catissue/extract/conf/scg_extract.yaml +3 -0
  17. data/test/fixtures/catissue/extract/conf/scg_fields.yaml +3 -0
  18. data/test/fixtures/catissue/extract/conf/spc_extract.yaml +3 -0
  19. data/test/fixtures/catissue/extract/conf/spc_fields.yaml +4 -0
  20. data/test/fixtures/lib/catissue/defaults_test_fixture.rb +202 -0
  21. data/test/lib/catissue/database/controlled_values_test.rb +47 -0
  22. data/test/lib/catissue/database/database_test.rb +28 -0
  23. data/test/lib/catissue/domain/address_test.rb +53 -0
  24. data/test/lib/catissue/domain/base_haemotology_pathology_test.rb +25 -0
  25. data/test/lib/catissue/domain/ca_tissue_test_defaults_test.rb +27 -0
  26. data/test/lib/catissue/domain/capacity_test.rb +12 -0
  27. data/test/lib/catissue/domain/collection_event_parameters_test.rb +24 -0
  28. data/test/lib/catissue/domain/collection_protocol_event_test.rb +25 -0
  29. data/test/lib/catissue/domain/collection_protocol_registration_test.rb +71 -0
  30. data/test/lib/catissue/domain/collection_protocol_test.rb +69 -0
  31. data/test/lib/catissue/domain/container_position_test.rb +29 -0
  32. data/test/lib/catissue/domain/department_test.rb +21 -0
  33. data/test/lib/catissue/domain/disposal_event_parameters_test.rb +16 -0
  34. data/test/lib/catissue/domain/location_test.rb +38 -0
  35. data/test/lib/catissue/domain/metadata_test.rb +62 -0
  36. data/test/lib/catissue/domain/participant_medical_identifier_test.rb +26 -0
  37. data/test/lib/catissue/domain/participant_test.rb +96 -0
  38. data/test/lib/catissue/domain/site_test.rb +30 -0
  39. data/test/lib/catissue/domain/specimen_array_test.rb +38 -0
  40. data/test/lib/catissue/domain/specimen_array_type_test.rb +27 -0
  41. data/test/lib/catissue/domain/specimen_characteristics_test.rb +15 -0
  42. data/test/lib/catissue/domain/specimen_collection_group_test.rb +216 -0
  43. data/test/lib/catissue/domain/specimen_event_parameters_test.rb +61 -0
  44. data/test/lib/catissue/domain/specimen_position_test.rb +62 -0
  45. data/test/lib/catissue/domain/specimen_requirement_test.rb +61 -0
  46. data/test/lib/catissue/domain/specimen_test.rb +272 -0
  47. data/test/lib/catissue/domain/storage_container_test.rb +150 -0
  48. data/test/lib/catissue/domain/storage_type_test.rb +70 -0
  49. data/test/lib/catissue/domain/transfer_event_parameters_test.rb +38 -0
  50. data/test/lib/catissue/domain/user_test.rb +50 -0
  51. data/test/lib/catissue/extract/delta_test.rb +25 -0
  52. data/test/lib/catissue/extract/extractor_test.rb +43 -0
  53. data/test/lib/catissue/import/importable_module_test.rb +14 -0
  54. data/test/lib/catissue/migration/test_case.rb +103 -0
  55. data/test/lib/catissue/test_case.rb +225 -0
  56. data/test/lib/examples/galena/domain/examples_test.rb +70 -0
  57. data/test/lib/examples/galena/migration/catissue.log +0 -0
  58. data/test/lib/examples/galena/migration/filter_test.rb +26 -0
  59. data/test/lib/examples/galena/migration/frozen_test.rb +28 -0
  60. data/test/lib/examples/galena/migration/general_test.rb +44 -0
  61. data/test/lib/examples/galena/migration/simple_test.rb +29 -0
  62. data/test/lib/examples/galena/migration/test_case.rb +52 -0
  63. data/test/lib/examples/galena/migration/uniquify.rb +93 -0
  64. metadata +223 -184
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+
4
+ class SpecimenRequirementTest < Test::Unit::TestCase
5
+ include CaTissue::TestCase
6
+
7
+ def setup
8
+ super
9
+ @rqmt = defaults.specimen_requirement
10
+ end
11
+
12
+ def test_event
13
+ assert(@rqmt.collection_event.requirements.include?(@rqmt), "Event requirements not updated")
14
+ end
15
+
16
+ def test_defaults
17
+ @rqmt.specimen_characteristics = nil
18
+ verify_defaults(@rqmt)
19
+ end
20
+
21
+ # Tests whether the child_specimens domain type is overridden in the configuration from the
22
+ # inferred Java parameterized generic type property.
23
+ def test_child_specimens_type
24
+ assert_equal(CaTissue::SpecimenRequirement, @rqmt.class.domain_type(:child_specimens), "child_specimens domain type not overridden in configuration to non-abstract SpecimenRequirement")
25
+ end
26
+
27
+ def test_derivative_validation
28
+ @rqmt.derive(:count => 2, :specimen_type => (@rqmt.specimen_type + ' Block'))
29
+ assert_equal(2, @rqmt.children.size, "Derived requirement count incorrect")
30
+ @rqmt.add_defaults
31
+ assert_raise(ValidationError, "Multiple derivatives incorrectly succeeds validation") { @rqmt.validate }
32
+ end
33
+
34
+ def test_save
35
+ verify_save(@rqmt)
36
+
37
+ # query the CPE
38
+ cpe = @rqmt.collection_protocol_event
39
+ tmpl = CaTissue::SpecimenRequirement.new(:collection_protocol_event => cpe)
40
+ logger.debug { "Verifying the Requirement CPE query #{tmpl.qp}..." }
41
+ verify_query(tmpl) do |result|
42
+ assert_equal(1, result.size, "Requirement event query result size incorrect")
43
+ assert_equal(@rqmt.identifier, result.first.identifier, "Requirement event query result identifier incorrect")
44
+ end
45
+ end
46
+
47
+ def test_derived_store
48
+ child = @rqmt.derive
49
+ verify_save(@rqmt)
50
+ assert_equal(1, @rqmt.children.size, "Requirment children size incorrect")
51
+ assert_same(child, @rqmt.children.first, "Requirment child incorrect")
52
+
53
+ # query the derived Requirement
54
+ tmpl = child.class.new(:parent => @rqmt.copy(:identifier))
55
+ logger.debug { "Verifying the derived Requirement query #{tmpl}..." }
56
+ verify_query(tmpl) do |result|
57
+ assert_equal(1, result.size, "Derived requirement query result size incorrect")
58
+ assert_equal(child.identifier, result.first.identifier, "Derived requirement query result identifier incorrect")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,272 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
3
+ require 'caruby/util/transitive_closure'
4
+
5
+ class SpecimenTest < Test::Unit::TestCase
6
+ include CaTissue::TestCase
7
+
8
+ def setup
9
+ super
10
+ @spc = defaults.specimen
11
+ end
12
+
13
+ # def test_requirement_copy
14
+ # rqmt = @spc.requirement
15
+ # rqmt.value_hash(rqmt.class.nondomain_attributes).each do |attr, value|
16
+ # assert_equal(value, @spc.send(attr), "Specimen requirement #{attr} not copied")
17
+ # end
18
+ # end
19
+ #
20
+ # def test_characteristics
21
+ # chrs = @spc.specimen_characteristics
22
+ # assert_not_nil(chrs, "Specimen characterstics not found")
23
+ # end
24
+ #
25
+ # def test_defaults
26
+ # @spc.lineage = @spc.specimen_class = @spc.specimen_characteristics = nil
27
+ # verify_defaults(@spc)
28
+ # # specimen class is set as a default value
29
+ # assert_equal("Tissue", @spc.specimen_class, "Specimen class incorrect")
30
+ # # the characteristics default is set as a default value
31
+ # assert_not_nil(@spc.specimen_characteristics, "Specimen characteristics not set to default")
32
+ # end
33
+ #
34
+ # # Tests whether the child_specimens domain type is overridden in the configuration from the
35
+ # # inferred Java parameterized generic type property.
36
+ # def test_child_specimens_type
37
+ # assert_equal(CaTissue::Specimen, @spc.class.domain_type(:child_specimens), "child_specimen domain type not overridden in configuration to non-abstract Specimen")
38
+ # end
39
+ #
40
+ # def test_parent
41
+ # @spc.parent = CaTissue::TissueSpecimen.new
42
+ # assert_equal(1, @spc.parent.children.size, "Specimen children size incorrect")
43
+ # assert_equal(@spc, @spc.parent.children.first, "Specimen parent incorrect")
44
+ # end
45
+ #
46
+ # def test_transitive_closure
47
+ # @spc.parent = CaTissue::TissueSpecimen.new
48
+ # # take the transitive closure of specimens in the hierarchy
49
+ # closure = [@spc.parent].transitive_closure(:children)
50
+ # assert(closure.include?(@spc.parent), "Specimen transitive closure does not contain parent")
51
+ # assert(closure.include?(@spc), "Specimen transitive closure does not contain child")
52
+ # end
53
+ #
54
+ # def test_move
55
+ # # add to the default box
56
+ # box = defaults.box << @spc
57
+ # pos = @spc.position
58
+ # assert_not_nil(pos, "Specimen position not set")
59
+ # assert_same(@spc, pos.specimen, "Specimen position specimen incorrect")
60
+ # # test move from box to another box
61
+ # dest = box.copy
62
+ # @spc >> dest
63
+ # assert_same(dest, @spc.position.container, "Specimen position container incorrect")
64
+ # assert(dest.include?(@spc), "Destination #{box.qp} doesn't hold specimen #{@spc.qp}")
65
+ # assert(!box.include?(@spc), "Old box #{box.qp} still holds specimen #{@spc.qp}")
66
+ # end
67
+ #
68
+ # def test_derive
69
+ # start_quantity = @spc.available_quantity
70
+ # child_quantity = start_quantity / 2
71
+ # child = @spc.derive(:specimen_class => :molecular, :specimen_type => 'DNA', :initial_quantity => child_quantity)
72
+ # assert_equal(CaTissue::MolecularSpecimen, child.class, "Derived specimen class incorrect")
73
+ # assert_same(@spc, child.parent, "Derived specimen parent incorrect")
74
+ # assert(@spc.children.include?(child), "Child specimens does not include the derived specimen")
75
+ # assert_equal(child_quantity, child.initial_quantity, "Child specimen quantity incorrect")
76
+ # # parent quantity not automatically decremented, since parent and child types differ
77
+ # assert_equal(start_quantity, @spc.available_quantity, "Parent specimen quantity not decremented correctly")
78
+ # end
79
+ #
80
+ # def test_derive_defaults
81
+ # child = @spc.derive
82
+ # assert_same(@spc.class, child.class, "Derived specimen class incorrect")
83
+ # assert_equal(@spc.specimen_type, child.specimen_type, "Derived specimen type incorrect")
84
+ # assert_equal(@spc.pathological_status, child.pathological_status, "Derived specimen pathological status incorrect")
85
+ # end
86
+ #
87
+ # def test_aliquot
88
+ # start_qty = @spc.available_quantity
89
+ # # the number of aliquots
90
+ # count = 2
91
+ # # the aliqout quantity
92
+ # alq_qty = start_qty / 4
93
+ # # the expected parent quantity
94
+ # par_qty = start_qty - (alq_qty * count)
95
+ # # make the aliquots
96
+ # alqs = @spc.derive(:count => count, :initial_quantity => alq_qty)
97
+ # assert_equal(count, alqs.size, "Aliquot count incorrect")
98
+ # assert_equal(par_qty, @spc.available_quantity, "Parent specimen quantity not decremented correctly")
99
+ # alqs.each do |alq|
100
+ # assert_same(@spc.class, alq.class, "Aliquot class incorrect")
101
+ # assert_equal(alq_qty, alq.initial_quantity, "Aliquot quantity incorrect")
102
+ # assert_same(@spc.specimen_characteristics, alq.specimen_characteristics, "Aliquot does not share parent characteristics")
103
+ # end
104
+ # # make a non-aliquot derived specimen
105
+ # @spc.derive(:specimen_class => :molecular, :specimen_type => 'DNA')
106
+ # # test that only the aliquots are included in the aliquots accessor
107
+ # assert_equal(alqs.to_set, @spc.aliquots.to_set, "Aliquots accessor incorrect")
108
+ # end
109
+ #
110
+ # def test_aliquot_default_quantity
111
+ # start_qty = @spc.available_quantity
112
+ # count = 2
113
+ # expected_qty = start_qty / count
114
+ # aliquots = @spc.derive(:count => count)
115
+ # assert_equal(0, @spc.available_quantity, "Parent specimen quantity not decremented correctly")
116
+ # aliquots.each do |aliquot|
117
+ # assert_equal(expected_qty, aliquot.initial_quantity, "Aliquot quantity incorrect")
118
+ # end
119
+ # end
120
+ #
121
+ # # Tests whether a Specimen with a position save template does not include the position.
122
+ # # The position is saved as a caTissue side-effect by creating a proxy transfer event.
123
+ # def test_position_save_template
124
+ # defaults.box << @spc
125
+ # assert_not_nil(@spc.position, "#{@spc.qp} not added to box")
126
+ # # the save template
127
+ # tmpl = mock_create_template(@spc)
128
+ # assert_nil(tmpl.position, "#{@spc.qp} save template incorrectly includes the position")
129
+ # end
130
+ #
131
+ # def test_pathology_annotation
132
+ # pths = @spc.prostate_specimen_pathology_annotations
133
+ # assert(pths.empty?, "Pathology annotations not empty at start")
134
+ # pth = CaTissue::Specimen::Pathology::ProstateSpecimenPathologyAnnotation.new
135
+ # pth.merge_attributes(:specimen => @spc)
136
+ # grade = CaTissue::Specimen::Pathology::HistologicGrade.new
137
+ # grade.merge_attributes(:grade => 3, :specimen_base_solid_tissue_pathology_annotation => pth)
138
+ # htype = CaTissue::Specimen::Pathology::HistologicType.new
139
+ # htype.merge_attributes(:type => 3, :specimen_base_solid_tissue_pathology_annotation => pth)
140
+ # gleason = CaTissue::Specimen::Pathology::GleasonScore.new
141
+ # gleason.merge_attributes(:primary_pattern_score => 3, :secondary_pattern_score => 4, :prostate_specimen_pathology_annotation => pth)
142
+ # assert_not_nil(pths.first, "Pathology annotation not added to participant pths")
143
+ # assert_same(pth, pths.first, "Pathology annotation incorrect")
144
+ # assert_same(gleason, pth.gleason_score, "Pathology annotation gleason score incorrect")
145
+ # assert_same(grade, pth.histologic_grades.first, "Pathology annotation histologic grades incorrect")
146
+ # assert_same(htype, pth.histologic_types.first, "Pathology annotation histologic types incorrect")
147
+ # end
148
+ #
149
+ #
150
+ # ## DATABASE TEST CASES ##
151
+ #
152
+ # def test_simple_save
153
+ # # save the auto-generated specimen
154
+ # verify_save(@spc)
155
+ #
156
+ # # verify SCG specimens query
157
+ # logger.debug { "Verifying SCG specimens query..." }
158
+ # scg = @spc.specimen_collection_group
159
+ # tmpl = scg.copy(:identifier)
160
+ # spcs = database.query(tmpl, :specimens)
161
+ # assert_equal(1, spcs.size, "SCG specimen query result count incorrect")
162
+ # spc = spcs.first
163
+ # spc.class.nondomain_attributes.each do |attr|
164
+ # assert_equal(@spc.send(attr), spc.send(attr), "SCG specimen query result #{attr} incorrect")
165
+ # end
166
+ #
167
+ # # make a new specimen in the same SCG
168
+ # spc2 = @spc.copy
169
+ # spc2.identifier = nil
170
+ # spc2.specimen_collection_group = scg
171
+ # verify_save(spc2)
172
+ # end
173
+ #
174
+ # # Tests the work-around for caTissue Bug #159: Update pending Specimen ignores availableQuantity.
175
+ # def test_quantity_save
176
+ # # reset the available quantity
177
+ # @spc.available_quantity = @spc.initial_quantity / 2
178
+ # verify_save(@spc)
179
+ # end
180
+ #
181
+ # # Exercises the CaTissue::Specimen external_identifiers logical dependency work-around.
182
+ # def test_eid_save
183
+ # # add an EID
184
+ # eid = CaTissue::ExternalIdentifier.new(:name => 'Test Name'.uniquify, :specimen => @spc, :value => 'Test Value'.uniquify)
185
+ # verify_save(@spc)
186
+ # # query on the EID
187
+ # logger.debug { "Verifying Specimen EID query..." }
188
+ # tmpl = @spc.copy(:external_identifiers)
189
+ # assert_not_nil(database.find(tmpl), "Specimen not found by external identifier")
190
+ # assert_equal(@spc.identifier, tmpl.identifier, "Incorrect specimen found by external identifier")
191
+ # # update the specimen to exercise Bug #164
192
+ # verify_save(@spc)
193
+ # end
194
+ #
195
+ # def test_events_save
196
+ # # add an event
197
+ # CaTissue::FrozenEventParameters.new(:specimen => @spc, :freeze_method => 'Cryostat')
198
+ # verify_save(@spc)
199
+ # end
200
+ #
201
+ # def test_position_save
202
+ # defaults.box << @spc
203
+ # verify_save(@spc)
204
+ # # move the specimen
205
+ # @spc.position.location = @spc.position.location.succ
206
+ # logger.debug { "#{name} verifing move of #{@spc} to #{@spc.position.location}..." }
207
+ # verify_save(@spc)
208
+ # end
209
+ #
210
+ # # Exercise creation of a child specimen.
211
+ # def test_derived_create
212
+ # # verify creating a derived specimen
213
+ # logger.debug { "Verifying creating a derived specimen..." }
214
+ # # derive a specimen
215
+ # drv = @spc.derive(:specimen_class => :molecular, :initial_quantity => 20, :specimen_type => 'DNA')
216
+ # # add an event
217
+ # CaTissue::SpunEventParameters.new(:specimen => drv, :duration_in_minutes => 2, :gravity_force => 5)
218
+ # # store the derived specimen
219
+ # verify_save(drv)
220
+ # # verify the derived specimen parent
221
+ # assert_same(@spc, drv.parent, "Derived specimen parent incorrect after store")
222
+ # # query the derived specimen
223
+ # tmpl = CaTissue::Specimen.new(:parent => @spc.class.new(:label => @spc.label))
224
+ # verify_query(tmpl) do |children|
225
+ # assert_equal(1, children.size, "Parent specimen children count incorrect")
226
+ # assert(drv.match_in_owner_scope(children), "Derived specimen not found in parent query result")
227
+ # end
228
+ # end
229
+ #
230
+ # # Exercise update of an auto-generated child specimen.
231
+ # #
232
+ # # This test case differs from {#test_derived_create} in that there are critical caTissue code path
233
+ # # differences which dictate how the derived object save template is built. See the caTissue
234
+ # # alert comment in CaRuby::StoreTemplateBuilder initialize code for details.
235
+ # def test_autogenerated_derived_save
236
+ # # verify updating an auto-generated derived specimen
237
+ # logger.debug { "Verifying updating an auto-generated derived specimen..." }
238
+ # # derive a specimen requirement
239
+ # rqmt = @spc.requirement.derive(:specimen_class => :molecular, :initial_quantity => 20, :specimen_type => 'DNA')
240
+ # # derive the specimen
241
+ # drv = @spc.derive(:requirement => rqmt)
242
+ # # store the derived specimen
243
+ # verify_save(drv)
244
+ # end
245
+ #
246
+ def test_save_prostate_annotation
247
+ pa = CaTissue::Specimen::Pathology::ProstateSpecimenPathologyAnnotation.new
248
+ pa.specimen = @spc
249
+ grade = CaTissue::Specimen::Pathology::HistologicGrade.new
250
+ grade.merge_attributes(:grade => 3, :specimen_base_solid_tissue_pathology_annotation => pa)
251
+ htype = CaTissue::Specimen::Pathology::HistologicType.new
252
+ htype.merge_attributes(:type => 3, :specimen_base_solid_tissue_pathology_annotation => pa)
253
+ invn = CaTissue::Specimen::Pathology::Invasion.new
254
+ invn.merge_attributes(:lymphatic_invasion => 'Present', :specimen_base_solid_tissue_pathology_annotation => pa)
255
+ gleason = CaTissue::Specimen::Pathology::GleasonScore.new
256
+ gleason.merge_attributes(:primary_pattern_score => 3, :secondary_pattern_score => 4, :prostate_specimen_pathology_annotation => pa)
257
+ verify_save(pa)
258
+ assert_not_nil(pa.identifier, "#{@spc} annotation #{pa} not saved")
259
+ assert_not_nil(grade.identifier, "#{@spc} annotation #{grade} not saved")
260
+ assert_not_nil(htype.identifier, "#{@spc} annotation #{htype} not saved")
261
+ assert_not_nil(invn.identifier, "#{@spc} annotation #{invn} not saved")
262
+ assert_not_nil(gleason.identifier, "#{gleason} not saved")
263
+ end
264
+ #
265
+ # def test_save_melanoma_annotation
266
+ # ma = CaTissue::Specimen::Pathology::MelanomaSpecimenPathologyAnnotation.new
267
+ # ma.merge_attributes(:specimen => @spc, :comments => "Test Comment", :depth_of_invasion => 2.0, :mitotic_index => "MitoticIndex",
268
+ # :ulceration => "Ulceration", :tumor_regression => "TumorRegression", :tumor_infiltrating_lymphocytes => "TumorInfiltratingLymphocytes")
269
+ # verify_save(ma)
270
+ # assert_not_nil(ma.identifier, "#{ma} not saved")
271
+ # end
272
+ end
@@ -0,0 +1,150 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_case')
2
+ require 'caruby/util/uniquifier'
3
+ require 'test/fixtures/lib/catissue/defaults_test_fixture'
4
+
5
+ class StorageContainerTest < Test::Unit::TestCase
6
+ include CaTissue::TestCase
7
+
8
+ def setup
9
+ super
10
+ @spc = defaults.specimen
11
+ site = defaults.tissue_bank
12
+ frz_type = CaTissue::StorageType.new(:name => 'Test Freezer'.uniquify, :columns => 1, :rows => 2)
13
+ rack_type = CaTissue::StorageType.new(:name => 'Test Rack'.uniquify, :columns => 2, :rows => 1)
14
+ box_type = CaTissue::StorageType.new(:name => 'Test Box'.uniquify, :columns => 1, :rows => 2)
15
+ array_type = CaTissue::SpecimenArrayType.new(:name => 'SpecimenArray'.uniquify,
16
+ :specimen_class => @spc.specimen_class, :specimen_types => [@spc.specimen_type],
17
+ :columns => 5, :rows => 5)
18
+ frz_type << rack_type
19
+ rack_type << box_type << array_type
20
+ box_type << @spc.specimen_class
21
+ @frz = CaTissue::StorageContainer.new(:site => site, :container_type => frz_type)
22
+ @array = CaTissue::SpecimenArray.new(:container_type => array_type)
23
+ end
24
+
25
+ def test_defaults
26
+ verify_defaults(@frz)
27
+ end
28
+
29
+ def test_add
30
+ @frz << @spc
31
+
32
+ rack = @frz[0, 0]
33
+ assert_not_nil(rack, "Rack not created")
34
+ assert(@frz.holds?(rack), "Rack not added to freezer")
35
+ assert_same(@frz, rack.parent, "Rack parent is not the freezer")
36
+ assert_equal(rack, @frz[0, 0], "Rack index accessor incorrect")
37
+
38
+ box = rack[0, 0]
39
+ assert_not_nil(box, "Box not created")
40
+ assert(rack.holds?(box), "Rack doesn't hold box")
41
+ assert_same(rack, box.parent, "Box parent is not the rack")
42
+
43
+ assert(box.holds?(@spc), "Box doesn't hold specimen")
44
+ assert_same(@spc, box[0, 0], "Specimen index accessor incorrect")
45
+ assert_nil(@frz[0, 1], "Empty slot index accessor not nil")
46
+ assert_nil(@frz[0, 2], "Column out of bounds index accessor not nil")
47
+ assert_nil(@frz[1, 0], "Row out of bounds index accessor not nil")
48
+ assert(!rack.full?, "Rack is incorrectly full")
49
+ assert(!box.full?, "Box is incorrectly full")
50
+
51
+ # add a new specimen
52
+ @frz << spc2 = @spc.copy
53
+ assert_same(box, spc2.position.container, "New specimen box incorrect")
54
+ assert(!rack.full?, "Rack is incorrectly full")
55
+ assert(box.full?, "Box is incorrectly not full")
56
+
57
+ # create a new box for another specimen
58
+ @frz << spc3 = @spc.copy
59
+ assert_not_same(box, spc3.position.container, "New box not allocated")
60
+ assert(rack.full?, "Rack is not full")
61
+
62
+ # create a new box for another specimen
63
+ @frz << spc4 = @spc.copy
64
+ assert_same(spc3.position.container, spc4.position.container, "New box incorrectly allocated")
65
+
66
+ # fill the freezer
67
+ 4.times { @frz << @spc.copy }
68
+ assert(@frz.full?, "Freezer incorrectly not full")
69
+ assert(@frz.completely_full?, "Freezer incorrectly not completely full")
70
+
71
+ # create a new box with no place to put it
72
+ assert_raises(IndexError, "Add to full box succeeded") { box << @spc.copy }
73
+ end
74
+
75
+ def test_fill_gap
76
+ @frz << @spc
77
+
78
+ rack = @frz[0, 0]
79
+ assert_not_nil(rack, "Rack not created")
80
+ box = rack[0, 0]
81
+ assert_not_nil(box, "Box not created")
82
+
83
+ # make another box
84
+ @frz << box2 = box.copy(:container_type)
85
+ assert_equal(box2, rack[1, 0], "Rack index accessor incorrect")
86
+
87
+ # add a specimen to the second box
88
+ box2 << spc2 = @spc.copy
89
+ assert_equal(spc2, box2[0, 0], "Specimen is placed in #{@spc.position.location} rather than the second box #{box.qp}")
90
+
91
+ # add a specimen to the first available slot in the first box
92
+ spc3 = @spc.copy
93
+ @frz << spc3
94
+ assert_equal(spc3, box[0, 1], "Specimen is placed in #{@spc.position.location} rather than the first box #{box.qp}")
95
+
96
+ # add a specimen to the second box
97
+ @frz << spc4 = @spc.copy
98
+ assert_equal(spc4, box2[0, 1], "Specimen is not placed in second box")
99
+
100
+ # fill the freezer
101
+ 4.times { @frz << @spc.copy }
102
+ assert(@frz.full?, "Freezer incorrectly not full")
103
+ assert(@frz.completely_full?, "Freezer incorrectly not completely full")
104
+ end
105
+
106
+ def test_comparison
107
+ @frz << @spc
108
+ assert_equal(@frz, @frz, "Same not equal")
109
+ rack = @frz.subcontainers.first
110
+ assert_not_nil(rack, "Rack missing")
111
+ box = rack.subcontainers.first
112
+ assert_not_nil(box, "Box missing")
113
+ assert(rack < @frz, "Rack not < freezer")
114
+ assert(@frz > rack, "Freezer not > rack")
115
+ assert(box < rack, "Box not < rack")
116
+ assert(box < @frz, "Box not < rack")
117
+ end
118
+
119
+ # def test_save
120
+ # @frz << @spc
121
+ # rack = @frz.subcontainers.first
122
+ # assert_not_nil(rack, "Rack missing")
123
+ # box = rack.subcontainers.first
124
+ # assert_not_nil(box, "Box missing")
125
+ #
126
+ # # verify that the box name can be set
127
+ # box.name = 'Test Box'.uniquify
128
+ # verify_save(box)
129
+ # assert_not_nil(@frz.identifier, "#{@frz.qp} not saved")
130
+ #
131
+ # assert_not_nil(rack.identifier, "#{rack.qp} not saved")
132
+ # assert_not_nil(rack.position, "#{rack.qp} position missing")
133
+ # assert_not_nil(rack.position.identifier, "#{rack.qp} position not saved")
134
+ # assert_not_nil(@frz.subcontainers.first, "#{@frz.qp} subcontainer not found")
135
+ # assert_same(rack, @frz.subcontainers.first, "#{@frz.qp} subcontainer is not the rack")
136
+ # assert_same(@frz, rack.position.parent_container, "#{rack.qp} position container missing")
137
+ #
138
+ # assert_not_nil(box.identifier, "#{box} not saved")
139
+ # assert_not_nil(box.position, "#{box} position missing")
140
+ # assert_not_nil(box.position.identifier, "#{box} position not saved")
141
+ # assert_same(rack, box.position.parent_container, "#{box} position container missing")
142
+ # assert_not_nil(rack.subcontainers.first, "#{rack.qp} subcontainer not found")
143
+ # assert_same(box, rack.subcontainers.first, "#{rack.qp} subcontainer is not the box")
144
+ #
145
+ # assert(!box.specimens.empty?, "#{box} doesn't hold a specimen")
146
+ # assert_same(@spc, box.specimens.first, "#{box} specimen incorrect")
147
+ # assert_not_nil(@spc.identifier, "#{@spc} not saved")
148
+ # assert_not_nil(@spc.position, "#{@spc} missing position")
149
+ # end
150
+ end