# -*- shell-script -*-
# 
# Q.gam - the default test file that gets run if gammon is called
#    without arguments.
# 

topic "Q.h:"

header <<EOF
#include <stdio.h>

#include <Q.h>

int z = 0;
int o = 1;

#define N 5

int v[N] = { 0, 1, 2, 3, 4 };

float fv[N] = { 1.0, 2.0, 3.0, 4.0, 5.0 };

float fvsum = 1.0+2.0+3.0+4.0+5.0;

float fvprod = 1.0*2.0*3.0*4.0*5.0;

int m[N][N] = { 
    { 1, 0, 0, 0, 0 },
    { 0, 1, 0, 0, 0 },
    { 0, 0, 1, 0, 0 },
    { 0, 0, 0, 1, 0 },
    { 0, 0, 0, 0, 1 }
};

#define T E(int i = 0, i < N, i++, v[i] == 1)
#define F A(int i = 0, i < N, i++, v[i] > i)

int main() {
    printf("%d\n",
EOF

footer <<EOF
    );
}
EOF

title "basic tests for each routine"

checktrue "(A(int i = 0, i < N, i++, v[i] == i))"

checkfalse "(A(int i = 0, i < N, i++, v[i] > i))"

checktrue "(E(int i = 0, i < N, i++, v[i] == 4))"
checktrue "(E(int i = 0, i < N, i++, v[i] == 0))"
checktrue "(E(int i = 0, i < N, i++, v[i] == 1))"

checkfalse "(E(int i = 0, i < N, i++, v[i] == 5))"
checkfalse "(E(int i = 0, i < N, i++, v[i] == -1))"
checkfalse "(E(int i = 0, i < N, i++, v[i] > i))"

checktrue "(C(int i = 0, i < N, i++, 1) == N)"
checktrue "(C(int i = 0, i < N, i++, v[i] == 0) == 1)"
checktrue "(C(int i = 0, i < N, i++, v[i] == 4) == 1)"
checktrue "(C(int i = 0, i < N, i++, v[i] == 5) == 0)"

checktrue "(E1(int i = 0, i < N, i++, v[i] == 4))"
checktrue "(E1(int i = 0, i < N, i++, v[i] == 0))"
checktrue "(E1(int i = 0, i < N, i++, v[i] == 1))"

checkfalse "(E1(int i = 0, i < N, i++, v[i] > 4))"
checkfalse "(E1(int i = 0, i < N, i++, v[i] == -1))"

checktrue "(S(int i = 0, i < N, i++, v[i]) == 10)"
checktrue "(S(int i = 0, i < 0, i++, v[i]) == 0)"

checktrue "(S(int i = 0, i < N, i++, fv[i]) == fvsum)"
checktrue "(S(int i = 0, i < 0, i++, fv[i]) == 0.0)"

checktrue "(P(int i = 1, i < N, i++, v[i]) == 24)"
checktrue "(P(int i = 1, i < 0, i++, v[i]) == 1)"

checktrue "(P(int i = 0, i < N, i++, fv[i]) == fvprod)"
checktrue "(P(int i = 0, i < 0, i++, fv[i]) == 1.0)"

title "checking out nesting of operations"
    
checktrue "(A(int i = 0, i < N, i++, 
		A(int j = 0, j < N, j++, 
		  m[i][j] == ((i == j) ? 1 : 0))))"

checkfalse "(A(int i = 0, i < N, i++,
		A(int j = 0, j < N, j++, 
		  m[i][j] == 0)))"

checktrue "(A(int i = 0, i < N, i++,
		E(int j = 0, j < N, j++, 
		  m[i][j] == 1)))"

checkfalse "(E(int i = 0, i < N, i++,
		E(int j = 0, j < N, j++, 
		  m[i][j] == 2)))"

checktrue "(A(int i = 0, i < N, i++,
		E1(int j = 0, j < N, j++, 
		  m[i][j] == 1)))"

checkfalse "(A(int i = 0, i < N, i++,
		E1(int j = 0, j < N, j++, 
		  m[i][j] == 2)))"

checkfalse "(A(int i = 0, i < N, i++,
		E1(int j = 0, j < N, j++, 
		  m[i][j] == 0)))"

checkfalse "(A(int i = 0, i < N, i++,
		E1(int j = 0, j < N, j++, 
		  m[i][j] == 4)))"

checktrue "(S(int i = 0, i < N, i++,
	     (S(int j = 0, j < N, j++, m[i][j]))) == N)"

checktrue "(P(int i = 0, i < N, i++,
	     S(int j = 0, j < N, j++, m[i][j])) == 1)"

checktrue "(C(int i = 0, i < N, i++,
	     S(int j = 0, j < N, j++, m[i][j]) == 1) == N)"

checktrue "(C(int i = 0, i < N, i++,
	     S(int j = 0, j < N, j++, m[i][j]) == 2) == 0)"

checktrue "(A(int i = 0, i < N, i++,
	     C(int j = 0, j < N, j++, m[i][j] == 1)))"
    
title "testing A(..)||E(..)"

checktrue "(T && T)"
checktrue "(T && 1)"
checktrue "(!(F) && T)"
checktrue "(F || T)"
checktrue "(F || 1)"
checktrue "(T || 1)"
checktrue "(T && T && T && (!(F)) && 1)"
checktrue "(T && T && T && T && T && (T || F))"

checkfalse "(F && T)"
checkfalse "(T && F)"
checkfalse "(T && 0)"
checkfalse "(!(F) && F)"
checkfalse "(F ? T : 0 )"
checkfalse "(F && F)"
checkfalse "(F || F)"
checkfalse "(T && T && T && F && 1)"
checkfalse "(T && T && T && F)"











