-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightTest.php
406 lines (340 loc) · 12.1 KB
/
WeightTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
/**
* @package Zend_Measure
* @subpackage UnitTests
*/
/**
* Zend_Measure_Weight
*/
require_once 'Zend/Measure/Weight.php';
/**
* PHPUnit test case
*/
require_once 'PHPUnit/Framework/TestCase.php';
/**
* @package Zend_Measure
* @subpackage UnitTests
*/
class Zend_Measure_WeightTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
}
/**
* test for Weight initialisation
* expected instance
*/
public function testWeightInit()
{
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$this->assertTrue($value instanceof Zend_Measure_Weight,'Zend_Measure_Weight Object not returned');
}
/**
* test for exception unknown type
* expected exception
*/
public function testWeightUnknownType()
{
try {
$value = new Zend_Measure_Weight('100','Weight::UNKNOWN','de');
$this->assertTrue(false,'Exception expected because of unknown type');
} catch (Exception $e) {
return true; // Test OK
}
}
/**
* test for exception unknown value
* expected exception
*/
public function testWeightUnknownValue()
{
try {
$value = new Zend_Measure_Weight('novalue',Zend_Measure_Weight::STANDARD,'de');
$this->assertTrue(false,'Exception expected because of empty value');
} catch (Exception $e) {
return true; // Test OK
}
}
/**
* test for exception unknown locale
* expected root value
*/
public function testWeightUnknownLocale()
{
try {
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'nolocale');
$this->assertTrue(false,'Exception expected because of unknown locale');
} catch (Exception $e) {
return true; // Test OK
}
}
/**
* test for standard locale
* expected integer
*/
public function testWeightNoLocale()
{
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD);
$this->assertEquals(100, $value->getValue(),'Zend_Measure_Weight value expected');
}
/**
* test for positive value
* expected integer
*/
public function testWeightValuePositive()
{
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(100, $value->getValue(), 'Zend_Measure_Weight value expected to be a positive integer');
}
/**
* test for negative value
* expected integer
*/
public function testWeightValueNegative()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-100, $value->getValue(), 'Zend_Measure_Weight value expected to be a negative integer');
}
/**
* test for decimal value
* expected float
*/
public function testWeightValueDecimal()
{
$value = new Zend_Measure_Weight('-100,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-100.200, $value->getValue(), 'Zend_Measure_Weight value expected to be a decimal value');
}
/**
* test for decimal seperated value
* expected float
*/
public function testWeightValueDecimalSeperated()
{
$value = new Zend_Measure_Weight('-100.100,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Weight Object not returned');
}
/**
* test for string with integrated value
* expected float
*/
public function testWeightValueString()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-100100.200, $value->getValue(),'Zend_Measure_Weight Object not returned');
}
/**
* test for equality
* expected true
*/
public function testWeightEquality()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$newvalue = new Zend_Measure_Weight('otherstring -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertTrue($value->equals($newvalue),'Zend_Measure_Weight Object should be equal');
}
/**
* test for no equality
* expected false
*/
public function testWeightNoEquality()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$newvalue = new Zend_Measure_Weight('otherstring -100,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertFalse($value->equals($newvalue),'Zend_Measure_Weight Object should be not equal');
}
/**
* test for serialization
* expected string
*/
public function testWeightSerialize()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$serial = $value->serialize();
$this->assertTrue(!empty($serial),'Zend_Measure_Weight not serialized');
}
/**
* test for unserialization
* expected object
*/
public function testWeightUnSerialize()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$serial = $value->serialize();
$newvalue = unserialize($serial);
$this->assertTrue($value->equals($newvalue),'Zend_Measure_Weight not unserialized');
}
/**
* test for set positive value
* expected integer
*/
public function testWeightSetPositive()
{
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(200, $value->getValue(), 'Zend_Measure_Weight value expected to be a positive integer');
}
/**
* test for set negative value
* expected integer
*/
public function testWeightSetNegative()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('-200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-200, $value->getValue(), 'Zend_Measure_Weight value expected to be a negative integer');
}
/**
* test for set decimal value
* expected float
*/
public function testWeightSetDecimal()
{
$value = new Zend_Measure_Weight('-100,200',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('-200,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-200.200, $value->getValue(), 'Zend_Measure_Weight value expected to be a decimal value');
}
/**
* test for set decimal seperated value
* expected float
*/
public function testWeightSetDecimalSeperated()
{
$value = new Zend_Measure_Weight('-100.100,200',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('-200.200,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Weight Object not returned');
}
/**
* test for set string with integrated value
* expected float
*/
public function testWeightSetString()
{
$value = new Zend_Measure_Weight('string -100.100,200',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('otherstring -200.200,200',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals(-200200.200, $value->getValue(),'Zend_Measure_Weight Object not returned');
}
/**
* test for exception unknown type
* expected exception
*/
public function testWeightSetUnknownType()
{
try {
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('otherstring -200.200,200','Weight::UNKNOWN','de');
$this->assertTrue(false,'Exception expected because of unknown type');
} catch (Exception $e) {
return true; // Test OK
}
}
/**
* test for exception unknown value
* expected exception
*/
public function testWeightSetUnknownValue()
{
try {
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('novalue',Zend_Measure_Weight::STANDARD,'de');
$this->assertTrue(false,'Exception expected because of empty value');
} catch (Exception $e) {
return; // Test OK
}
}
/**
* test for exception unknown locale
* expected exception
*/
public function testWeightSetUnknownLocale()
{
try {
$value = new Zend_Measure_Weight('100',Zend_Measure_Weight::STANDARD,'de');
$value->setValue('200',Zend_Measure_Weight::STANDARD,'nolocale');
$this->assertTrue(false,'Exception expected because of unknown locale');
} catch (Exception $e) {
return true; // Test OK
}
}
/**
* test for exception unknown locale
* expected exception
*/
public function testMeasureSetWithNoLocale()
{
$value = new Zend_Measure_Weight('100', Zend_Measure_Weight::STANDARD, 'de');
$value->setValue('200', Zend_Measure_Weight::STANDARD);
$this->assertEquals(200, $value->getValue(), 'Zend_Measure_Weight value expected to be a positive integer');
}
/**
* test setting type
* expected new type
*/
public function testWeightSetType()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$value->setType(Zend_Measure_Weight::GRAM);
$this->assertEquals($value->getType(), Zend_Measure_Weight::GRAM, 'Zend_Measure_Weight type expected');
}
/**
* test setting computed type
* expected new type
*/
public function testWeightSetComputedType1()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::DRAM,'de');
$value->setType(Zend_Measure_Weight::OUNCE);
$this->assertEquals($value->getType(), Zend_Measure_Weight::OUNCE, 'Zend_Measure_Weight type expected');
}
/**
* test setting computed type
* expected new type
*/
public function testWeightSetComputedType2()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::OUNCE,'de');
$value->setType(Zend_Measure_Weight::DRAM);
$this->assertEquals($value->getType(), Zend_Measure_Weight::DRAM, 'Zend_Measure_Weight type expected');
}
/**
* test setting unknown type
* expected new type
*/
public function testWeightSetTypeFailed()
{
try {
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$value->setType('Weight::UNKNOWN');
$this->assertTrue(false,'Exception expected because of unknown type');
} catch (Exception $e) {
return true; // OK
}
}
/**
* test toString
* expected string
*/
public function testWeightToString()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals($value->toString(), '-100 kg', 'Value -100 kg expected');
}
/**
* test __toString
* expected string
*/
public function testWeight_ToString()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$this->assertEquals($value->__toString(), '-100 kg', 'Value -100 kg expected');
}
/**
* test getConversionList
* expected array
*/
public function testWeightConversionList()
{
$value = new Zend_Measure_Weight('-100',Zend_Measure_Weight::STANDARD,'de');
$unit = $value->getConversionList();
$this->assertTrue(is_array($unit), 'Array expected');
}
}