Prototype: NewBalanceAccount() *BalanceAccount, Balance() int, Deposit(amount) (int,error) positive only; Withdraw(amount) (bool,error) positive only, false unchanged if insufficient.

Final: NewBank() *Bank. Every identifier is nonempty; invalid IDs error. CreateAccount(id) (bool,error) creates zero balance/spending, false if already present without resetting. Balance(id) (*int,error) nil unknown. Deposit(id,amount) (*int,error) validates positive amount before missing-account lookup. Transfer(request,source,target string,amount int) (*TransferResult,error) first validates positive amount/IDs. Exact successful retry returns the original balances; conflicting use errors. New missing/same-account/insufficient requests return nil unchanged and consume no ID. Success moves funds, increments source outgoing total, records result. TopSpenders(limit) ([]Spending,error) includes zero spenders, sorts total descending then ID ascending; zero empty, negative error.

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.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.