Baseline: tree as shared
This commit is contained in:
commit
659c03bbf8
1471 files changed
+990535
No files matched your search
@@ -0,0 +1,33 @@
|
||||
# probe: a struct method that raises, caught by the caller
|
||||
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
|
||||
# expect-stdout: withdrew 30 left 120
|
||||
# expect-stdout: refused 200 : insufficient funds
|
||||
# expect-stdout: withdrew 120 left 0
|
||||
# expect-stdout: ada 0
|
||||
struct Account(Movable):
|
||||
var owner: String
|
||||
var balance: Int
|
||||
|
||||
def __init__(out self, owner: String, balance: Int):
|
||||
self.owner = owner
|
||||
self.balance = balance
|
||||
|
||||
def withdraw(mut self, amount: Int) raises:
|
||||
if amount > self.balance:
|
||||
raise Error("insufficient funds")
|
||||
self.balance -= amount
|
||||
|
||||
def deposit(mut self, amount: Int):
|
||||
self.balance += amount
|
||||
|
||||
|
||||
def main():
|
||||
var acct = Account("ada", 100)
|
||||
acct.deposit(50)
|
||||
for amount in [30, 200, 120]:
|
||||
try:
|
||||
acct.withdraw(amount)
|
||||
print("withdrew", amount, "left", acct.balance)
|
||||
except e:
|
||||
print("refused", amount, ":", e)
|
||||
print(acct.owner, acct.balance)
|
||||
Reference in new issue
Block a user