-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(financial-calculating): add
calculateDiscountParentage
method (#…
…33) * feat(financial-calculating): add calculateDiscountPercentage function for discount percentage calculation * docs(financial-calculating): add tsDoc for new method * docs(financial-calculate): add Documentation for the new method * test(financial-calculating): write three test for calculate discount percentage * test(financial-calculating): update tests for calculateDiscountAmount and calculateDiscountedPrice functions * refactor(financial-calculating): separate calculateDiscountPercentage for calculate profit and discount * refactor(financial-calculating): rename discount percentage functions for clarity * lint: Make Happy :)
- Loading branch information
Showing
3 changed files
with
72 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
import test from 'ava'; | ||
|
||
import {calculateDiscountAmount, calculateDiscountedPrice} from '@nexim/financial-calculate'; | ||
|
||
test('calculate discount from price with: 3, 4 input', (test) => { | ||
import { | ||
calculateDiscountAmount, | ||
calculateDiscountedPrice, | ||
calculatePercentageDiscount, | ||
calculatePercentageProfit, | ||
} from '@nexim/financial-calculate'; | ||
|
||
test('calculate discount from price', (test) => { | ||
test.is(calculateDiscountAmount(3, 4), 0.12); | ||
}); | ||
|
||
test('calculateDiscountAmount(100, 10) returns 10.00', (t) => { | ||
t.is(calculateDiscountAmount(100, 10), 10); | ||
}); | ||
|
||
test('calculate price from discount with: 3, 4 input', (test) => { | ||
test.is(calculateDiscountedPrice(3, 4), 2.88); | ||
}); | ||
|
||
test('calculate discount from price with: 587, 629 input', (test) => { | ||
test.is(calculateDiscountAmount(100, 10), 10); | ||
test.is(calculateDiscountAmount(587, 629), 3692.23); | ||
}); | ||
|
||
test('calculate price from discount with: 587, 629 input', (test) => { | ||
test.is(calculateDiscountedPrice(587, 629), -3105.23); | ||
}); | ||
|
||
test('calculate discount from price with: 15034, 73 input', (test) => { | ||
test.is(calculateDiscountAmount(15034, 73), 10974.82); | ||
test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6); | ||
}); | ||
|
||
test('calculate price from discount with: 15034, 73 input', (test) => { | ||
test('calculate price from discount', (test) => { | ||
test.is(calculateDiscountedPrice(3, 4), 2.88); | ||
test.is(calculateDiscountedPrice(100, 10), 90); | ||
test.is(calculateDiscountedPrice(15034, 73), 4059.18); | ||
test.is(calculateDiscountedPrice(587, 629), -3105.23); | ||
test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6); | ||
}); | ||
|
||
test('calculate discount from price with: 54205, 1332, 5 input', (test) => { | ||
test.is(calculateDiscountAmount(54205, 1332, 5), 722010.6); | ||
test('calculate discount percentage for profit and discount', (test) => { | ||
test.is(calculatePercentageProfit(100, 80), 25); | ||
test.is(calculatePercentageProfit(100, 53), 88.68); | ||
}); | ||
|
||
test('calculate price from discount with: 54205, 1332, 5 input', (test) => { | ||
test.is(calculateDiscountedPrice(54205, 1332, 5), -667805.6); | ||
test('calculate discount percentage for profit', (test) => { | ||
test.is(calculatePercentageDiscount(100, 80, 1), 20); | ||
test.is(calculatePercentageDiscount(100, 53), 47); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters