Class: TestDose

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



12
13
14
# File 'test/test_model/dose.rb', line 12

def setup
  @dose = ODDB::Dose.new('1,7', 'mL')
end

- (Object) test_arithmetics



74
75
76
77
78
79
80
81
82
83
84
# File 'test/test_model/dose.rb', line 74

def test_arithmetics
  dose1 = ODDB::Dose.new(10, 'mg')
  dose2 = ODDB::Dose.new(5, 'mg')
  dose3 = ODDB::Dose.new(2, 'ml')
  assert_equal dose1, dose2 + dose2
  assert_equal dose2, dose1 - dose2
  assert_equal dose1, dose2 * 2
  assert_equal dose2, dose1 / 2
  assert_equal ODDB::Dose.new(5, 'mg/ml'), dose1 / dose3
  assert_equal ODDB::Dose.new(100, 'mg mg'), dose1 ** 2
end

- (Object) test_comparable1



85
86
87
88
89
# File 'test/test_model/dose.rb', line 85

def test_comparable1
  dose1 = ODDB::Dose.new(10, 'mg')
  dose2 = ODDB::Dose.new(10, 'mg')
  assert_equal(dose1, dose2)
end

- (Object) test_comparable2



90
91
92
93
94
# File 'test/test_model/dose.rb', line 90

def test_comparable2
  dose1 = ODDB::Dose.new(10, 'mg')
  dose2 = ODDB::Dose.new(10, 'g')
  assert(dose2 > dose1, "dose2 was not > dose1")
end

- (Object) test_comparable3



95
96
97
98
99
# File 'test/test_model/dose.rb', line 95

def test_comparable3
  dose1 = ODDB::Dose.new(1000, 'I.E.')
  dose2 = ODDB::Dose.new(500, 'I.E.')
  assert(dose2 < dose1, "dose2 was not < dose1")
end

- (Object) test_comparable4



100
101
102
103
104
# File 'test/test_model/dose.rb', line 100

def test_comparable4
  dose1 = ODDB::Dose.new(1000, 'mg')
  dose2 = ODDB::Dose.new(500, 'I.E.')
  assert_equal(-1, dose2 <=> dose1, "dose2 was not < dose1")
end

- (Object) test_comparable5



105
106
107
108
109
# File 'test/test_model/dose.rb', line 105

def test_comparable5
  dose1 = ODDB::Dose.new(1000, 'mg')
  dose2 = ODDB::Dose.new(500, 'l')
  assert_equal(-1, dose2 <=> dose1, "dose2 was not < dose1")
end

- (Object) test_comparable6



110
111
112
113
114
# File 'test/test_model/dose.rb', line 110

def test_comparable6
  dose1 = ODDB::Dose.new(1000, 'mg')
  dose2 = ODDB::Dose.new(1, 'g')
  assert(dose2 == dose1, "dose2 was not == dose1")
end

- (Object) test_comparable7



115
116
117
118
119
# File 'test/test_model/dose.rb', line 115

def test_comparable7
  dose1 = ODDB::Dose.new('400-600', 'mg')
  dose2 = ODDB::Dose.new('0.4-0.6', 'g')
  assert(dose2 == dose1, "dose2 was not == dose1")
end

- (Object) test_comparable8



120
121
122
123
124
# File 'test/test_model/dose.rb', line 120

def test_comparable8
  dose1 = ODDB::Dose.new('1000', 'µg')
  dose2 = ODDB::Dose.new('1', 'mg')
  assert(dose2 == dose1, "dose2 was not == dose1")
end

- (Object) test_comparable9



125
126
127
128
129
130
# File 'test/test_model/dose.rb', line 125

def test_comparable9
  dose1 = ODDB::Dose.new('1000', nil) 
  dose2 = ODDB::Dose.new('1', 'mg')
  assert(dose2 > dose1, "dose2 was not > dose1")
  assert(dose1 < dose2, "dose1 was not < dose2")
end

- (Object) test_complex_unit



131
132
133
134
135
136
# File 'test/test_model/dose.rb', line 131

def test_complex_unit
  dose = nil
  assert_nothing_raised {
    dose = ODDB::Dose.new(20.0, 'mg/5ml')
  }
end

- (Object) test_from_quanty



137
138
139
140
141
142
143
144
145
# File 'test/test_model/dose.rb', line 137

def test_from_quanty
  quanty = Quanty.new(1,'mg')
  result = ODDB::Dose.from_quanty(quanty)
  assert_instance_of(ODDB::Dose, result)
  assert_equal(ODDB::Dose.new(1, 'mg'), result)
  second = ODDB::Dose.from_quanty result
  assert_equal result, second
  assert_equal result.object_id, second.object_id
end

- (Object) test_initialize1



15
16
17
18
19
20
21
# File 'test/test_model/dose.rb', line 15

def test_initialize1
  vals = ['Aspirin, Tabletten', '12', '500', 'mg', 'D']
  dose = ODDB::Dose.new(*vals[2,2])
  assert_equal(500, dose.qty)
  assert_equal('mg', dose.unit.to_s)
  assert_equal('500 mg', dose.to_s)
end

- (Object) test_initialize2



