@@ -30,6 +30,7 @@ describe("PreciseUnitMath", () => {
3030
3131 // Used to make sure rounding is done correctly, 1020408168544454473
3232 const preciseNumber = BigNumber . from ( "0x0e2937d2abffc749" ) ;
33+ const negativePreciseNumber = preciseNumber . mul ( - 1 ) ;
3334
3435 before ( async ( ) => {
3536 [
@@ -236,6 +237,93 @@ describe("PreciseUnitMath", () => {
236237 } ) ;
237238 } ) ;
238239
240+ describe ( "#preciseDivCeil: int256" , async ( ) => {
241+ let subjectA : BigNumber ;
242+ let subjectB : BigNumber ;
243+
244+ async function subject ( ) : Promise < BigNumber > {
245+ return mathMock . preciseDivCeilInt ( subjectA , subjectB ) ;
246+ }
247+
248+ describe ( "when a and b are positive" , ( ) => {
249+ beforeEach ( async ( ) => {
250+ subjectA = preciseNumber ;
251+ subjectB = ether ( .3 ) ;
252+ } ) ;
253+
254+ it ( "returns the correct number" , async ( ) => {
255+ const division = await subject ( ) ;
256+
257+ const expectedDivision = preciseDivCeilInt ( subjectA , subjectB ) ;
258+ expect ( division ) . to . eq ( expectedDivision ) ;
259+ } ) ;
260+ } ) ;
261+
262+ describe ( "when a and b are negative" , ( ) => {
263+ beforeEach ( async ( ) => {
264+ subjectA = negativePreciseNumber ;
265+ subjectB = ether ( - .3 ) ;
266+ } ) ;
267+
268+ it ( "returns the correct number" , async ( ) => {
269+ const division = await subject ( ) ;
270+
271+ const expectedDivision = preciseDivCeilInt ( subjectA , subjectB ) ;
272+ expect ( division ) . to . eq ( expectedDivision ) ;
273+ } ) ;
274+ } ) ;
275+
276+ describe ( "when a is positive and b is negative" , ( ) => {
277+ beforeEach ( async ( ) => {
278+ subjectA = preciseNumber ;
279+ subjectB = ether ( - .3 ) ;
280+ } ) ;
281+
282+ it ( "returns the correct number" , async ( ) => {
283+ const division = await subject ( ) ;
284+
285+ const expectedDivision = preciseDivCeilInt ( subjectA , subjectB ) ;
286+ expect ( division ) . to . eq ( expectedDivision ) ;
287+ } ) ;
288+ } ) ;
289+
290+ describe ( "when a is negative and b is positive" , ( ) => {
291+ beforeEach ( async ( ) => {
292+ subjectA = negativePreciseNumber ;
293+ subjectB = ether ( .3 ) ;
294+ } ) ;
295+
296+ it ( "returns the correct number" , async ( ) => {
297+ const division = await subject ( ) ;
298+
299+ const expectedDivision = preciseDivCeilInt ( subjectA , subjectB ) ;
300+ expect ( division ) . to . eq ( expectedDivision ) ;
301+ } ) ;
302+ } ) ;
303+
304+ describe ( "when a is 0" , async ( ) => {
305+ beforeEach ( async ( ) => {
306+ subjectA = ZERO ;
307+ } ) ;
308+
309+ it ( "should return 0" , async ( ) => {
310+ const division = await subject ( ) ;
311+ expect ( division ) . to . eq ( ZERO ) ;
312+ } ) ;
313+ } ) ;
314+
315+ describe ( "when b is 0" , async ( ) => {
316+ beforeEach ( async ( ) => {
317+ subjectA = ZERO ;
318+ subjectB = ZERO ;
319+ } ) ;
320+
321+ it ( "should revert" , async ( ) => {
322+ await expect ( subject ( ) ) . to . be . revertedWith ( "Cant divide by 0" ) ;
323+ } ) ;
324+ } ) ;
325+ } ) ;
326+
239327 describe ( "#divDown: int256" , async ( ) => {
240328 let subjectA : BigNumber ;
241329 let subjectB : BigNumber ;
0 commit comments