import type { BigNumber } from "@ethersproject/bignumber" ; import { Zero } from "@ethersproject/constants" ; import { expect } from "chai" ; import { toBn } from "evm-bn" ; import forEach from "mocha-each" ; import { exp } from "../../../src/functions" ; import { EPSILON } from "../../shared/constants" ; export function shouldBehaveLikeExp ( ) { context ( "when x is zero" , function ( ) { it ( "returns 1" , function ( ) { const x = Zero ; const expected = toBn ( "1" ) ; expect ( expected ) . to . equal ( exp ( x ) ) ; } ) ; } ) ; context ( "when x is negative" , function ( ) { const testSets = [ "-20.82" , "-16" , "-11.89215" , "-4" , "-3.14" , "-3" , "-2.71" , "-2" , "-1" ] ; forEach ( testSets ) . it ( "takes %f and returns the correct value" , function ( x ) { const expected = Number ( toBn ( String ( Math . exp ( Number ( x ) ) ) ) ) ; const result = Number ( exp ( toBn ( x ) ) ) ; expect ( expected ) . to . be . closeTo ( result , EPSILON ) ; } ) ; } ) ; context ( "when x is positive" , function ( ) { const testSets = [ "1" , "2" , "2.71" , "3" , "3.14" , "4" , "11.89215" , "16" , "20.82" ] ; forEach ( testSets ) . it ( "takes %f and returns the correct value" , function ( x ) { const expected = Number ( toBn ( String ( Math . exp ( Number ( x ) ) ) ) ) ; const result = Number ( exp ( toBn ( x ) ) ) ; expect ( expected ) . to . be . closeTo ( result , EPSILON ) ; } ) ; } ) ; }