Skip to content

Commit

Permalink
test: add complete transforms sequence tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Jan 14, 2025
1 parent f6b83ee commit 6b17d9e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Data/Component.elm
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ applyTransforms transforms (Results materialResults) =
transformImpacts =
Impact.sumImpacts
[ process.impacts
-- Note: impacts are always computed from input mass
-- Note: impacts are always computed from input mass
|> Impact.multiplyBy (Mass.inKilograms mass)

-- FIXME: we should also add elec and heat impacts, but using what
Expand Down
39 changes: 39 additions & 0 deletions tests/Data/ComponentTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,45 @@ suite =
|> Expect.within (Expect.Absolute 0.00001) 30
)
]
, let
results =
Component.Results
{ impacts = Impact.empty |> Impact.insertWithoutAggregateComputation Definition.Ecs (Unit.impact 100)
, items = []
, mass = Mass.kilogram
}
|> Component.applyTransforms
[ { fading
| waste = Split.half
, impacts =
fading.impacts
|> Impact.insertWithoutAggregateComputation Definition.Ecs (Unit.impact 10)
}
, { fading
| waste = Split.half
, impacts =
fading.impacts
|> Impact.insertWithoutAggregateComputation Definition.Ecs (Unit.impact 20)
}
]
in
describe "impacts & waste"
-- Note: impacts are always computed from input mass
-- 100 + (1kg * 10) + (0.5kg * 20) = 120
[ asTest "should handle impacts+waste when applying transforms: impacts"
(Component.extractImpacts results
|> Impact.getImpact Definition.Ecs
|> Unit.impactToFloat
|> Expect.within (Expect.Absolute 0.00001) 120
)

-- (1kg * 0.5) * 0.5 == 0.25
, asTest "should handle impacts+waste when applying transforms: mass"
(Component.extractMass results
|> Mass.inKilograms
|> Expect.within (Expect.Absolute 0.00001) 0.25
)
]
]
, describe "compute"
[ asTest "should compute results from decoded component items"
Expand Down

0 comments on commit 6b17d9e

Please sign in to comment.