Class: TestActiveAgent

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_model/activeagent.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'test/test_model/activeagent.rb', line 61

def setup
  @substance_name = 'ACIDUM ACETYLSALICYLICUM'
  @agent = ODDB::ActiveAgent.new(@substance_name)
  @agent.substance = @substance
  @agent.dose = ODDB::Dose.new 100, 'mg'
  @app = StubActiveAgentApp.new
  @substance = StubActiveAgentSubstance.new(@substance_name)
  @agent.pointer = ODDB::Persistence::Pointer.new('parent', 'self')
  @sequence = StubActiveAgentSequence.new
  @sequence.pointer = ODDB::Persistence::Pointer.new(:sequence, 1)
  @agent.sequence = @sequence
  @agent.init(@app)
end

- (Object) test_adjust_types



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'test/test_model/activeagent.rb', line 113

def test_adjust_types
  app = StubActiveAgentApp.new
  subst = StubActiveAgentSubstance.new('ACIDUM MEFENAMICUM')
  dose = ODDB::Dose.new(10, 'mg')
  input = {
    :dose        =>  ['10', 'mg'],
    :substance =>  'ACIDUM MEFENAMICUM',
  }
  expected = {
    :dose        =>  dose,
    :substance =>  subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :dose        =>  '10mg',
    :substance =>  'ACIDUM MEFENAMICUM',
  }
  expected = {
    :dose        =>  ODDB::Dose.new(10),
    :substance =>  subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :dose        =>  ['10', 'mg'],
    :substance =>  'ACIDUM ACETYLSALICYLICUM',
  }
  expected = {
    :dose        =>  dose,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
end

- (Object) test_adjust_types__error



208
209
210
211
212
213
214
# File 'test/test_model/activeagent.rb', line 208

def test_adjust_types__error
  res = nil
  assert_nothing_raised do
    res = @agent.adjust_types :dose => []
  end
  assert_equal({}, res)
end

- (Object) test_adjust_types_chemical



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'test/test_model/activeagent.rb', line 144

def test_adjust_types_chemical
  app = StubActiveAgentApp.new
  subst = StubActiveAgentSubstance.new('ACIDUM MEFENAMICUM')
  dose = ODDB::Dose.new(10, 'mg')
  input = {
    :chemical_dose     =>  ['10', 'mg'],
    :chemical_substance  => 'ACIDUM MEFENAMICUM',
  }
  expected = {
    :chemical_dose     =>  dose,
    :chemical_substance  => subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :chemical_dose     =>  nil,
    :chemical_substance  => 'ACIDUM MEFENAMICUM',
  }
  expected = {
    :chemical_dose     =>  nil,
    :chemical_substance  => subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :chemical_dose     =>  ['10', 'mg'],
    :chemical_substance  => 'ACIDUM ACETYLSALICYLICUM',
  }
  expected = {
    :chemical_dose     =>  dose,
    :chemical_substance  => nil,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
end

- (Object) test_adjust_types_equivalent



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'test/test_model/activeagent.rb', line 176

def test_adjust_types_equivalent
  app = StubActiveAgentApp.new
  subst = StubActiveAgentSubstance.new('ACIDUM MEFENAMICUM')
  dose = ODDB::Dose.new(10, 'mg')
  input = {
    :equivalent_dose     =>  ['10', 'mg'],
    :equivalent_substance  => 'ACIDUM MEFENAMICUM',
  }
  expected = {
    :equivalent_dose     =>  dose,
    :equivalent_substance  => subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :equivalent_dose     =>  nil,
    :equivalent_substance  => 'ACIDUM MEFENAMICUM',
  }
  expected = {
    :equivalent_dose     =>  nil,
    :equivalent_substance  => subst,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
  input = {
    :equivalent_dose     =>  ['10', 'mg'],
    :equivalent_substance  => 'ACIDUM ACETYLSALICYLICUM',
  }
  expected = {
    :equivalent_dose     =>  dose,
    :equivalent_substance  => nil,
  }
  assert_equal(expected, @agent.adjust_types(input, app))
end

- (Object) test_checkout



109
110
111
112
# File 'test/test_model/activeagent.rb', line 109

def test_checkout
  @agent.checkout
  assert_equal(@sequence, @agent.substance.removed_sequence)
end

- (Object) test_compare1



215
216
217
218
219
220
221
222
223
224
# File 'test/test_model/activeagent.rb', line 215

def test_compare1
  @agent.dose = ODDB::Dose.new(1,'g')
  other = ODDB::ActiveAgent.new(@substance_name)
  other.pointer = ODDB::Persistence::Pointer.new('parent', 'self')
  other.init(@app)
  other.dose = ODDB::Dose.new(2, 'g')
  assert_equal(-1, other <=> @agent)
  other.dose = ODDB::Dose.new(1, 'g')
  assert_equal(0, other <=> @agent)
end

- (Object) test_compare2



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'test/test_model/activeagent.rb', line 225

def test_compare2
  substance = StubActiveAgentSubstance.new('LEVOMENTHOLUM')
  @app.substances = {
    'LEVOMENTHOLUM' => substance,
    @substance_name  => @substance,
  }
  @agent.dose = ODDB::Dose.new(1,'g')
  other = ODDB::ActiveAgent.new('LEVOMENTHOLUM')
  other.pointer = ODDB::Persistence::Pointer.new('parent', 'self')
  other.init(@app)
  other.dose = ODDB::Dose.new(2, 'g')
  assert_equal(-1, other <=> @agent)
  other.dose = ODDB::Dose.new(0.5, 'g')
  assert_equal(1, other <=> @agent)
  other.dose = ODDB::Dose.new(1, 'g')
  assert_equal(1, other <=> @agent)
  assert_equal([@agent, other], [other, @agent].sort)
end

- (Object) test_compare3



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'test/test_model/activeagent.rb', line 243

def test_compare3
  substance = StubActiveAgentSubstance.new('LEVOMENTHOLUM')
  @app.substances = {
    'LEVOMENTHOLUM' => substance,
    @substance_name  => @substance,
  }
  @agent.dose = ODDB::Dose.new(1,'g')
  other = ODDB::ActiveAgent.new('LEVOMENTHOLUM')
  other.pointer = ODDB::Persistence::Pointer.new('parent', 'self')
  other.init(@app)
  assert_equal(1, other <=> @agent)
  @agent.dose = nil
  other.dose = ODDB::Dose.new(0.5, 'g')
  assert_equal(-1, other <=> @agent)
  other.dose = nil
  assert_equal(1, other <=> @agent)
end

- (Object) test_equal



78
79
80
81
82
83
84
85
86
87
88
# File 'test/test_model/activeagent.rb', line 78

def test_equal
  other = ODDB::ActiveAgent.new(@substance_name)
  other.substance = @substance
  other.dose = ODDB::Dose.new 100, 'mg'
  other.pointer = ODDB::Persistence::Pointer.new('parent', 'self')
  other.init(@app)
  assert_equal(other, @agent)
  assert_nothing_raised {
    @agent == nil
  }
end

- (Object) test_init



74
75
76
77
# File 'test/test_model/activeagent.rb', line 74

def test_init
  assert_equal(@substance, @agent.substance)
  assert_equal(@sequence, @agent.substance.sequence)
end

- (Object) test_same_as



260
261
262
263
264
265
266
267
268
269
270
271
# File 'test/test_model/activeagent.rb', line 260

def test_same_as
  agent = ODDB::ActiveAgent.new(@substance_name)
  assert_equal(false, agent.same_as?('Levomentholum'))
  subst = Mock.new
  agent.instance_variable_set('@substance', subst)
  subst.__next(:same_as?) { |arg| 
    assert_equal('Levomentholum', arg)
    true
  }
  assert_equal(true, agent.same_as?('Levomentholum'))
  subst.__verify
end

- (Object) test_substance_writer



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'test/test_model/activeagent.rb', line 89

def test_substance_writer
  sequence = StubActiveAgentSequence.new
  sequence.pointer = ODDB::Persistence::Pointer.new([:sequence, 2])
  subst1 = StubActiveAgentSubstance.new("LEVOMENTHOLUM")
  @agent.sequence = sequence
  @agent.substance = subst1
  assert_equal(sequence, subst1.sequence)
  assert_equal(subst1, @agent.substance)
  subst2 = StubActiveAgentSubstance.new("ACIDUM MEFENAMICUM")
  @agent.substance = subst2
  assert_equal(sequence, subst1.removed_sequence)
  assert_equal(sequence, subst2.sequence)
  assert_equal(subst2, @agent.substance)
  subst3 = StubActiveAgentSubstance.new("ACIDUM MEFENAMICUM")
  # no action if substance == @substance
  @agent.substance = subst3
  assert_nil(subst2.removed_sequence)
  assert_nil(subst3.sequence)
  assert_equal(subst2, @agent.substance)
end

- (Object) test_to_a



272
273
274
# File 'test/test_model/activeagent.rb', line 272

def test_to_a
  assert_equal [@substance, @agent.dose], @agent.to_a
end

- (Object) test_to_s



275
276
277
# File 'test/test_model/activeagent.rb', line 275

def test_to_s
  assert_equal 'ACIDUM ACETYLSALICYLICUM 100 mg', @agent.to_s
end

- (Object) test_update_values



278
279
# File 'test/test_model/activeagent.rb', line 278

def test_update_values
end