Skip to content

Commit ecc3bfd

Browse files
committed
update cash checks
1 parent 4880c33 commit ecc3bfd

File tree

2 files changed

+30
-64
lines changed

2 files changed

+30
-64
lines changed

cash/.cs50.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
check50:
2-
files: &check50_files # "Alias", in YAML-speak, for the files we include in check50
2+
files: &check50_files
33
- !exclude "*"
44
- !require cash.c
55

66
submit50:
7-
files: *check50_files # Accessing the same files for submit50
7+
files: *check50_files

cash/__init__.py

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,66 @@
11
import check50
22
import check50.c
3-
import re
3+
44

55
@check50.check()
66
def exists():
77
"""cash.c exists"""
88
check50.exists("cash.c")
99

10-
# Include additional unit testing file
11-
check50.include("testing.c")
1210

1311
@check50.check(exists)
1412
def compiles():
1513
"""cash.c compiles"""
16-
# Check if student code compiles
1714
check50.c.compile("cash.c", lcs50=True)
18-
19-
# Rename main function to "distro_main"
20-
cash = re.sub("int\s+main", "int distro_main", open("cash.c").read())
2115

22-
# Read testing file
23-
testing = open("testing.c").read()
2416

25-
# Combine student code and testing file
26-
with open("cash_test.c", "w") as f:
27-
f.write(cash)
28-
f.write("\n")
29-
f.write(testing)
17+
@check50.check(compiles)
18+
def test041():
19+
"""input of 41 yields output of 4"""
20+
check50.run("./cash").stdin("41").stdout(coins(4), "4\n").exit(0)
3021

31-
check50.c.compile("cash_test.c", lcs50=True)
3222

3323
@check50.check(compiles)
34-
def cents():
35-
"""get_cents returns integer number of cents"""
36-
check50.run("./cash_test 0").stdin("100", prompt = True).stdout("100").exit()
24+
def test001():
25+
"""input of 1 yields output of 1"""
26+
check50.run("./cash").stdin("1").stdout(coins(1), "1\n").exit(0)
3727

38-
@check50.check(compiles)
39-
def negative():
40-
"""get_cents rejects negative input"""
41-
check50.run("./cash_test 0").stdin("-10", prompt = True).reject()
4228

4329
@check50.check(compiles)
44-
def test_reject_foo():
45-
"""get_cents rejects a non-numeric input of "foo" """
46-
check50.run("./cash_test 0").stdin("foo", prompt = True).reject()
30+
def test015():
31+
"""input of 15 yields output of 2"""
32+
check50.run("./cash").stdin("15").stdout(coins(2), "2\n").exit(0)
4733

48-
@check50.check(compiles)
49-
def quarters0():
50-
"""calculate_quarters returns 2 when input is 50"""
51-
check50.run("./cash_test 1").stdout("2")
5234

5335
@check50.check(compiles)
54-
def quarters1():
55-
"""calculate_quarters returns 1 when input is 42"""
56-
check50.run("./cash_test 2").stdout("1")
36+
def test160():
37+
"""input of 160 yields output of 7"""
38+
check50.run("./cash").stdin("160").stdout(coins(7), "7\n").exit(0)
5739

58-
@check50.check(compiles)
59-
def dimes0():
60-
"""calculate_dimes returns 1 when input is 10"""
61-
check50.run("./cash_test 3").stdout("1")
6240

6341
@check50.check(compiles)
64-
def dimes1():
65-
"""calculate_dimes returns 1 when input is 15"""
66-
check50.run("./cash_test 4").stdout("1")
42+
def test230():
43+
"""input of 2300 yields output of 92"""
44+
check50.run("./cash").stdin("2300").stdout(coins(92), "92\n").exit(0)
6745

68-
@check50.check(compiles)
69-
def dimes2():
70-
"""calculate_dimes returns 7 when input is 73"""
71-
check50.run("./cash_test 8").stdout("7")
72-
73-
@check50.check(compiles)
74-
def nickels0():
75-
"""calculate_nickels returns 1 when input is 5"""
76-
check50.run("./cash_test 5").stdout("1")
7746

7847
@check50.check(compiles)
79-
def nickels1():
80-
"""calculate_nickels returns 5 when input is 28"""
81-
check50.run("./cash_test 6").stdout("5")
48+
def test_reject_negative():
49+
"""rejects a negative input like -1"""
50+
check50.run("./cash").stdin("-1").reject()
8251

83-
@check50.check(compiles)
84-
def pennies():
85-
"""calculate_pennies returns 4 when input is 4"""
86-
check50.run("./cash_test 7").stdout("4")
87-
8852

8953
@check50.check(compiles)
90-
def test41():
91-
"""input of 41 cents yields output of 4 coins"""
92-
output = check50.run("./cash").stdin("41", prompt = True).stdout("4\n").exit()
54+
def test_reject_foo():
55+
"""rejects a non-numeric input of "foo" """
56+
check50.run("./cash").stdin("foo").reject()
57+
9358

9459
@check50.check(compiles)
95-
def test160():
96-
"""input of 160 cents yields output of 7 coins"""
97-
check50.run("./cash").stdin("160", prompt = True).stdout("7\n").exit()
60+
def test_reject_empty():
61+
"""rejects a non-numeric input of "" """
62+
check50.run("./cash").stdin("").reject()
63+
9864

9965
def coins(num):
10066
# regex that matches `num` not surrounded by any other numbers (so coins(2) won't match e.g. 123)

0 commit comments

Comments
 (0)