import { createUtilityValue } from "./createUtilityValue" ; import { ScoringDirection , UtilityNumberValue } from "./types" ; describe ( "createUtilityValue" , ( ) => { const inputs = { health : 50 , money : 5 } ; const personality = { ambition : 50 as UtilityNumberValue , composure : 150 as UtilityNumberValue } ; test ( "should return the correct value" , ( ) => { const result = createUtilityValue ( [ { value : inputs . health , range : [ 1 , 100 ] , direction : ScoringDirection . Low , weighting : { value : personality . composure , direction : ScoringDirection . Low } } , { value : inputs . money , range : [ 1 , 55 ] , direction : ScoringDirection . High , weighting : { value : personality . ambition , direction : ScoringDirection . High } } ] ) ; const hV = ( ( inputs . health - 1 ) / 99 ) ; const cV = 1 - ( personality . composure / 200 ) ; const mV = ( ( inputs . money - 1 ) / 54 ) ; const aV = personality . ambition / 200 ; const healthValue = ( hV * 200 ) * cV ; const moneyValue = ( mV * 200 ) * aV ; const expected = Math . floor ( ( healthValue + moneyValue ) / 2 ) ; expect ( result ) . toEqual ( expected ) ; } ) ; } ) ;