Skip to content

Commit

Permalink
Merge pull request #13 from brewerwall/feature/more-water-calculations
Browse files Browse the repository at this point in the history
Boil Off Volume and Post Boil Volume Water Calculations
  • Loading branch information
griffithben authored Oct 12, 2023
2 parents 31c983d + 2635717 commit 22b72b0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ ___
Parts Per Million (PPM) is a calculation to determine the amount of a substance in a solution.

```php
Water::partsPerMillion(float $amount, Volume $volume): float
Water::partsPerMillion(Weight $substance, Volume $volume): float
```

##### Arguments
Expand All @@ -516,4 +516,43 @@ Water::partsPerMillion(float $amount, Volume $volume): float

##### Returns

- `float` - Parts Per Million (PPM) Value
- `float` - Parts Per Million (PPM) Value

---

#### Boil Off Volume

Boil Off Volume determines the Volume boiled off based on Boil Rate and Time.

```php
Water::boilOffVolume(Boil $boilRate, Time $time): Volume
```

##### Arguments

- `Boil $boilRate` - Boil Rate of your system
- `Time $time` - Time of the boil

##### Returns

- `Volume` - Volume that has been boiled off

---

#### Post Boil Volume

Post Boil Volume determines the Volume solution remaining after a Pre Boil Volume, Boil Rate and Time are given.

```php
Water::boilOffVolume(Volume postBoilVolume, Boil $boilRate, Time $time): Volume
```

##### Arguments

- `Volume $preBoilVolume` - Volume of solution before it's boiled
- `Boil $boilRate` - Boil Rate of your system
- `Time $time` - Time of the boil

##### Returns

- `Volume` - Volume that remains from the boil
31 changes: 31 additions & 0 deletions src/Calculate/Water.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Unitz\Calculate;

use InvalidArgumentException;
use Unitz\Rate\Boil;
use Unitz\Time;
use Unitz\Volume;
use Unitz\Weight;

Expand All @@ -26,5 +28,34 @@ public static function partsPerMillion(Weight $substance, Volume $water): float

return ($substance->getGram() / $water->getMilliliter()) * 1000000;
}

/**
* Boil Off Volume
*
* Gets the Volume of solution based on the Boil Rate and Time
*
* @param \Unitz\Rate\Boil $boilRate
* @param \Unitz\Time $time
* @return \Unitz\Volume
*/
public static function boilOffVolume(Boil $boilRate, Time $time): Volume
{
return new Volume(gallon: $boilRate->getGallonsPerHour()->getGallon() * $time->getHour());
}

/**
* Post Boil Volume
*
* Gets the post boil volume of solution
*
* @param \Unitz\Volume $preBoilVolume
* @param \Unitz\Rate\Boil $boilRate
* @param \Unitz\Time $time
* @return \Unitz\Volume
*/
public static function postBoilVolume(Volume $preBoilVolume, Boil $boilRate, Time $time): Volume
{
return new Volume(gallon: $preBoilVolume->getGallon() - self::boilOffVolume($boilRate, $time)->getGallon());
}
}

23 changes: 23 additions & 0 deletions tests/Calculate/WaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Unitz\Calculate\Water;
use Unitz\Rate\Boil;
use Unitz\Time;
use Unitz\Volume;
use Unitz\Weight;

Expand All @@ -30,4 +32,25 @@ public function testPartsPerMillionThrowsInvalidArgumentExceptionWithZeroWater()

Water::partsPerMillion($substance, $water);
}

public function testBoilOffVolumeReturnsCorrectVolume(): void
{
$boilRate = new Boil(new Volume(gallon: 2), new Time(hour: 1));
$time = new Time(hour: 1.5);
$expected = new Volume(gallon: 3);

$actual = Water::boilOffVolume($boilRate, $time);
$this->assertEquals($expected, $actual);
}

public function testPostBoilVolumeReturnsCorrectVolume(): void
{
$preBoilVolume = new Volume(gallon: 10);
$boilRate = new Boil(new Volume(gallon: 2), new Time(hour: 1));
$time = new Time(hour: 1.5);
$expected = new Volume(gallon: 7);

$actual = Water::postBoilVolume($preBoilVolume, $boilRate, $time);
$this->assertEquals($expected, $actual);
}
}

0 comments on commit 22b72b0

Please sign in to comment.