#! /bin/csh
#
# shell script for testing one student's program 3
# BST-related and WordCloudGenerator classes
#

# location of files provided to the students (that they don't change)
set providedFiles = /p/course/cs367-hasti/public/html/assignments/p3/files

# location of test files
set testFiles = /p/course/cs367-hasti/public/html/assignments/p3/grading/testFiles

# location of solution files
set solnFiles = /p/course/cs367-hasti/public/html/assignments/p3/solution

if ($#argv == 0) then
        echo Usage: $0 directory
        exit 1
endif

if (-e $1) else
  echo "$1" does not exist
  exit
endif

# copy student's files into JAVA subdirectory
cd $argv[1]
mkdir JAVA

cp $providedFiles/BSTnode.java JAVA/
cp $providedFiles/DictionaryADT.java JAVA/
cp $providedFiles/DuplicateException.java JAVA/
cp $providedFiles/Prioritizable.java JAVA/
cp $providedFiles/PriorityQueueADT.java JAVA/

# copy KeyWord and ArrayHeap solutions for testing
cp $solnFiles/KeyWord.java JAVA/
cp $solnFiles/ArrayHeap.java JAVA/

if (-e *2014*BSTDictionary.java) then
	cp *2014*BSTDictionary.java JAVA/BSTDictionary.java
	if (-e *2014*BSTDictionaryIterator.java) then
		cp *2014*BSTDictionaryIterator.java JAVA/BSTDictionaryIterator.java
		if (-e *2014*WordCloudGenerator.java) then
			cp *2014*WordCloudGenerator.java JAVA/WordCloudGenerator.java
		else
			echo "WordCloudGenerator.java missing or misnamed"
			exit
		endif
	else
		echo "BSTDictionaryIterator.java missing or misnamed"
		exit
	endif
else
	echo "BSTDictionary.java missing or misnamed"
	exit
endif

# copy test files
cp $testFiles/DictionaryTester.java JAVA/
cp $testFiles/*.txt JAVA/
cp $testFiles/*.html JAVA/

# compile all code
cd JAVA/
javac *.java

# test the student's BSTDictionary
echo "--- test BSTDictionary ---"
java DictionaryTester

# test the student's WordCloudGenerator
echo "--- test WordCloudGenerator ---"
echo "- test test1.txt"
java WordCloudGenerator test1.txt out.html emptyIgnore.txt 100
diff out.html test1out100.html
rm -f out.html

echo "- test test2.txt"
java WordCloudGenerator test2.txt out.html emptyIgnore.txt 20
diff out.html test2out20.html
rm -f out.html

java WordCloudGenerator test2.txt out.html emptyIgnore.txt 22
echo "this diff should show at most 2 lines different:"
diff out.html test2out22.html
rm -f out.html

echo "- test mrEdLyrics.txt"
java WordCloudGenerator mrEdLyrics.txt out.html ignore.txt 50
diff out.html mrEdLyrics50.html
rm -f out.html

java WordCloudGenerator mrEdLyrics.txt out.html emptyIgnore.txt 80
diff out.html mrEdLyrics80x.html
rm -f out.html

echo "- test neurons.txt"
java WordCloudGenerator neurons.txt out.html ignore.txt 6 
diff out.html neurons6.html
rm -f out.html

java WordCloudGenerator neurons.txt out.html emptyIgnore.txt 350 
diff out.html neurons350x.html
rm -f out.html

echo "- test recursion.txt"
java WordCloudGenerator recursion.txt out.html ignore.txt 8 
diff out.html recursion8.html
rm -f out.html

java WordCloudGenerator recursion.txt out.html ignore.txt 500 
diff out.html recursion500.html
rm -f out.html

# wrap up
echo "--- check BSTDictionary.java for efficiency ---"
echo "--- check BSTDictionaryIterator.java for efficiency ---"

rm -f *.class
