hourCostCents)->toBe(46125) ->and($profit->revenueCents())->toBe(112000) ->and($profit->marginCents())->toBe(55875) ->and($profit->marginRatio())->toEqualWithDelta(0.4989, 0.0001) ->and($profit->effectiveHourlyCents())->toBe(9756); }); it('leaves the cost of the hours and the margin out without an hourly cost', function () { $profit = Profit::of(8, 0, 50000, 0, 0, null); expect($profit->hourCostCents)->toBeNull() ->and($profit->marginCents())->toBeNull() ->and($profit->marginRatio())->toBeNull() ->and($profit->effectiveHourlyCents())->toBe(25000) ->and($profit->plus(Profit::of(4, 0, 0, 0, 0, 4500))->hourCostCents)->toBeNull(); }); it('has no margin ratio or hourly yield when nothing was billed or worked', function () { $profit = Profit::of(0, 0, 0, 0, 5000, 4500); expect($profit->marginCents())->toBe(-5000) ->and($profit->marginRatio())->toBeNull() ->and($profit->effectiveHourlyCents())->toBeNull(); }); it('splits the figures evenly so that the parts add up to the whole', function () { $profit = Profit::of(5, 4, 1001, 0, -7, 4500); $parts = $profit->split(3); expect(array_map(fn (Profit $part): int => $part->quarters, $parts))->toBe([2, 2, 1]) ->and(array_map(fn (Profit $part): int => $part->workCents, $parts))->toBe([334, 334, 333]) ->and(array_map(fn (Profit $part): int => $part->expenseCostCents, $parts))->toBe([-3, -2, -2]) ->and(array_sum(array_map(fn (Profit $part): int => (int) $part->hourCostCents, $parts)))->toBe($profit->hourCostCents) ->and($parts[0]->plus($parts[1])->plus($parts[2]))->toEqual($profit); });