#!/usr/bin/env bash

source bash_multithread.sh

# $1 test dir suffix (debug / release)

# SETTINGS
TESTCASE_ITERATIONS=100
TESTCASE_TIMEOUT=10
LOGFILE="log_tests.txt"

RAND_SIZE_SUBJECT=1000
RAND_SIZE_PATTERN=4
RAND_HEIGHT_SUBJECT=25
RAND_HEIGHT_PATTERN=2
RAND_ALPHABET=2

EXECUTABLES="arand2 atrim2 adeterminize2 anormalize2 "
TESTS_DIR="`pwd`/examples2/tree"

RES_GOOD=
RES_FAIL=
RES_TIME=
RES_SEGV=
RES_UNKN=
MATCHES=


# ----------------------------

for FILE in $EXECUTABLES; do
	if [ ! -f bin-$1/$FILE ]; then
		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
		exit 1
	fi
done

cd bin-$1/
rm -f $LOGFILE

JOBS=$2
if [ -z "$JOBS" ]; then
	JOBS=1
fi

# ----------------------------

# $1 = conv command
# $2 = return code
# $3 = input automaton
# $4 = output of conversion
function log {
	echo "----------------------------------------------------------" >> $LOGFILE
	echo "conv: " $1 >> $LOGFILE
	echo "ret: " $2 >> $LOGFILE
	echo "subject:" >> $LOGFILE
	cat  "$3" >> $LOGFILE
	echo "pattern:" >> $LOGFILE
	cat  "$4" >> $LOGFILE
	echo "command out:" >> $LOGFILE
	echo "$5" >> $LOGFILE
}

function generateNonlinearPatternSingle {
	./arand2 -t RNP --nodes $RAND_SIZE_PATTERN --terminals $(( $RANDOM % $RAND_ALPHABET + 1 )) --height $RAND_HEIGHT_PATTERN --single_nonlinear_variable 2>/dev/null
}

function generateNonlinearPattern {
	./arand2 -t RNP --nodes $RAND_SIZE_PATTERN --terminals $(( $RANDOM % $RAND_ALPHABET + 1 )) --height $RAND_HEIGHT_PATTERN 2>/dev/null
}

function generatePattern {
	./arand2 -t RP --nodes $RAND_SIZE_PATTERN --terminals $(( $RANDOM % $RAND_ALPHABET + 1 )) --height $RAND_HEIGHT_PATTERN 2>/dev/null
}

function generateSubtree {
	./arand2 -t RT --nodes $RAND_SIZE_PATTERN --terminals $(( $RANDOM % $RAND_ALPHABET + 1 )) --height $RAND_HEIGHT_PATTERN 2>/dev/null
}

function generateSubject {
	./arand2 -t RT --nodes $RAND_SIZE_SUBJECT --terminals $(( $RANDOM % $RAND_ALPHABET + 1 )) --height $RAND_HEIGHT_SUBJECT --rank 2 2>/dev/null
}

# $1 = command to compute expected number of occurrences
# $2 = command to test
# $3 = subject
# $4 = pattern
function runTest2 {
	OUT1=`bash -c "SUBJECT_FILE=\"$3\"; PATTERN_FILE=\"$4\"; $1"`
	OUT2=`timeout $TESTCASE_TIMEOUT bash -c "SUBJECT_FILE=\"$3\"; PATTERN_FILE=\"$4\"; $2"`
	RET=$?
	if [ $RET == 0 ]; then # ok
		OUT=`test $OUT1 -eq $OUT2`
	fi
	RET2=$?

	if [ $RET != 0 ] || [ $RET2 != 0 ]; then # fail
		log "$2" $RET "$3" "$4" "$OUT1:$OUT2:$OUT"
	fi

	rm $3
	rm $4

	if [ $RET == 124 ]; then # timeout
		registerResult 2
		return 2
	elif [ $RET -ge 124 ]; then #segv
		registerResult 3
		return 3
	elif [ $RET != 0 ] || [ $RET2 != 0 ]; then # fail
		registerResult 1
		return 1
	else
		echo -n "+$OUT2" >> $MATCHES
		registerResult 0
		return 0
	fi
}

