232 lines
6.3 KiB
C#
232 lines
6.3 KiB
C#
namespace TinyCC.E2ETests;
|
|
|
|
/// <summary>
|
|
/// 端到端测试用例集合
|
|
/// </summary>
|
|
public static class TestCases
|
|
{
|
|
/// <summary>
|
|
/// 获取所有基础测试用例
|
|
/// </summary>
|
|
public static IEnumerable<TestCase> GetBasicTests()
|
|
{
|
|
// 最简单的测试:返回常量
|
|
yield return new TestCase(
|
|
Name: "simple_return_zero",
|
|
SourceCode: """
|
|
int main() {
|
|
return 0;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 返回常量 42
|
|
yield return new TestCase(
|
|
Name: "simple_return_42",
|
|
SourceCode: """
|
|
int main() {
|
|
return 42;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 42
|
|
);
|
|
|
|
// 算术运算测试 - 使用 if-else 替代三元运算符
|
|
yield return new TestCase(
|
|
Name: "arithmetic_add",
|
|
SourceCode: """
|
|
int add(int a, int b) {
|
|
return a + b;
|
|
}
|
|
int main() {
|
|
int result;
|
|
result = add(3, 4);
|
|
if (result == 7) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 控制流测试 - for 循环
|
|
yield return new TestCase(
|
|
Name: "control_flow_for_loop",
|
|
SourceCode: """
|
|
int main() {
|
|
int sum;
|
|
int i;
|
|
sum = 0;
|
|
for (i = 1; i <= 10; i = i + 1) {
|
|
sum = sum + i;
|
|
}
|
|
if (sum == 55) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 控制流测试 - while 循环
|
|
yield return new TestCase(
|
|
Name: "control_flow_while_loop",
|
|
SourceCode: """
|
|
int main() {
|
|
int sum;
|
|
int i;
|
|
sum = 0;
|
|
i = 1;
|
|
while (i <= 10) {
|
|
sum = sum + i;
|
|
i = i + 1;
|
|
}
|
|
if (sum == 55) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 函数调用测试
|
|
yield return new TestCase(
|
|
Name: "function_call",
|
|
SourceCode: """
|
|
int multiply(int a, int b) {
|
|
return a * b;
|
|
}
|
|
int main() {
|
|
int result;
|
|
result = multiply(6, 7);
|
|
if (result == 42) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 条件分支测试
|
|
yield return new TestCase(
|
|
Name: "conditional_branch",
|
|
SourceCode: """
|
|
int max(int a, int b) {
|
|
if (a > b) {
|
|
return a;
|
|
} else {
|
|
return b;
|
|
}
|
|
}
|
|
int main() {
|
|
int result;
|
|
result = max(10, 20);
|
|
if (result == 20) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 变量赋值测试
|
|
yield return new TestCase(
|
|
Name: "variable_assignment",
|
|
SourceCode: """
|
|
int main() {
|
|
int x;
|
|
x = 42;
|
|
if (x == 42) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 递归函数测试
|
|
yield return new TestCase(
|
|
Name: "recursive_factorial",
|
|
SourceCode: """
|
|
int factorial(int n) {
|
|
if (n <= 1) {
|
|
return 1;
|
|
}
|
|
return n * factorial(n - 1);
|
|
}
|
|
int main() {
|
|
int result;
|
|
result = factorial(5);
|
|
if (result == 120) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 局部变量作用域测试
|
|
yield return new TestCase(
|
|
Name: "local_variable_scope",
|
|
SourceCode: """
|
|
int main() {
|
|
int x;
|
|
x = 10;
|
|
if (x > 5) {
|
|
int y;
|
|
y = 20;
|
|
x = y;
|
|
}
|
|
if (x == 20) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取预期失败的测试用例(用于记录当前不支持的功能)
|
|
/// </summary>
|
|
public static IEnumerable<TestCase> GetKnownFailures()
|
|
{
|
|
// 指针测试 - 当前可能不支持
|
|
yield return new TestCase(
|
|
Name: "pointers_basic",
|
|
SourceCode: """
|
|
int main() {
|
|
int x = 42;
|
|
int *p = &x;
|
|
return *p == 42 ? 0 : 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
|
|
// 数组测试 - 当前可能不支持
|
|
yield return new TestCase(
|
|
Name: "arrays_basic",
|
|
SourceCode: """
|
|
int main() {
|
|
int arr[3];
|
|
arr[0] = 1;
|
|
arr[1] = 2;
|
|
arr[2] = 3;
|
|
return arr[1] == 2 ? 0 : 1;
|
|
}
|
|
""",
|
|
ExpectedExitCode: 0
|
|
);
|
|
}
|
|
}
|