Skip to content

Commit

Permalink
test: elm test for durability and airTransportRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
vjousse committed Sep 18, 2024
1 parent 90948a1 commit f5e155b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Data/Textile/Simulator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ computeMakingAirTransportRatio ({ durability, inputs } as simulator) =
Split.third

else
-- FIXME: how about faling back to coutry default?
-- Spli.full ?
country.airTransportRatio
-- FIXME: how about falling back to country default?
-- country.airTransportRatio
Split.full
}
)

Expand Down
52 changes: 52 additions & 0 deletions tests/Data/Textile/SimulatorTest.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Data.Textile.SimulatorTest exposing (..)

import Data.Country as Country
import Data.Impact as Impact
import Data.Impact.Definition as Definition
import Data.Split as Split
import Data.Textile.Economics as Economics
import Data.Textile.LifeCycle as LifeCycle
import Data.Textile.Query exposing (Query, tShirtCotonFrance)
import Data.Textile.Simulator as Simulator
Expand Down Expand Up @@ -81,6 +84,55 @@ suite =
)
]
]
, let
tShirtCotonWithSmallerPhysicalDurability =
{ tShirtCotonFrance
| numberOfReferences = Just 10
, price = Just <| Economics.priceFromFloat 100
, physicalDurability = Just <| Unit.physicalDurability 1
}
in
describe "compute holistic durability"
[ tShirtCotonFrance
|> Simulator.compute db
|> Result.map .durability
|> Expect.equal (Ok { physical = Unit.physicalDurability 1.45, nonPhysical = Unit.nonPhysicalDurability 0.67 })
|> asTest "should have default durability"
, { physical = Unit.physicalDurability 1.45, nonPhysical = Unit.nonPhysicalDurability 0.67 }
|> Unit.floatDurabilityFromHolistic
|> Expect.within (Expect.Absolute 0.001) 0.67
|> asTest "should take the min of the two durabilities"
, tShirtCotonWithSmallerPhysicalDurability
|> Simulator.compute db
|> Result.map .durability
|> Expect.equal (Ok { physical = Unit.physicalDurability 1, nonPhysical = Unit.nonPhysicalDurability 1.19 })
|> asTest "should take into account when non physical durability changes"
, tShirtCotonWithSmallerPhysicalDurability
|> Simulator.compute db
|> Result.map (.durability >> Unit.floatDurabilityFromHolistic)
|> Expect.equal (Ok 1)
|> asTest "should return non physical durability if it is the smallest"
]
, describe "compute airTransporRatio"
[ tShirtCotonFrance
|> Simulator.compute db
|> Result.map (.lifeCycle >> LifeCycle.getStepProp Label.Making .airTransportRatio Split.half)
|> Expect.equal (Ok Split.zero)
|> asTest "should be zero for products from Europe or Turkey"
, { tShirtCotonFrance | countryMaking = Just (Country.Code "CN") }
|> Simulator.compute db
|> Result.map (.lifeCycle >> LifeCycle.getStepProp Label.Making .airTransportRatio Split.half)
|> Expect.equal (Ok Split.full)
|> asTest "should be full for products not coming from Europe or Turkey"
, { tShirtCotonFrance
| countryMaking = Just (Country.Code "CN")
, airTransportRatio = Just Split.two
}
|> Simulator.compute db
|> Result.map (.lifeCycle >> LifeCycle.getStepProp Label.Making .airTransportRatio Split.half)
|> Expect.equal (Ok Split.two)
|> asTest "should keep the user provided value"
]
, describe "getTotalImpactsWithoutComplements"
[ tShirtCotonFrance
|> Simulator.compute db
Expand Down

0 comments on commit f5e155b

Please sign in to comment.