function registerResult {
	case $1 in
		0)
			echo -n "."
			echo -n "+1" >> $RES_GOOD
			;;
		1)
			echo -n "x"
			echo -n "+1" >> $RES_FAIL
			;;
		2)
			echo -n "T"
			echo -n "+1" >> $RES_TIME
			;;
		3)
			echo -n "E"
			echo -n "+1" >> $RES_SEGV
			;;
		*)
			echo -n "?"
			echo -n "+1" >> $RES_UNKN
			;;
	esac
}

function initResults {
	RES_GOOD=$(mktemp)
	echo -n "0" > $RES_GOOD
	RES_FAIL=$(mktemp)
	echo -n "0" > $RES_FAIL
	RES_TIME=$(mktemp)
	echo -n "0" > $RES_TIME
	RES_SEGV=$(mktemp)
	echo -n "0" > $RES_SEGV
	RES_UNKN=$(mktemp)
	echo -n "0" > $RES_UNKN
	MATCHES=$(mktemp)
	echo -n "0" > $MATCHES
}

function clearResults {
	rm $RES_GOOD
	rm $RES_FAIL
	rm $RES_TIME
	rm $RES_SEGV
	rm $RES_UNKN
	rm $MATCHES
}

function outputResults {
	echo "" >> $RES_GOOD
	echo "" >> $RES_FAIL
	echo "" >> $RES_TIME
	echo "" >> $RES_SEGV
	echo "" >> $RES_UNKN
	echo "" >> $MATCHES

	# summary
	echo -ne "\n\t"
	echo "RES: GOOD:" $(bc < $RES_GOOD) ", FAIL:" $(bc < $RES_FAIL) ", TIME:" $(bc < $RES_TIME) ", SEGV:" $(bc < $RES_SEGV), "UNKN:" $(bc < $RES_UNKN), "MATCHES:" $(bc < $MATCHES)
	echo ""
}

# $1 - aconversions2 sequence
function runTestSubtree {
	echo $1
	echo -ne "\t"

	initResults
	bgxgrp=""

	Occs="./aarbology2 -a exactSubtreeMatch -s \"\$SUBJECT_FILE\" -p \"\$PATTERN_FILE\" | ./astat2 -p size"

	# predefined tests first
	for SUBJECT_FILE in `ls $TESTS_DIR/aarbology.test*.subject.xml`; do
		PATTERN_FILE=${SUBJECT_FILE%.subject.xml}.subtree.xml
		if [ -f $PATTERN_FILE ]; then
			SUBJECT_FILE_COPY=$(mktemp)
			PATTERN_FILE_COPY=$(mktemp)

			cat $SUBJECT_FILE > $SUBJECT_FILE_COPY
			cat $PATTERN_FILE > $PATTERN_FILE_COPY

			bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE_COPY" "$PATTERN_FILE_COPY"
		fi
	done

	bgxwait

	echo -n " | "

	# random tests
	for i in $(seq 1 $TESTCASE_ITERATIONS );
	do
		SUBJECT_FILE=$(mktemp)
		PATTERN_FILE=$(mktemp)

		cat <(generateSubject) > $SUBJECT_FILE
		cat <(generateSubtree) > $PATTERN_FILE

		bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
	done

	bgxwait

	outputResults
	clearResults
}

# $1 - aconversions2 sequence
function runTestPattern {
	echo $1
	echo -ne "\t"

	initResults
	bgxgrp=""

	Occs="./aarbology2 -a exactPatternMatch -s \"\$SUBJECT_FILE\" -p \"\$PATTERN_FILE\" | ./astat2 -p size"

	# predefined tests first
	for SUBJECT_FILE in `ls $TESTS_DIR/aarbology.test*.subject.xml`; do
		PATTERN_FILE=${SUBJECT_FILE%.subject.xml}.pattern.xml
		if [ -f $PATTERN_FILE ]; then
			SUBJECT_FILE_COPY=$(mktemp)
			PATTERN_FILE_COPY=$(mktemp)

			cat $SUBJECT_FILE > $SUBJECT_FILE_COPY
			cat $PATTERN_FILE > $PATTERN_FILE_COPY

			bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE_COPY" "$PATTERN_FILE_COPY"
		fi
	done

	bgxwait

	echo -n " | "

	# random tests
	for i in $(seq 1 $TESTCASE_ITERATIONS );
	do
		SUBJECT_FILE=$(mktemp)
		PATTERN_FILE=$(mktemp)

		cat <(generateSubject) > $SUBJECT_FILE
		cat <(generatePattern) > $PATTERN_FILE

		bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
	done

	bgxwait

	outputResults
	clearResults
}

