/**
  * Compound needed to reach a target concentration for an element.
  *
  * In case no element is specified the default proxy element for the
  * compound is used.
  *
  * @param Concentration $target Target concentration.
  * @param CompoundInterface $compound Compound to be added.
  * @param string|null $element Element used for target.
  *
  * @throws ImpossibleCalculation When the target concentration is impossible.
  *
  * @return float Times the compound should be added to reach the target.
  */
 public function targetElement(Concentration $target, CompoundInterface $compound, $element = null)
 {
     if ($target->toUnit() * $compound->getVolume()->toUnit() >= $compound->element($element)->toUnit()) {
         throw new ImpossibleCalculation();
     }
     return $target->toUnit() * $this->volume->toUnit() / ($compound->element($element)->toUnit() - $target->toUnit() * $compound->getVolume()->toUnit());
 }
 public function testConversions()
 {
     $concentration = new Concentration(1, 'g/l');
     $this->assertEquals(1000.0, $concentration->toUnit('mg/l'));
     $this->assertEquals(0.001, $concentration->toUnit('g/ml'));
     $this->assertEquals(1000.0, $concentration->toUnit('ppm'));
     $concentration = new Concentration(1, 'mg/l');
     $this->assertEquals(0.001, $concentration->toUnit('g/l'));
     $this->assertEquals(1.0E-6, $concentration->toUnit('g/ml'));
     $this->assertEquals(1, $concentration->toUnit('ppm'));
     $concentration = new Concentration(1, 'ppm');
     $this->assertEquals(1, $concentration->toUnit('mg/l'));
     $this->assertEquals(1.0E-6, $concentration->toUnit('g/ml'));
     $this->assertEquals(0.001, $concentration->toUnit('g/l'));
 }