From bf1769cef65a8ccc81faaf645c5d574e8c5e2981 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sun, 19 Sep 2021 17:50:01 +0800 Subject: [PATCH] nac3standalone: more tests --- nac3standalone/demo.c | 3 ++- nac3standalone/mandelbrot.py | 39 ++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/nac3standalone/demo.c b/nac3standalone/demo.c index beefe0b..cdd6d39 100644 --- a/nac3standalone/demo.c +++ b/nac3standalone/demo.c @@ -11,7 +11,8 @@ int output(int x) { if(x < strlen(chars)) { putchar(chars[x]); } else { - printf("ERROR\n"); + // printf("ERROR\n"); + printf("%d", x); } } return 0; diff --git a/nac3standalone/mandelbrot.py b/nac3standalone/mandelbrot.py index ac222f2..7afd28a 100644 --- a/nac3standalone/mandelbrot.py +++ b/nac3standalone/mandelbrot.py @@ -1,13 +1,34 @@ -def run() -> int32: +def y_scale(maxX: float, minX: float, height: float, width: float, aspectRatio: float) -> float: + return (maxX-minX)*(height/width)*aspectRatio + +def check_smaller_than_sixteen(i: int32) -> bool: + return i < 16 + +def rec(x: int32): + if x > 1: + output(x) + rec(x - 1) + return + else: + output(-1) + return + +def fib(n: int32) -> int32: + if n <= 2: + return 1 + else: + return fib(n - 1) + fib(n - 2) + +def draw(): minX = -2.0 maxX = 1.0 width = 78.0 height = 36.0 aspectRatio = 2.0 - test = 1.0 + 1 + # test = 1.0 + 1 - yScale = (maxX-minX)*(height/width)*aspectRatio + yScale = y_scale(maxX, minX, height, width, aspectRatio) y = 0.0 while y < height: @@ -18,7 +39,7 @@ def run() -> int32: z_r = c_r z_i = c_i i = 0 - while i < 16: + while check_smaller_than_sixteen(i): if z_r*z_r + z_i*z_i > 4.0: break new_z_r = (z_r*z_r)-(z_i*z_i) + c_r @@ -29,5 +50,15 @@ def run() -> int32: x = x + 1.0 output(-1) y = y + 1.0 + + return + +def run() -> int32: + rec(5) + + output(fib(10)) + output(-1) + + draw() return 0