BINARY=calc.exe

all: tests

compile: ${BINARY}
${BINARY}: calc.c stack.o
	gcc -Wall -g stack.o -o $@ $<

stack.o: stack.c
	gcc -Wall -c stack.c

tests: \
test-no-arg test-one-arg test-simple-expressions test-invalid-token \
test-too-many-operand test-too-many-operator \
test-division-by-zero test-overflow test-underflow \
test-complex-expressions

test-no-arg: compile
	./${BINARY}

test-one-arg: compile
	./${BINARY} 1
	./${BINARY} 0.34142E+1

# All expressions yield 10.0
test-simple-expressions: compile
	./${BINARY} 0001.9 8.100000 +
	./${BINARY} 15 5. -
	./${BINARY} -2.5 -4 "*"
	./${BINARY} 20 2 /

test-invalid-token: compile
	./${BINARY} 1.2.3 || true
	./${BINARY} 123banana || true
	./${BINARY} 1.2E+1.0 || true

test-too-many-operator: compile
	./${BINARY} + || true
	./${BINARY} 1 + || true
	./${BINARY} 1 2 + + || true

test-too-many-operand: compile
	./${BINARY} 1 2 3 + || true
	./${BINARY} 1 2 + 3 || true
	./${BINARY} 1 2 3 - || true

test-division-by-zero: compile
	./${BINARY} 1 0 /

test-overflow: compile
	./${BINARY} 1.0E+208 1.0E+100 "*"
	./${BINARY} 1.0E+209 1.0E+100 "*"

test-underflow: compile
	# TODO $@

test-complex-expressions: compile
	# TODO $@	
