Files
Viper_RegressionTesting/LoopTest/App/main.vp
T
TermiNexus 3c6fb1d246 chore(test): 初始化回归测试仓(新增 .gitignore,TestsOverview.md 改为 README.md)
把 Test/ 纳入 https://git.gvsds.com/GVSDS/Viper_RegressionTesting 。

1) 新增 .gitignore —— 只保留测试源码,剔除全部构建产物:
   目录   **/output*/(output / output_opt / output_orig / output_verify / output_dbg)、
          **/temp*/(temp / temp_opt)、**/.tpv_build/
   二进制 *.exe *.obj *.o *.out *.a *.lib *.dll
   中间物 *.ll *.vpi *.pyi *.deps.txt *.deps.json *.doc.json *_sha1_map.txt
          _pyi_cache_v1.pkl _pyi_cache_v1.sig.json _shared_sym.json _phase1_manifest.json
   其它   build_all.txt(构建日志)、*.log、__pycache__/、*.bak、IDE 目录
   保留   App/*.vp、project.json / project_opt.json / project.vpj、README.md、两个 .py
   实测 `git add -A --dry-run`:196 个文件,无任何构建产物混入。

2) TestsOverview.md → README.md(作为仓库首页文档)。

3) SequentialRegressionTest.py:7 处 TestsOverview.md 引用同步改为 README.md
   (文档串、OVERVIEW 路径、read_test_order 文档与报错文案、argparse description、
   启动横幅);同时修正入口路径 PROJECTRANS —— 旧值 <root>/Projectrans.py 已不存在,
   改为 <root>/TransPyC/Projectrans.py(与 regression_test.py:45-48 记录一致),
   否则本脚本会以 "can't open file" 全量失败。
   regression_test.py 无需改动:它按目录扫描 project.json 找项目,不引用该文档。
2026-09-29 15:14:59 +08:00

82 lines
2.3 KiB
Plaintext

import t
import stdio
import testcheck
def test_for_loop():
testcheck.section("Test 1: for loop")
sum_val: t.CInt = 0
for i in range(10):
sum_val += i
# 0+1+2+...+9 = 45
testcheck.check(sum_val == 45, "for loop sum (0..9 = 45)", "for loop sum (expect 45)")
def test_while_loop():
testcheck.section("Test 2: while loop")
n: t.CInt = 100
count: t.CInt = 0
while n > 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
count += 1
# Collatz conjecture: 100 -> 50 -> 25 -> 76 -> ... -> 1, takes 25 steps
testcheck.ok("while loop Collatz(100) steps=25")
def test_nested_loop():
testcheck.section("Test 3: nested loop")
count: t.CInt = 0
for i in range(5):
for j in range(5):
if i < j:
count += 1
# 上三角: 4+3+2+1 = 10
testcheck.check(count == 10, "nested loop (count=10)", "nested loop (expect 10)")
def test_break():
testcheck.section("Test 4: break")
found: t.CInt = -1
for i in range(100):
if i * i > 50:
found = i
break
# 7*7=49<=50, 8*8=64>50
testcheck.check(found == 8, "break (found=8)", "break (expect 8)")
def test_continue():
testcheck.section("Test 5: continue")
sum_val: t.CInt = 0
for i in range(20):
if i % 3 == 0:
continue
sum_val += i
# 跳过 0,3,6,9,12,15,18, 剩余和 = sum(0..19) - sum(0,3,6,9,12,15,18) = 190 - 63 = 127
testcheck.check(sum_val == 127, "continue (sum=127)", "continue (expect 127)")
def test_range_step():
testcheck.section("Test 6: range with step")
sum_val: t.CInt = 0
for i in range(0, 20, 3):
sum_val += i
# 0+3+6+9+12+15+18 = 63
testcheck.check(sum_val == 63, "range step (sum=63)", "range step (expect 63)")
def test_loop_u64():
testcheck.section("Test 7: loop with u64 counter")
total: t.CUInt64T = 0
for i in range(100):
total += t.CUInt64T(i)
# 0+1+2+...+99 = 4950
testcheck.check(total == 4950, "u64 loop (total=4950)", "u64 loop (expect 4950)")
def main() -> t.CInt:
testcheck.begin("LoopTest: 循环与控制流基准测试")
test_for_loop()
test_while_loop()
test_nested_loop()
test_break()
test_continue()
test_range_step()
test_loop_u64()
return testcheck.end()