Files
Viper_RegressionTesting/G3/App/main.vp
T
TermiNexus ee6461be46 chore(comments): Test 仓注释英文化(R11)
把 81 个 .vp 文件的中文 # 注释与三引号文档串改写为简洁英文,每个连续注释块 <=2 行;运行时中文字符串字面量(testcheck.begin/print 等用户可见消息)保持原样。骨架比对 HEAD 与工作区 112 文件漂移 0,全量 77/77 顺序回归通过。
2026-10-05 22:43:38 +08:00

63 lines
1.5 KiB
Plaintext

import t
import stdio
import testcheck
from linkedlist import GSListNode
# ============================================================
# G3: test F-bounded polymorphism.
# class Node(GSListNode[Node]) inherits a generic base specialized on itself.
# ============================================================
@t.NoVTable
class Node(GSListNode[Node]):
value: int
def __init__(self):
self.value = 0
self.Next = None
def test_node_create():
testcheck.section("Test 1: Node(GSListNode[Node]) create")
n: Node = Node()
n.value = 42
testcheck.check(n.value == 42, "Node.value = 42", "expect 42")
def test_node_next_field():
testcheck.section("Test 2: Next field from GSListNode[Node]")
n1: Node = Node()
n2: Node = Node()
n1.value = 10
n2.value = 20
n1.Next = n2
next_node: Node = n1.Next
v: int = next_node.value
testcheck.check(v == 20, "n1.Next.value = 20", "expect 20")
def test_node_chain():
testcheck.section("Test 3: Node chain traversal")
a: Node = Node()
b: Node = Node()
c: Node = Node()
a.value = 1
b.value = 2
c.value = 3
a.Next = b
b.Next = c
sum: int = a.value
p: Node = a.Next
sum = sum + p.value
p = p.Next
sum = sum + p.value
testcheck.check(sum == 6, "chain sum = 1+2+3 = 6", "expect 6")
def main() -> int:
testcheck.begin("G3: GSListNode inheritance (F-bounded polymorphism)")
test_node_create()
test_node_next_field()
test_node_chain()
return testcheck.end()