"""Unit tests for bread calculation logic.""" import pytest from bread import BreadRecipe, SourdoughRatio class TestSourdoughRatio: """Test the SourdoughRatio model.""" def test_equal_parts_hydration(self): """Test 1:1 ratio gives 100% hydration.""" ratio = SourdoughRatio(flour_parts=1, water_parts=1) assert ratio.hydration_percentage == 100.0 def test_dry_starter_hydration(self): """Test 1:0.5 ratio gives 50% hydration.""" ratio = SourdoughRatio(flour_parts=1, water_parts=0.5) assert ratio.hydration_percentage == 50.0 def test_wet_starter_hydration(self): """Test 1:1.2 ratio gives 120% hydration.""" ratio = SourdoughRatio(flour_parts=1, water_parts=1.2) assert ratio.hydration_percentage == 120.0 def test_invalid_zero_flour(self): """Test that zero flour parts is rejected.""" with pytest.raises(ValueError): SourdoughRatio(flour_parts=0, water_parts=1) class TestBreadRecipe: """Test the BreadRecipe calculations.""" def test_sourdough_weight_calculation(self): """Test sourdough weight is correctly calculated.""" recipe = BreadRecipe( total_flour=1000, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=1), salt=2 ) assert recipe.sourdough_weight == 200.0 def test_water_in_sourdough_equal_ratio(self): """Test water calculation with 1:1 ratio.""" recipe = BreadRecipe( total_flour=1000, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=1), salt=2 ) assert recipe.water_in_sourdough == 100.0 assert recipe.flour_in_sourdough == 100.0 def test_water_in_sourdough_unequal_ratio(self): """Test water calculation with 1:0.8 ratio.""" recipe = BreadRecipe( total_flour=1000, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=0.8), salt=2 ) # 200g sourdough with 1:0.8 ratio # Total parts = 1.8 # Water = 200 * (0.8/1.8) = 88.89g # Flour = 200 * (1/1.8) = 111.11g assert recipe.water_in_sourdough == 88.89 assert recipe.flour_in_sourdough == 111.11 def test_flour_to_add(self): """Test flour to add calculation.""" recipe = BreadRecipe( total_flour=500, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=1), salt=2 ) # 500g total - 50g in sourdough = 450g to add assert recipe.flour_to_add == 450.0 def test_water_to_add(self): """Test water to add calculation.""" recipe = BreadRecipe( total_flour=500, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=1), salt=2 ) # Total water = 500 * 70% = 350g # Water in sourdough = 50g # Water to add = 350 - 50 = 300g assert recipe.water_to_add == 300.0 def test_salt_weight(self): """Test salt calculation.""" recipe = BreadRecipe( total_flour=500, hydration=70, sourdough_percentage=20, sourdough_ratio=SourdoughRatio(flour_parts=1, water_parts=1), salt=2 ) assert recipe.salt_weight == 10.0