From 2009a26e17ad9dbefee3a5ca4339d754e51ef078 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 15 Feb 2026 00:04:23 +0900 Subject: refactor: write more tests in C --- tests/functions.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/functions.c') diff --git a/tests/functions.c b/tests/functions.c index eef9496..6e4622c 100644 --- a/tests/functions.c +++ b/tests/functions.c @@ -1,4 +1,5 @@ #include +#include int sprintf(char*, const char*, ...); @@ -99,6 +100,17 @@ int f10() { return 12345; } +int sum(int n, ...) { + va_list args; + va_start(args, n); + int s = 0; + for (int i = 0; i < n; ++i) { + s += va_arg(args, int); + } + va_end(args); + return s; +} + // recursive functions int fib(int n) { if (n <= 1) { @@ -154,6 +166,8 @@ int main() { int (*fp4)(int, int, int, int, int, int, int, int, int, int, int) = f7; ASSERT_EQ(7, fp4(6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + ASSERT_EQ(400, sum(5, 100, 90, 80, 70, 60)); + // recursive functions ASSERT_EQ(89, fib(10)); } -- cgit v1.3-1-g0d28