aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2026-05-01 22:39:26 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2026-05-01 22:39:26 +0300
commit47dfe9ab7a4a658ece8b8cca08489d53758b249b (patch)
tree84b2b7eb4534e1f24007b17a7216374e0323929f /tests
parente560c40a9ce3902e655f34078382a52d9b85be1b (diff)
downloadfwd-47dfe9ab7a4a658ece8b8cca08489d53758b249b.tar.gz
fwd-47dfe9ab7a4a658ece8b8cca08489d53758b249b.zip
add sum test
Diffstat (limited to 'tests')
-rw-r--r--tests/sum/sum.fwd28
-rw-r--r--tests/sum/test.mk1
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/sum/sum.fwd b/tests/sum/sum.fwd
new file mode 100644
index 0000000..05a4632
--- /dev/null
+++ b/tests/sum/sum.fwd
@@ -0,0 +1,28 @@
+import "../../mod/libfwdio.so"
+
+sum_inner(i32 s, i32 n, (i32) res)
+{
+ if n <= 0 as i32 {
+ res(s);
+ } else {
+ sum_inner(s + n, n - 1 as i32, res);
+ }
+}
+
+sum(i32 n, (i32) res)
+{
+ sum_inner(0 as i32, n, res);
+}
+
+main()
+{
+ sum(1000000 as i32) => i32 s;
+ if s != 1784293664 as i32 {
+ fwdprint_str("expected 1784293664, got ");
+ fwdprint_i64(s as i64);
+ fwdprint_nl();
+ } else {
+ fwdprint_str("OK");
+ fwdprint_nl();
+ }
+}
diff --git a/tests/sum/test.mk b/tests/sum/test.mk
new file mode 100644
index 0000000..9836826
--- /dev/null
+++ b/tests/sum/test.mk
@@ -0,0 +1 @@
+XPASS += sum