chore(test): 迁移测试夹具到新语法
机械规则 R2/R3/R4/R6/R7/R8/R13 + R16 保守子集,共 86 文件 2127 行。R1(T | t.CPtr)与 R12(while 下标循环)未做,仍列为待办。全量 77/77 顺序回归通过。
This commit is contained in:
1 parent
c9d741c202
commit
f5da836fbb
86 files changed
+2121
-2121
No files matched your search
+10
-10
@@ -5,15 +5,15 @@ import testcheck
|
||||
|
||||
# 定义结构体
|
||||
class Point():
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
x: int
|
||||
y: int
|
||||
|
||||
class Rect():
|
||||
origin: Point
|
||||
size: Point
|
||||
|
||||
class Node():
|
||||
value: t.CInt
|
||||
value: int
|
||||
next: t.CPtr # Node* 类型
|
||||
|
||||
def test_struct_basic():
|
||||
@@ -38,7 +38,7 @@ def test_struct_pointer():
|
||||
p.x = 42
|
||||
p.y = 84
|
||||
# 取结构体指针
|
||||
pp: Point | t.CPtr = t.CPtr(t.CUInt64T(p))
|
||||
pp: Point | t.CPtr = t.CPtr(uint64(p))
|
||||
# 通过指针修改
|
||||
pp.x = 100
|
||||
pp.y = 200
|
||||
@@ -50,17 +50,17 @@ def test_struct_param():
|
||||
p: Point = Point()
|
||||
p.x = 5
|
||||
p.y = 15
|
||||
sum_val: t.CInt = point_sum(p)
|
||||
sum_val: int = point_sum(p)
|
||||
testcheck.check(sum_val == 20, "struct param (sum=20)", "struct param (sum expect 20)")
|
||||
|
||||
def point_sum(p: Point) -> t.CInt:
|
||||
def point_sum(p: Point) -> int:
|
||||
return p.x + p.y
|
||||
|
||||
def test_struct_array():
|
||||
testcheck.section("Test 5: struct array")
|
||||
# 分配结构体数组
|
||||
buf: t.CUInt8T | t.CPtr = w32.win32memory.VirtualAlloc(None, 256, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
buf: uint8 | t.CPtr = w32.win32memory.VirtualAlloc(None, 256, 12288, 4)
|
||||
if uint64(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
return
|
||||
string.memset(buf, 0, 256)
|
||||
@@ -70,12 +70,12 @@ def test_struct_array():
|
||||
pts[0].y = 2
|
||||
pts[1].x = 3
|
||||
pts[1].y = 4
|
||||
total: t.CInt = pts[0].x + pts[0].y + pts[1].x + pts[1].y
|
||||
total: int = pts[0].x + pts[0].y + pts[1].x + pts[1].y
|
||||
testcheck.check(total == 10, "struct array (total=10)", "struct array (total expect 10)")
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt:
|
||||
def main() -> int:
|
||||
testcheck.begin("StructTest: 结构体操作基准测试")
|
||||
test_struct_basic()
|
||||
test_struct_nested()
|
||||
|
||||
Reference in new issue
Block a user