Verbessere die Berechnung der Geschenkekosten in FalukantService und füge Tests für die Funktion hinzu
This commit is contained in:
20
backend/tools/simulate_getGiftCost.js
Normal file
20
backend/tools/simulate_getGiftCost.js
Normal file
@@ -0,0 +1,20 @@
|
||||
function getGiftCostLocal(value, titleOfNobility, lowestTitleOfNobility) {
|
||||
const val = Number(value) || 0;
|
||||
const title = Number(titleOfNobility) || 1;
|
||||
const lowest = Number(lowestTitleOfNobility) || 1;
|
||||
const titleLevel = title - lowest + 1;
|
||||
const cost = Math.round(val * Math.pow(1 + titleLevel * 0.3, 1.3) * 100) / 100;
|
||||
return Number.isFinite(cost) ? cost : 0;
|
||||
}
|
||||
|
||||
const cases = [
|
||||
{ giftValue: 100, title: 3, lowest: 1 },
|
||||
{ giftValue: '200', title: '2', lowest: '1' },
|
||||
{ giftValue: null, title: null, lowest: null },
|
||||
{ giftValue: undefined, title: undefined, lowest: undefined },
|
||||
{ giftValue: 'abc', title: 5, lowest: 1 }
|
||||
];
|
||||
|
||||
for (const c of cases) {
|
||||
console.log(`in=${JSON.stringify(c)} -> cost=${getGiftCostLocal(c.giftValue, c.title, c.lowest)}`);
|
||||
}
|
||||
Reference in New Issue
Block a user