summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/compile/tmandelbrot.nim53
-rw-r--r--tests/accept/run/tanontuples.nim15
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/accept/compile/tmandelbrot.nim b/tests/accept/compile/tmandelbrot.nim
new file mode 100644
index 000000000..54724d247
--- /dev/null
+++ b/tests/accept/compile/tmandelbrot.nim
@@ -0,0 +1,53 @@
+# -*- nimrod -*-
+
+import math
+import os
+import strutils
+
+type TComplex = tuple[re, im: float]
+
+proc `+` (a, b: TComplex): TComplex =
+    return (a.re + b.re, a.im + b.im)
+
+proc `*` (a, b: TComplex): TComplex =
+    result.re = a.re * b.re - a.im * b.im
+    result.im = a.re * b.im + a.im * b.re
+
+proc abs2 (a: TComplex): float =
+    return a.re * a.re + a.im * a.im
+
+var size    = parseInt (paramStr (1))
+var bit     = 128
+var byteAcc = 0
+
+stdout.writeln ("P4")
+stdout.write ($size)
+stdout.write (" ")
+stdout.writeln ($size)
+
+var fsize = float (size)
+for y in 0 .. size-1:
+    var fy = 2.0 * float (y) / fsize - 1.0
+    for x in 0 .. size-1:
+        var z = (0.0, 0.0)
+        var c = (float (2*x) / fsize - 1.5, fy)
+
+        block iter:
+            for i in 0 .. 49:
+                z = z*z + c
+                if abs2 (z) >= 4.0:
+                    break iter
+            byteAcc = byteAcc + bit
+
+        if bit > 1:
+            bit = bit div 2
+        else:
+            stdout.write (chr (byteAcc))
+            bit     = 128
+            byteAcc = 0
+
+    if bit != 128:
+        stdout.write (chr (byteAcc))
+        bit     = 128
+        byteAcc = 0
+
diff --git a/tests/accept/run/tanontuples.nim b/tests/accept/run/tanontuples.nim
new file mode 100644
index 000000000..a2babf038
--- /dev/null
+++ b/tests/accept/run/tanontuples.nim
@@ -0,0 +1,15 @@
+discard """
+  output: "61, 125"
+"""
+
+proc `^` (a, b: int): int =
+  result = 1
+  for i in 1..b: result = result * a
+
+var m = (0, 5)
+var n = (56, 3)
+
+m = (n[0] + m[1], m[1] ^ n[1])
+
+echo m[0], ", ", m[1]
+