# $1 - aconversions2 sequence
function runTestNonlinearPattern {
	echo $1
	echo -ne "\t"

	initResults
	bgxgrp=""

	Occs="./aarbology2 -a exactPatternMatch -s \"\$SUBJECT_FILE\" -p \"\$PATTERN_FILE\" | ./astat2 -p size"

	# predefined tests first
	for SUBJECT_FILE in `ls $TESTS_DIR/aarbology.test*.subject.xml`; do
		PATTERN_FILE=${SUBJECT_FILE%.subject.xml}.nonlinear.pattern.xml
		if [ -f $PATTERN_FILE ]; then
			SUBJECT_FILE_COPY=$(mktemp)
			PATTERN_FILE_COPY=$(mktemp)

			cat $SUBJECT_FILE > $SUBJECT_FILE_COPY
			cat $PATTERN_FILE > $PATTERN_FILE_COPY

			bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE_COPY" "$PATTERN_FILE_COPY"
		fi
	done

	bgxwait

	echo -n " | "

	# random tests
	for i in $(seq 1 $TESTCASE_ITERATIONS );
	do
		SUBJECT_FILE=$(mktemp)
		PATTERN_FILE=$(mktemp)

		cat <(generateSubject) > $SUBJECT_FILE
		cat <(generateNonlinearPattern) > $PATTERN_FILE

		bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
	done

	bgxwait

	outputResults
	clearResults
}

# $1 - aconversions2 sequence
function runTestPatternEnds {
	echo $1
	echo -ne "\t"

	initResults
	bgxgrp=""

	Occs="./aarbology2 -e -a exactPatternMatch -s <(./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <(./acast2 -t PrefixRankedPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

	# predefined tests first
	for SUBJECT_FILE in `ls $TESTS_DIR/aarbology.test*.subject.xml`; do
		PATTERN_FILE=${SUBJECT_FILE%.subject.xml}.pattern.xml
		if [ -f $PATTERN_FILE ]; then
			SUBJECT_FILE_COPY=$(mktemp)
			PATTERN_FILE_COPY=$(mktemp)

			cat $SUBJECT_FILE > $SUBJECT_FILE_COPY
			cat $PATTERN_FILE > $PATTERN_FILE_COPY

			bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE_COPY" "$PATTERN_FILE_COPY"
		fi
	done

	bgxwait

	echo -n " | "

	# random tests
	for i in $(seq 1 $TESTCASE_ITERATIONS );
	do
		SUBJECT_FILE=$(mktemp)
		PATTERN_FILE=$(mktemp)

		cat <(generateSubject) > $SUBJECT_FILE
		cat <(generatePattern) > $PATTERN_FILE

		bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
	done

	bgxwait

	outputResults
	clearResults
}

# $1 - aconversions2 sequence
function runTestNonlinearPatternEnds {
	echo $1
	echo -ne "\t"

	initResults
	bgxgrp=""

	Occs="./aarbology2 -e -a exactPatternMatch -s <(./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <(./acast2 -t PrefixRankedNonlinearPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

	# predefined tests first
	for SUBJECT_FILE in `ls $TESTS_DIR/aarbology.test*.subject.xml`; do
		PATTERN_FILE=${SUBJECT_FILE%.subject.xml}.nonlinear.pattern.xml
		if [ -f $PATTERN_FILE ]; then
			SUBJECT_FILE_COPY=$(mktemp)
			PATTERN_FILE_COPY=$(mktemp)

			cat $SUBJECT_FILE > $SUBJECT_FILE_COPY
			cat $PATTERN_FILE > $PATTERN_FILE_COPY

			bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE_COPY" "$PATTERN_FILE_COPY"
		fi
	done

	bgxwait

	echo -n " | "

	# random tests
	for i in $(seq 1 $TESTCASE_ITERATIONS );
	do
		SUBJECT_FILE=$(mktemp)
		PATTERN_FILE=$(mktemp)

		cat <(generateSubject) > $SUBJECT_FILE
		cat <(generateNonlinearPatternSingle) > $PATTERN_FILE

		bgxlimit ${JOBS} runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
	done

	bgxwait

	outputResults
	clearResults
}

