Skip to content

Commit 2c663ca

Browse files
author
William Yang
committed
Migrate checks from TypeScript to Python (bootcs format)
- Replace TypeScript check files with Python __init__.py - Use .bootcs.yml config format - Add expected output files for mario-less - Update .gitignore to exclude __pycache__
1 parent 73753d7 commit 2c663ca

File tree

13 files changed

+183
-193
lines changed

13 files changed

+183
-193
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ Thumbs.db
1717
*.o
1818
*.exe
1919
*.out
20+
21+
# Python
22+
__pycache__/
23+
*.pyc

checks/cash/.bootcs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bootcs:
2+
files:
3+
- !include "*.c"

checks/cash/__init__.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Cash check - adapted from cs50/problems/cash
3+
"""
4+
5+
from bootcs.check import check, exists, run
6+
from bootcs.check import c
7+
8+
9+
@check()
10+
def file_exists():
11+
"""cash.c exists"""
12+
exists("cash.c")
13+
14+
15+
@check(file_exists)
16+
def compiles():
17+
"""cash.c compiles"""
18+
c.compile("cash.c")
19+
20+
21+
@check(compiles)
22+
def test041():
23+
"""input of 41 yields output of 4"""
24+
run("./cash").stdin("41").stdout(coins(4), "4\n").exit(0)
25+
26+
27+
@check(compiles)
28+
def test001():
29+
"""input of 1 yields output of 1"""
30+
run("./cash").stdin("1").stdout(coins(1), "1\n").exit(0)
31+
32+
33+
@check(compiles)
34+
def test015():
35+
"""input of 15 yields output of 2"""
36+
run("./cash").stdin("15").stdout(coins(2), "2\n").exit(0)
37+
38+
39+
@check(compiles)
40+
def test160():
41+
"""input of 160 yields output of 7"""
42+
run("./cash").stdin("160").stdout(coins(7), "7\n").exit(0)
43+
44+
45+
@check(compiles)
46+
def test230():
47+
"""input of 2300 yields output of 92"""
48+
run("./cash").stdin("2300").stdout(coins(92), "92\n").exit(0)
49+
50+
51+
@check(compiles)
52+
def test_reject_negative():
53+
"""rejects a negative input like -1"""
54+
run("./cash").stdin("-1").reject()
55+
56+
57+
def coins(num):
58+
"""regex that matches `num` not surrounded by any other numbers"""
59+
return fr"(?<!\d){num}(?!\d)"

checks/cash/checks.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

checks/hello/.bootcs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bootcs:
2+
files:
3+
- !include "*.c"

checks/hello/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Hello check - adapted from cs50/problems/hello
3+
"""
4+
5+
from bootcs.check import check, exists, run
6+
from bootcs.check import c
7+
8+
9+
@check()
10+
def file_exists():
11+
"""hello.c exists"""
12+
exists("hello.c")
13+
14+
15+
@check(file_exists)
16+
def compiles():
17+
"""hello.c compiles"""
18+
c.compile("hello.c")
19+
20+
21+
@check(compiles)
22+
def prints_hello():
23+
"""prints hello"""
24+
# 简化版:只检查输出包含 hello
25+
run("./hello").stdout("[Hh]ello").exit(0)

checks/hello/checks.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

checks/mario-less/.bootcs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bootcs:
2+
files:
3+
- !include "*.c"

checks/mario-less/1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

checks/mario-less/2.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#
2+
##

0 commit comments

Comments
 (0)