Multiple changes and improvements

* Base and NicotineBase separated
* Importer bugfixed
* Mixer improved
This commit is contained in:
2019-07-09 02:10:56 +02:00
parent 6e662f0263
commit 922d9f09dd
14 changed files with 302 additions and 44 deletions

View File

@ -5,55 +5,74 @@ namespace NoccyLabs\Juicer\Recipe\Mixer;
use NoccyLabs\Juicer\Recipe\Recipe;
use NoccyLabs\Juicer\Ingredient\Ingredient;
use NoccyLabs\Juicer\Ingredient\Base;
use NoccyLabs\Juicer\Recipe\RecipeInterface;
class MixerTest extends \PhpUnit\Framework\TestCase
{
public function testMixingEmptyRecipesWithVg()
public function getDataForEmptyRecipes()
{
$recipe = new Recipe();
$mixer = new Mixer();
$base = new Base("VG100");
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
$this->assertCount(1, $mixed);
$mixedVg = reset($mixed);
$this->assertEquals(10, $mixedVg->getVolume());
$this->assertEquals("VG", $mixedVg->getFlavorName());
return [
[ 'VG100', 10, [ 'VG' => 10 ], 10 ],
[ 'PG100', 10, [ 'PG' => 10 ], 10 ],
[ 'VG70', 10, [ 'VG' => 7, 'PG' => 3 ], 10 ],
[ 'VG50', 10, [ 'VG' => 5, 'PG' => 5 ], 10 ]
];
}
public function testMixingEmptyRecipesWithPg()
/**
* @dataProvider getDataForEmptyRecipes
*/
public function testMixingEmptyRecipes($base, $amount, array $assertBases, $assertAmount)
{
$recipe = new Recipe();
$mixer = new Mixer();
$base = new Base("PG100");
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
$base = new Base($base);
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0);
$this->assertCount(1, $mixed);
$mixedPg = reset($mixed);
$this->assertEquals(10, $mixedPg->getVolume());
$this->assertEquals("PG", $mixedPg->getFlavorName());
$this->assertCount(count($assertBases), $mixed);
$mixedAmount = 0;
foreach ($mixed as $measured) {
$name = $measured->getFlavorName();
if (!array_key_exists($name, $assertBases)) {
$this->assertFail("Mixed contains unexpected ingredients");
}
$mixedAmount += $measured->getVolume();
}
$this->assertEquals($assertAmount, $mixedAmount);
}
public function testMixingEmptyRecipesWith70Vg30Pg()
public function getDataForDummyRecipes()
{
$ingredientA1 = new Ingredient("Ingredient A1", null, 2);
$ingredientA2 = new Ingredient("Ingredient A2", null, 3);
$recipeA = new Recipe();
$recipeA->setRecipeName("Recipe A");
$recipeA->addIngredient($ingredientA1);
$recipeA->addIngredient($ingredientA2);
return [
[ $recipeA, 'VG70', 10 ],
];
}
/**
* @dataProvider getDataForDummyRecipes
*/
public function testMixingDummyRecipes(RecipeInterface $recipe, $base, $amount)
{
$recipe = new Recipe();
$mixer = new Mixer();
$base = new Base($base);
$mixed = $mixer->mixRecipe($recipe, $amount, $base, 0);
$base = new Base("VG70");
$mixed = $mixer->mixRecipe($recipe, 10, $base, 0);
$expectedCount = count($base->getComponents()) + count($recipe->getIngredients());
$this->assertCount(2, $mixed);
$mixedVg = array_shift($mixed);
$this->assertEquals(10, $mixedVg->getVolume());
$this->assertEquals("VG", $mixedVg->getFlavorName());
$mixedPg = array_shift($mixed);
$this->assertEquals(10, $mixedPg->getVolume());
$this->assertEquals("PG", $mixedPg->getFlavorName());
$this->assertCount($expectedCount, $mixed);
$mixedAmount = 0;
foreach ($mixed as $measured) {
$mixedAmount += $measured->getVolume();
}
$this->assertEquals($amount, $mixedAmount);
}
}