assertSame('5.000', WeightEstimator::estimate('10斤/箱', '斤', '5')); $this->assertSame('6.000', WeightEstimator::estimate('', '公斤', '3')); $this->assertSame('6.000', WeightEstimator::estimate('', 'KG', '3')); $this->assertSame('1.000', WeightEstimator::estimate('', '克', '500')); } /** 规格解析每件重量 × 订货量 */ public function test_spec_per_unit_weight(): void { $this->assertSame('30.000', WeightEstimator::estimate('10斤/箱', '箱', '3')); $this->assertSame('75.000', WeightEstimator::estimate('25斤/袋', '袋', '3')); $this->assertSame('3.000', WeightEstimator::estimate('500g/袋', '袋', '3')); $this->assertSame('3.000', WeightEstimator::estimate('500克/袋', '袋', '3')); $this->assertSame('9.000', WeightEstimator::estimate('1.5kg/箱', '箱', '3')); $this->assertSame('12.000', WeightEstimator::estimate('2公斤/筐', '筐', '3')); $this->assertSame('15.000', WeightEstimator::estimate('10斤/箱', '箱', '1.5'), '订货量可为小数'); } /** 规格无法解析:裸数字按斤计,无数字计 0 */ public function test_unparsable_spec_fallback(): void { $this->assertSame('20.000', WeightEstimator::estimate('10/箱', '箱', '2'), '裸数字按斤计'); $this->assertSame('0.000', WeightEstimator::estimate('散装', '箱', '3')); $this->assertSame('0.000', WeightEstimator::estimate('', '箱', '3')); } }