# -*- shell-script -*-
# 
# I.gam - test out the I.h macros
# 


header <<EOF
#include <stdio.h>

#define I_DEFAULT_HANDLER(e,f,l,p) printf("fail\n")

#include <I.h>
#include <Q.h>

int z = 0;
int o = 1;

#define MAX 5

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

float fv[MAX] = { 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[MAX][MAX] = { 
    { 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 }
};

int main() {
EOF

footer <<EOF
;
}
EOF


topic "I.h:"
title "basic tests"

checkempty "I(0 == 0)"
checkfail "I(0 == 1)"
checkempty "I(1)"
checkfail "I(0)"
   
title "testing with quantifiers (based on check_Q.c)"
	 
checkempty "I(A(int i = 0, i < MAX, i++, v[i] == i))"
checkfail "I(A(int i = 0, i < MAX, i++, v[i] > i))"

checkempty "I(E(int i = 0, i < MAX, i++, v[i] == 4))"
checkempty "I(E(int i = 0, i < MAX, i++, v[i] == 0))"
checkempty "I(E(int i = 0, i < MAX, i++, v[i] == 1))"

checkfail "I(E(int i = 0, i < MAX, i++, v[i] == 5))"
checkfail "I(E(int i = 0, i < MAX, i++, v[i] == -1))"
checkfail "I(E(int i = 0, i < MAX, i++, v[i] > i))"

checkempty "I(C(int i = 0, i < MAX, i++, 1) == MAX)"
checkempty "I(C(int i = 0, i < MAX, i++, v[i] == 0) == 1)"
checkempty "I(C(int i = 0, i < MAX, i++, v[i] == 4) == 1)"
checkempty "I(C(int i = 0, i < MAX, i++, v[i] == 5) == 0)"

checkempty "I(E1(int i = 0, i < MAX, i++, v[i] == 4))"
checkempty "I(E1(int i = 0, i < MAX, i++, v[i] == 0))"
checkempty "I(E1(int i = 0, i < MAX, i++, v[i] == 1))"

checkfail "I(E1(int i = 0, i < MAX, i++, v[i] > 4))"
checkfail "I(E1(int i = 0, i < MAX, i++, v[i] == -1))"
checkfail "I(E1(int i = 0, i < MAX, i++, v[i] == i))"

checkfail "I(S(int i = 0, i < MAX, i++, v[i]) == 9)"
checkempty "I(S(int i = 0, i < 0, i++, v[i]) == 0)"

checkempty "I(S(int i = 0, i < MAX, i++, fv[i]) == fvsum)"
checkfail "I(S(int i = 0, i < MAX, i++, fv[i])==0.0)"

checkempty "I(P(int i = 1, i < MAX, i++, v[i])==24)"
checkempty "I(P(int i = 1, i < 0, i++, v[i])==1)"

checkempty "I(P(int i = 0, i < MAX, i++, fv[i])==fvprod)"
checkfail "I(P(int i = 0, i < 0, i++, fv[i]) != 1.0)"

title "check out nesting of operations"
    
checkempty "I(A(int i = 0, i < MAX, i++,
		A(int j = 0, j < MAX, j++, 
		  m[i][j] == ((i == j) ? 1 : 0))))"

checkfail "I(A(int i = 0, i < MAX, i++,
		A(int j = 0, j < MAX, j++, 
		  m[i][j] == 0)))"

checkempty "I(A(int i = 0, i < MAX, i++,
		E(int j = 0, j < MAX, j++, 
		  m[i][j] == 1)))"

checkfail "I(E(int i = 0, i < MAX, i++,
		E(int j = 0, j < MAX, j++, 
		  m[i][j] == 2)))"

checkempty "I(A(int i = 0, i < MAX, i++,
		E1(int j = 0, j < MAX, j++, 
		  m[i][j] == 1)))"

checkfail "I(A(int i = 0, i < MAX, i++,
		E1(int j = 0, j < MAX, j++, 
		  m[i][j] == 2)))"

checkfail "I(A(int i = 0, i < MAX, i++,
		E1(int j = 0, j < MAX, j++, 
		  m[i][j] == 0)))"

checkfail "I(A(int i = 0, i < MAX, i++,
		E1(int j = 0, j < MAX, j++, 
		  m[i][j] == 4)))"

checkempty "I(S(int i = 0, i < MAX, i++,
	     S(int j = 0, j < MAX, j++, m[i][j])) == MAX)"

checkempty "I(P(int i = 0, i < MAX, i++,
	     S(int j = 0, j < MAX, j++, m[i][j])) == 1)"

checkempty "I(C(int i = 0, i < MAX, i++,
	     S(int j = 0, j < MAX, j++, m[i][j]) == 1) == MAX)"

checkempty "I(C(int i = 0, i < MAX, i++,
	     S(int j = 0, j < MAX, j++, m[i][j]) == 2) == 0)"

checkempty "I(A(int i = 0, i < MAX, i++,
	       C(int j = 0, j < MAX, j++, m[i][j] == 1)))"
    







