Prototype: SplitEqual(total int,participants []string) (map[string]int,error) requires total>=0 and nonempty distinct nonempty names; divide equally, first total%count lexicographically sorted names get one extra cent. Return every share including zero, preserve input; Go map iteration unordered.
Final: NewExpenseSharing(members []string) (*ExpenseSharing,error) copies fixed nonempty distinct nonempty group, balances zero. AddExpense(op,payer string,total int,participants []string) (bool,error) requires nonempty op, positive total, known payer and nonempty distinct known participants; payer may be absent. Credit total to payer, debit exact equal shares; new success true. Settle(op,debtor,creditor string,amount int) (bool,error) structurally requires nonempty op, distinct known members and positive amount; new success requires debtor balance<=-amount and creditor>=amount, then increases debtor/decreases creditor. Both methods validate structure first, recognize exact successful retry next (false unchanged), then perform balance checks. Expense identity ignores participant order. Any accepted op reused with changed data or other method errors; failed requests do not consume op. Balances() map[string]int fresh all members including zeros; positive owed, negative owes, sum zero. SuggestSettlements() []Settlement copies balances, sorts debtor/creditor names separately, pairs first remaining for smaller amount, advances exhausted sides, no zero transfers, no mutation. All integers fit int.
All identifiers and strings compare exactly and case-sensitively. Numeric inputs are typed int; booleans cannot be passed as amounts. Arithmetic and logical timestamps fit int. All supplied collection inputs that are retained must be copied. Every collection or pointer snapshot must be detached; separate service instances own independent state. A nil pointer or nil optional slice denotes absence, while an ordinary empty result collection is nonnil. Invalid calls leave state unchanged unless the contract explicitly accepts time and expires state on a valid unsuccessful call. The exported signatures in exercise.go are the API specification.
Edit exercise.go; retain the public types and signatures. prototype and final are separate stages. The executable tests recover panics as failures, report named checks, and exit nonzero on any failure. A successful run must execute at least one check. Tests use logical time or explicit synchronization where relevant.
Complete the starter code, then run the checks.
Results and errors will appear here.