runTestNonlinearPattern "Exact Nonlinear Pattern Matching Using Compressed Bit Vectors (PrefixRankedBar)" "./aarbology2 -a nonlinearCompressedBitParallelIndex -s <(./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q nonlinearCompressedBitParallelismPatterns -i - -p <( ./acast2 -t PrefixRankedBarNonlinearPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestNonlinearPattern "Exact Nonlinear Pattern Matching Using Full And Linear Index (PrefixRanked)" "./aarbology2 -a nonlinearFullAndLinearIndex -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q nonlinearFullAndLinearIndexPatterns -i - -p <( ./acast2 -t PrefixRankedNonlinearPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestNonlinearPattern "Exact Nonlinear Pattern Matching Using Full And Linear Index (PrefixRankedBar)" "./aarbology2 -a nonlinearFullAndLinearIndex -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q nonlinearFullAndLinearIndexPatterns -i - -p <( ./acast2 -t PrefixRankedBarNonlinearPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestPattern "Exact Pattern Matching Using Full And Linear Index (PrefixRankedBar)" "./aarbology2 -a fullAndLinearIndex -s <(./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q fullAndLinearIndexPatterns -i - -p <( ./acast2 -t PrefixRankedBarPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestPattern "Exact Pattern Matching Using Full And Linear Index (PrefixRanked)" "./aarbology2 -a fullAndLinearIndex -s <(./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q fullAndLinearIndexPatterns -i - -p <( ./acast2 -t PrefixRankedPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestPattern "Exact Pattern Matching Using Compressed Bit Vectors (PrefixRankedBar)" "./aarbology2 -a compressedBitParallelIndex -s <(./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q compressedBitParallelismPatterns -i - -p <( ./acast2 -t PrefixRankedBarPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestPatternEnds "Exact Pattern Matching Using Compressed Bit Vectors (PrefixRanked)" "./aarbology2 -a compressedBitParallelIndex -s <(./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) | ./aquery2 -q compressedBitParallelismPatterns -i - -p <( ./acast2 -t PrefixRankedPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"

runTestPatternEnds "Exact Pattern Matching Automaton (PrefixRanked)" "./aarbology2 -a exactPatternMatchingAutomaton -p <(./acast2 -t PrefixRankedPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <( ./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\" ) ) ) | ./adeterminize2 | ./arun2 -t occurrences -a - -i <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" | ./acast2 -t LinearString ) | ./astat2 -p size"

RAND_SIZE_SUBJECT=120
runTestPatternEnds "Exact Tree Pattern Automaton (PrefixRanked)" "./aarbology2 -a exactTreePatternAutomaton -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -w <( ./aaccess2 --tree subtree_wildcard -o get -i \"\$PATTERN_FILE\" ) | ./adeterminize2 | ./arun2 -t result -i <(./acast2 -t PrefixRankedPattern -i \"\$PATTERN_FILE\" | ./acast2 -t LinearString ) | ./astat2 -p size"
RAND_SIZE_SUBJECT=80
runTestNonlinearPatternEnds "Exact Nonlinear Tree Pattern Automaton (PrefixRanked)" "./aarbology2 -a exactNonlinearTreePatternAutomaton -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -w <( ./aaccess2 --tree subtree_wildcard -o get -i \"\$PATTERN_FILE\" ) -n <( ./aaccess2 --tree nonlinear_variables -o get -i \"\$PATTERN_FILE\" ) | ./adeterminize2 | ./arun2 -t result -i <(./acast2 -t PrefixRankedNonlinearPattern -i \"\$PATTERN_FILE\" | ./acast2 -t LinearString ) -f <(echo '<Set />') | ./aaccess2 --pairSet first -o get | ./astat2 -p size"


RAND_SIZE_SUBJECT=1000
runTestSubtree "Exact Boyer Moore Horspool (Subtree PrefixRankedBar)" "./aarbology2 -a boyerMooreHorspool -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarTree -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestSubtree "Exact Subtree Automaton (Tree)" "./arun2 -t occurrences -a <(./aarbology2 -a exactSubtreeMatchingAutomaton -p \"\$PATTERN_FILE\" | ./adeterminize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p size"
runTestSubtree "Exact Minimized Subtree Automaton (Tree)" "./arun2 -t occurrences -a <(./aarbology2 -a exactSubtreeMatchingAutomaton -p \"\$PATTERN_FILE\" | ./adeterminize2 | ./atrim2 -r -u | ./aminimize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p size"

runTestPattern "Exact Boyer Moore Horspool (Pattern PrefixRankedBar)" "./aarbology2 -a boyerMooreHorspool -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestNonlinearPattern "Exact Pattern Match (NonlinearPattern PrefixRankedBar)" "./aarbology2 -a exactPatternMatch -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarNonlinearPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestNonlinearPattern "Exact Boyer Moore Horspool (NonlinearPattern PrefixRankedBar)" "./aarbology2 -a boyerMooreHorspool -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarNonlinearPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestPattern "Exact Reversed Boyer Moore Horspool (Pattern PrefixRankedBar)" "./aarbology2 -a reversedBoyerMooreHorspool -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestPattern "Exact Reversed Boyer Moore Horspool (Pattern PrefixRanked)" "./aarbology2 -a reversedBoyerMooreHorspool -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestNonlinearPattern "Exact Reversed Boyer Moore Horspool (NonlinearPattern PrefixRankedBar)" "./aarbology2 -a reversedBoyerMooreHorspool -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarNonlinearPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestNonlinearPattern "Exact Reversed Boyer Moore Horspool (NonlinearPattern PrefixRanked)" "./aarbology2 -a reversedBoyerMooreHorspool -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedNonlinearPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestPattern "Exact Knuth Morris Pratt (Pattern PrefixRankedBar)" "./aarbology2 -a knuthMorrisPratt -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"
runTestPattern "Exact Knuth Morris Pratt (Pattern PrefixRanked)" "./aarbology2 -a knuthMorrisPratt -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedPattern -i \"\$PATTERN_FILE\" ) | ./astat2 -p size"
runTestPattern "Exact Dead Zone Using Bad Character Shift And Border Array (Pattern PrefixRanked)" "./aarbology2 -a deadZoneUsingBadCharacterShiftAndBorderArray -s <( ./acast2 -t PrefixRankedTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"
runTestPattern "Exact Dead Zone Using Bad Character Shift And Border Array (Pattern PrefixRankedBar)" "./aarbology2 -a deadZoneUsingBadCharacterShiftAndBorderArray -s <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" ) -p <( ./acast2 -t PrefixRankedBarPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\"))) | ./astat2 -p size"

runTestPattern "Exact Pattern Matching Automaton (Pattern Tree)" "./arun2 -t occurrences -a <(./aarbology2 -a exactPatternMatchingAutomaton -p <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <(./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\")) | ./adeterminize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p size"
runTestPattern "Exact Pattern Matching Automaton (PrefixRankedBar)" "./aarbology2 -a exactPatternMatchingAutomaton -p <(./acast2 -t PrefixRankedBarPattern -i <(./aaccess2 --tree alphabet -o add -i \"\$PATTERN_FILE\" -a <( ./aaccess2 --tree alphabet -o get -i \"\$SUBJECT_FILE\" ) ) ) | ./adeterminize2 | ./arun2 -t occurrences -a - -i <( ./acast2 -t PrefixRankedBarTree -i \"\$SUBJECT_FILE\" | ./acast2 -t LinearString ) | ./astat2 -p size"
