Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit 798c65d

Browse files
committed
新增综合字段赋值测试用例
新增 `comprehensive_field_test.cn` 文件,用于测试类中多个字段的赋值和访问功能。该测试用例创建了一个 `Student` 类,并演示了如何初始化对象、修改多个字段、以及单独修改字段。同时,测试了字段访问和赋值的混合使用,以确保字段赋值功能的完整性和正确性。
1 parent ff58172 commit 798c65d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

comprehensive_field_test.cn

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// 综合字段赋值测试
2+
3+
using lib<io>;
4+
5+
class Student {
6+
public name : string;
7+
public age : int;
8+
public grade : string;
9+
public score : int;
10+
11+
constructor(name : string, age : int, grade : string, score : int) {
12+
this.name = name;
13+
this.age = age;
14+
this.grade = grade;
15+
this.score = score;
16+
};
17+
18+
public fn getInfo() : string {
19+
return this.name + " (" + this.age + "岁, " + this.grade + "年级, 分数: " + this.score + ")";
20+
};
21+
};
22+
23+
fn main() : int {
24+
std::println("=== 综合字段赋值测试 ===");
25+
26+
// 创建学生对象
27+
student : Student = new Student("小明", 15, "高一", 85);
28+
29+
std::println("初始信息: " + student.getInfo());
30+
31+
// 测试多个字段赋值
32+
student.name = "小红";
33+
student.age = 16;
34+
student.grade = "高二";
35+
student.score = 92;
36+
37+
std::println("修改后信息: " + student.getInfo());
38+
39+
// 测试单独字段修改
40+
student.score = 95;
41+
std::println("提高分数后: " + student.getInfo());
42+
43+
// 测试字段访问和赋值混合
44+
old_score : int = student.score;
45+
student.score = old_score + 3;
46+
std::println("再次提高分数: " + student.getInfo());
47+
48+
return 0;
49+
};

0 commit comments

Comments
 (0)