public function testConversions() { $volume = new Volume(1, 'l'); $this->assertEquals(1, $volume->toUnit('l')); $this->assertEquals(10.0, $volume->toUnit('dl')); $this->assertEquals(100.0, $volume->toUnit('cl')); $this->assertEquals(1000.0, $volume->toUnit('ml'), null, 0.0001); $volume = new Volume(1, 'dl'); $this->assertEquals(0.1, $volume->toUnit('l')); $this->assertEquals(1, $volume->toUnit('dl')); $this->assertEquals(10.0, $volume->toUnit('cl')); $this->assertEquals(100.0, $volume->toUnit('ml')); $volume = new Volume(1, 'cl'); $this->assertEquals(0.01, $volume->toUnit('l')); $this->assertEquals(0.1, $volume->toUnit('dl')); $this->assertEquals(1, $volume->toUnit('cl')); $this->assertEquals(10.0, $volume->toUnit('ml')); $volume = new Volume(1, 'ml'); $this->assertEquals(0.001, $volume->toUnit('l'), null, 0.0001); $this->assertEquals(0.01, $volume->toUnit('dl')); $this->assertEquals(0.1, $volume->toUnit('cl')); $this->assertEquals(1, $volume->toUnit('ml')); }
/** * Calculate the effects of adding a compound. * * Returns a solution object where the water in the tank is the solvent and * the added compound is the solute. * * @param CompoundInterface $compound Compound added. * * @return Solution Tank water as a solution. */ public function effectsOf(CompoundInterface $compound) { return new Solution($compound, new Volume($this->volume->toUnit() + $compound->getVolume()->toUnit())); }
/** * Gets wet compound dose by name and quantity. * * @param string $compoundId Wet compound name. * @param Volume $volume Quantity of the compound. * * @return Solution Solution object. */ public function getWetCompound($compoundId, Volume $volume = null) { if (!array_key_exists($compoundId, $this->data['wetCompounds'])) { return null; } if ($volume === null) { $volume = new Volume(1); } $compound = new Compound($this->data['wetCompounds'][$compoundId], new Mass($volume->toUnit('l'))); return new Solution($compound, $volume); }