22
23
24
25
26
27
28
# File 'test/test_model/dose.rb', line 22

def test_initialize2
  vals = ['Hametum, Salbe', '62.5', 'mg/g', 'D']
  dose = ODDB::Dose.new(*vals[1,2])
  assert_equal(62.5, dose.qty)
  assert_equal('mg/g', dose.unit.to_s)
  assert_equal('62.5 mg/g', dose.to_s)
end

- (Object) test_initialize3



29
30
31
32
33
34
# File 'test/test_model/dose.rb', line 29

def test_initialize3
  dose = ODDB::Dose.new('1,7', 'mL')
  assert_equal(1.7, dose.qty)
  assert_equal('ml', dose.unit.to_s)
  assert_equal('1.7 ml', dose.to_s)
end

- (Object) test_initialize4



35
36
37
38
39
40
41
42
43
44
# File 'test/test_model/dose.rb', line 35

def test_initialize4
  compare = ODDB::Dose.new(6.25, 'mg/g')
  vals = ['62.5', 'mg/10g']
  dose = ODDB::Dose.new(*vals)
  assert_equal(6.25, dose.qty)
  assert_equal('mg/g', dose.unit.to_s)
  assert_equal('62.5mg / 10g', dose.to_s)
  assert_equal(0, compare<=>dose)
  assert_equal(compare, dose)
end

- (Object) test_initialize5



45
46
47
48
49
50
51
52
53
54
# File 'test/test_model/dose.rb', line 45

def test_initialize5
  compare = ODDB::Dose.new(0.5, 'mg/ml')
  vals = [1, 'mg/2ml']
  dose = ODDB::Dose.new(*vals)
  assert_equal(0.5, dose.qty)
  assert_equal('mg/ml', dose.unit.to_s)
  assert_equal('1mg / 2ml', dose.to_s)
  assert_equal(0, compare<=>dose)
  assert_equal(compare, dose)
end

- (Object) test_initialize6



55
56
57
58
59
60
61
# File 'test/test_model/dose.rb', line 55

def test_initialize6
  vals = ['62.5', ' mg / 10g']
  dose = ODDB::Dose.new(*vals)
  assert_equal(6.25, dose.qty)
  assert_equal('mg/g', dose.unit.to_s)
  assert_equal('62.5mg / 10g', dose.to_s)
end

- (Object) test_initialize7



62
63
64
65
66
67
# File 'test/test_model/dose.rb', line 62

def test_initialize7
  dose = ODDB::Dose.new('0.025', '%')
  assert_equal(0.025, dose.qty)
  assert_equal('%', dose.unit.to_s)
  assert_equal('0.025 %', dose.to_s)
end

- (Object) test_initialize8



68
69
70
71
72
73
# File 'test/test_model/dose.rb', line 68

def test_initialize8
  dose = ODDB::Dose.new('40-60', 'mg')
  assert_equal(50, dose.qty)
  assert_equal('mg', dose.unit.to_s)
  assert_equal('40-60 mg', dose.to_s)
end

- (Object) test_multiplication



146
147
148
149
150
# File 'test/test_model/dose.rb', line 146

def test_multiplication
  dose1 = ODDB::Dose.new(1,'ml')
  dose2 = ODDB::Dose.new(1.7,'kg')
  assert_equal(ODDB::Dose.new(1.7, 'ml kg'), dose1 * dose2)
end

- (Object) test_robust_initalizer



151
152
153
154
155
# File 'test/test_model/dose.rb', line 151

def test_robust_initalizer
  assert_nothing_raised {
    ODDB::Dose.new(12)
  }
end

- (Object) test_robust_to_f



156
157
158
159
160
161
# File 'test/test_model/dose.rb', line 156

def test_robust_to_f
  dose = ODDB::Dose.new(12, 'mg')
  assert_nothing_raised {
    dose.to_f
  }
end

- (Object) test_scale



162
163
164
165
166
# File 'test/test_model/dose.rb', line 162

def test_scale
  assert_nil @dose.scale
  dose = ODDB::Dose.new(100, 'µg / 2 h')
  assert_equal ODDB::Dose.new(2, 'h'), dose.scale
end

- (Object) test_to_i



171
172
173
# File 'test/test_model/dose.rb', line 171

def test_to_i
  assert_equal 1, @dose.to_i
end

- (Object) test_to_s



174
175
176
177
178
# File 'test/test_model/dose.rb', line 174

def test_to_s
  assert_equal '1.7 ml', @dose.to_s
  dose = ODDB::Dose.new(100, 'µg / 2 h')
  assert_equal '100µg / 2h', dose.to_s
end

- (Object) test_ug_h



167
168
169
170
# File 'test/test_model/dose.rb', line 167

def test_ug_h
  dose = ODDB::Dose.new(100, 'µg/h')
  assert_equal('100 µg/h', dose.to_s)
end

- (Object) test_want



179
180
181
182
183
184
# File 'test/test_model/dose.rb', line 179

def test_want
  wanted = @dose.want 'cl'
  assert_instance_of ODDB::Dose, wanted
  assert_equal 'cl', wanted.unit
  assert_equal 0.17, wanted.qty
end