-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of test macros and use + panic in images fix +
for i := num {
…
… fix (#229) * Start of test macros and use * Add comments * fix error handling for images (panic) * Fix that := wouldn't work in simple for loop * Add mandelbrot example (will be good to profile that one as it's slow) * optimize/avoid allocs, better colors
- Loading branch information
Showing
9 changed files
with
133 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#! /bin/bash | ||
set -e | ||
export GOMEMLIMIT=1GiB | ||
BIN="./grol -panic -shared-state" | ||
echo "---testing double format for grol_tests ---" | ||
$BIN -format grol_tests/*.gr > /tmp/format1 | ||
$BIN -format /tmp/format1 > /tmp/format2 | ||
diff -u /tmp/format1 /tmp/format2 | ||
$BIN -eval=false grol_tests/*.gr > /tmp/output1 | ||
$BIN /tmp/format2 > /tmp/output2 | ||
diff -u /tmp/output1 /tmp/output2 | ||
$BIN -format -compact grol_tests/*.gr > /tmp/format3 | ||
$BIN -format -compact /tmp/format3 > /tmp/format4 | ||
diff -u /tmp/format3 /tmp/format4 | ||
$BIN /tmp/format4 > /tmp/output3 | ||
diff -u /tmp/output1 /tmp/output3 | ||
echo "---done---" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
maxIter = 32 | ||
|
||
func mandelbrot(x, y) { | ||
m := maxIter // bind to global, prevents caching, save allocs/cache writes. | ||
zx := 0.0 | ||
zy := 0.0 | ||
for n := m { | ||
zx2 := zx * zx | ||
zy2 := zy * zy | ||
if zx2 + zy2 > 4.0 { | ||
return n | ||
} | ||
zy = 2 * zx * zy + y | ||
zx = zx2 - zy2 + x | ||
} | ||
m | ||
} | ||
|
||
size:=256 | ||
img:="img" | ||
image.new(img, size, size) | ||
|
||
now := time.now() | ||
for px := size { | ||
for py := size { | ||
x := (2.*px)/size - 1.5 | ||
y := (2.*py)/size - 1. | ||
m := mandelbrot(x, y) | ||
color := [0,0,0] | ||
if m != maxIter { | ||
norm := ln(m)/ln(maxIter) | ||
color = [ 0.5+cos(PI/3+norm*PI/4)/2., .9, .5] | ||
} | ||
image.set_hsl(img,px,py,color) | ||
} | ||
} | ||
elapsed := time.now() - now | ||
log("Elapsed time:", elapsed) | ||
image.save(img) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Library of macros for testing | ||
*/ | ||
|
||
// Convert any grol object to a string. | ||
func str(x) { | ||
sprintf("%v", x) | ||
} | ||
|
||
// Test for absence of error and that the expression's result matches a regexp. | ||
NoErr = macro(msg, expr, expectedRegexp) { | ||
quote(if (r = catch(unquote(expr))).err { | ||
error("FAIL unexpected error:", r.value, "for", unquote(msg)) | ||
} else { | ||
if (regexp(unquote(expectedRegexp), str(r.value))) { | ||
println("OK", unquote(msg), "is:", r.value) | ||
} else { | ||
error("FAIL", unquote(msg), "didn't match expected:", r.value) | ||
} | ||
}) | ||
} | ||
|
||
// Test for expected error and that the message matches a regexp. | ||
IsErr = macro(msg, expr, expectedRegexp) { | ||
quote(if (r = catch(unquote(expr))).err { | ||
if (regexp(unquote(expectedRegexp), str(r.value))) { | ||
println("OK", unquote(msg), "get expected error:", r.value) | ||
} else { | ||
error("FAIL", unquote(msg), "didn't match expected:", r.value) | ||
} | ||
} else { | ||
error("FAIL", unquote(msg),"didn't get expected error:",r.value) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,4 @@ | ||
// - Test constants | ||
|
||
/* | ||
NoErr = macro(expr,a,b) { | ||
quote( | ||
r = catch(unquote(expr)) | ||
if r.err { | ||
error("unexpected error:", r.value) | ||
unquote(a) | ||
} else { | ||
unquote(b) | ||
} | ||
) | ||
} | ||
*/ | ||
|
||
if (r=catch(PI)).err { | ||
error("unexpected error:", r.value) | ||
} else { | ||
println("PI is:", r.value) | ||
} | ||
|
||
|
||
if !(r=catch(PI++)).err { | ||
error("expected error, got ok", r) | ||
} else { | ||
if regexp("attempt to change constant PI", r.value) { | ||
println("Got expected error:", r.value) | ||
} else { | ||
error("unexpected error:", r.value) | ||
} | ||
} | ||
NoErr("PI should exist", PI, "3.141592") | ||
IsErr("Can't change a constant", PI++, "attempt to change constant PI") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
s :=0 | ||
// check that := works too in for loop. | ||
for n := 4 { | ||
s = s+ n | ||
} | ||
// 0 + 1 + 2 + 3 = 6 | ||
if s != 6 { | ||
error("Expected 6, got", s) // was 16 before the fix. | ||
} |