Allocation
Allocation According to Ratios
import 'money2.dart';
test('Ratio', () {
final usd = CommonCurrencies().usd;
final profit = Money.fromBigIntWithCurrency(BigInt.from(5), usd); // 5¢
var allocation = profit.allocationAccordingTo([70, 30]);
expect(allocation[0],
equals(Money.fromBigIntWithCurrency(BigInt.from(4), usd))); // 4¢
expect(allocation[1],
equals(Money.fromBigIntWithCurrency(BigInt.from(1), usd))); // 1¢
/// The order of ratios is important:
allocation = profit.allocationAccordingTo([30, 70]);
expect(allocation[0],
equals(Money.fromBigIntWithCurrency(BigInt.from(2), usd))); // 2¢
expect(allocation[1],
equals(Money.fromBigIntWithCurrency(BigInt.from(3), usd))); // 3¢
});Allocation to N Targets
Last updated
Was this helpful?