Open the context
Choose the project folder and name the files or behavior involved.
Return an exact uncorrected Gini fraction for 1–4096 nonnegative integer counts bounded by 10^9. Test equal counts, permutations and all-zero input, defining zero for the latter and rejecting Boolean values without making fairness judgments.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from fractions import Fraction
def gini_fraction(values):
if type(values) is not list or not 1 <= len(values) <= 4096 or any(type(x) is not int or not 0 <= x <= 10**9 for x in values):
raise ValueError("gini.values")
total, n = sum(values), len(values)
if total == 0:
return Fraction(0, 1)
numerator = sum((2*i-n-1)*value for i, value in enumerate(sorted(values), 1))
return Fraction(numerator, n*total)
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.