Browse Source

add some trivial emscripten test cases

pull/1/head
Sami Vaarala 11 years ago
parent
commit
8c06a31cab
  1. 18
      emscripten-testcases/fizzbuzz.c
  2. 11
      emscripten-testcases/helloworld.c
  3. 52
      emscripten-testcases/mandelbrot.c

18
emscripten-testcases/fizzbuzz.c

@ -0,0 +1,18 @@
/*
* Fizzbuzz test case.
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
int i;
for (i = 1; i <= 100; i++) {
if ((i % 3) == 0) { printf("Fizz"); }
if ((i % 5) == 0) { printf("Buzz"); }
if ((i % 3) && (i % 5)) { printf("%d", i); }
printf("\n");
}
return 0;
}

11
emscripten-testcases/helloworld.c

@ -0,0 +1,11 @@
/*
* Hello World test case.
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello world!\n");
return 0;
}

52
emscripten-testcases/mandelbrot.c

@ -0,0 +1,52 @@
/*
* Mandelbrot test case.
*/
#include <stdio.h>
int main(int argc, char *argv[]) {
int w = 80;
int h = 40;
int iter = 100;
int i, j, k;
double x0, y0, xx, yy, xx2, yy2;
char row[80+1];
char c;
for (i = 0; i < h; i++) {
y0 = (double) i / (double) h * 4.0 - 2.0;
for (j = 0; j < w; j++) {
x0 = (double) j / (double) w * 4.0 - 2.0;
xx = 0.0;
yy = 0.0;
c = '#';
for (k = 0; k < iter; k++) {
/* z -> z^2 + c
* -> (xx+i*yy)^2 + (x0+i*y0)
* -> xx*xx+i*2*xx*yy-yy*yy + x0 + i*y0
* -> (xx*xx - yy*yy + x0) + i*(2*xx*yy + y0)
*/
xx2 = xx * xx;
yy2 = yy * yy;
if (xx2 + yy2 < 4.0) {
yy = 2 * xx * yy + y0;
xx = xx2 - yy2 + x0;
} else {
c = '.';
break;
}
}
row[j] = c;
}
row[j] = (char) 0;
printf("%s\n", row);
}
return 0;
}
Loading…
Cancel
Save