1 | <?php |
||
20 | class QuantityParserTest extends StringValueParserTest { |
||
21 | |||
22 | /** |
||
23 | * @deprecated since DataValues Common 0.3, just use getInstance. |
||
24 | */ |
||
25 | protected function getParserClass() { |
||
28 | |||
29 | /** |
||
30 | * @see ValueParserTestBase::getInstance |
||
31 | * |
||
32 | * @return QuantityParser |
||
33 | */ |
||
34 | protected function getInstance() { |
||
37 | |||
38 | /** |
||
39 | * @param ParserOptions|null $options |
||
40 | * |
||
41 | * @return QuantityParser |
||
42 | */ |
||
43 | private function getQuantityParser( ParserOptions $options = null ) { |
||
62 | |||
63 | /** |
||
64 | * @see ValueParserTestBase::validInputProvider |
||
65 | */ |
||
66 | public function validInputProvider() { |
||
67 | $amounts = array( |
||
68 | // amounts in various styles and forms |
||
69 | '0' => UnboundedQuantityValue::newFromNumber( 0, '1' ), |
||
70 | '-0' => UnboundedQuantityValue::newFromNumber( 0, '1' ), |
||
71 | '-00.00' => UnboundedQuantityValue::newFromNumber( '+0.00', '1' ), |
||
72 | '+00.00' => UnboundedQuantityValue::newFromNumber( '+0.00', '1' ), |
||
73 | '0001' => UnboundedQuantityValue::newFromNumber( 1, '1' ), |
||
74 | '+01' => UnboundedQuantityValue::newFromNumber( 1, '1' ), |
||
75 | '-1' => UnboundedQuantityValue::newFromNumber( -1, '1' ), |
||
76 | '+42' => UnboundedQuantityValue::newFromNumber( 42, '1' ), |
||
77 | ' - 42' => UnboundedQuantityValue::newFromNumber( -42, '1' ), |
||
78 | '9001' => UnboundedQuantityValue::newFromNumber( 9001, '1' ), |
||
79 | '.5' => UnboundedQuantityValue::newFromNumber( '+0.5', '1' ), |
||
80 | '-.125' => UnboundedQuantityValue::newFromNumber( '-0.125', '1' ), |
||
81 | '3.' => UnboundedQuantityValue::newFromNumber( 3, '1' ), |
||
82 | ' 3 ' => UnboundedQuantityValue::newFromNumber( 3, '1' ), |
||
83 | '2.125' => UnboundedQuantityValue::newFromNumber( '+2.125', '1' ), |
||
84 | '2.1250' => UnboundedQuantityValue::newFromNumber( '+2.1250', '1' ), |
||
85 | |||
86 | '1.4e-2' => QuantityValue::newFromNumber( '+0.014', '1', '+0.015', '+0.013' ), |
||
87 | '-1.4e-2' => QuantityValue::newFromNumber( '-0.014', '1', '-0.013', '-0.015' ), |
||
88 | '1.4e3' => QuantityValue::newFromNumber( '+1400', '1', '+1500', '+1300' ), |
||
89 | '1.4e3!m' => QuantityValue::newFromNumber( '+1400', 'm', '+1400', '+1400' ), |
||
90 | '1.4e3m2' => QuantityValue::newFromNumber( '+1400', 'm2', '+1500', '+1300' ), |
||
91 | '1.4ev' => UnboundedQuantityValue::newFromNumber( '+1.4', 'ev' ), |
||
92 | '1.4e' => UnboundedQuantityValue::newFromNumber( '+1.4', 'e' ), |
||
93 | '12e3e4' => QuantityValue::newFromNumber( '+12000', 'e4', '+13000', '+11000' ), |
||
94 | // FIXME: Add support for 12x10^3, see DecimalParser. |
||
95 | '0.004e3' => QuantityValue::newFromNumber( '+4', '1', '+5', '+3' ), |
||
96 | '0.004e-3' => QuantityValue::newFromNumber( '+0.000004', '1', '+0.000005', '+0.000003' ), |
||
97 | '4000e3' => QuantityValue::newFromNumber( '+4000000', '1', '+4001000', '+3999000' ), |
||
98 | '4000e-3' => QuantityValue::newFromNumber( '+4.000', '1', '+4.001', '+3.999' ), |
||
99 | |||
100 | // precision |
||
101 | '0!' => QuantityValue::newFromNumber( 0, '1', 0, 0 ), |
||
102 | '10.003!' => QuantityValue::newFromNumber( '+10.003', '1', '+10.003', '+10.003' ), |
||
103 | '-200!' => QuantityValue::newFromNumber( -200, '1', -200, -200 ), |
||
104 | '0~' => UnboundedQuantityValue::newFromNumber( 0, '1' ), |
||
105 | '10.003~' => UnboundedQuantityValue::newFromNumber( '+10.003', '1' ), |
||
106 | '-200~' => UnboundedQuantityValue::newFromNumber( -200, '1' ), |
||
107 | |||
108 | // uncertainty |
||
109 | '5.3 +/- 0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
110 | '5.3+-0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
111 | '5.3 ±0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
112 | |||
113 | '5.3 +/- +0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
114 | '5.3+-+0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
115 | |||
116 | '5.3e3 +/- 0.2e2' => QuantityValue::newFromNumber( '+5300', '1', '+5320', '+5280' ), |
||
117 | '2e-2+/-1.1e-1' => QuantityValue::newFromNumber( '+0.02', '1', '+0.13', '-0.09' ), |
||
118 | |||
119 | // negative |
||
120 | '5.3 +/- -0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
121 | '5.3+--0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
122 | '5.3 ±-0.2' => QuantityValue::newFromNumber( '+5.3', '1', '+5.5', '+5.1' ), |
||
123 | |||
124 | // units |
||
125 | '5.3+-0.2cm' => QuantityValue::newFromNumber( '+5.3', 'cm', '+5.5', '+5.1' ), |
||
126 | '10.003! km' => QuantityValue::newFromNumber( '+10.003', 'km', '+10.003', '+10.003' ), |
||
127 | '-200~ % ' => UnboundedQuantityValue::newFromNumber( -200, '%' ), |
||
128 | '100003 m³' => UnboundedQuantityValue::newFromNumber( 100003, 'm³' ), |
||
129 | '3.±-0.2µ' => QuantityValue::newFromNumber( '+3', 'µ', '+3.2', '+2.8' ), |
||
130 | '+00.20 Å' => UnboundedQuantityValue::newFromNumber( '+0.20', 'Å' ), |
||
131 | ); |
||
132 | |||
133 | $argLists = array(); |
||
134 | |||
135 | foreach ( $amounts as $amount => $expected ) { |
||
136 | //NOTE: PHP may "helpfully" have converted $amount to an integer. Yay. |
||
137 | $argLists[$amount] = array( strval( $amount ), $expected ); |
||
138 | } |
||
139 | |||
140 | return $argLists; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @see StringValueParserTest::invalidInputProvider |
||
145 | */ |
||
146 | public function invalidInputProvider() { |
||
198 | |||
199 | public function testParseLocalizedQuantity() { |
||
233 | |||
234 | /** |
||
235 | * @dataProvider unitOptionProvider |
||
236 | */ |
||
237 | public function testUnitOption( $value, $unit, $expected ) { |
||
246 | |||
247 | public function unitOptionProvider() { |
||
256 | |||
257 | /** |
||
258 | * @dataProvider conflictingUnitOptionProvider |
||
259 | */ |
||
260 | public function testConflictingUnitOption( $value, $unit ) { |
||
269 | |||
270 | public function conflictingUnitOptionProvider() { |
||
277 | |||
278 | } |
||
279 |