Skip to content
Snippets Groups Projects
Commit 70646580 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

exact subtree matching test

parent 6a3caa0b
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,7 @@ debug: all-debug ...@@ -84,6 +84,7 @@ debug: all-debug
./tests.aderivation.aintegral.sh debug ./tests.aderivation.aintegral.sh debug
./tests.astringology.sh debug ./tests.astringology.sh debug
./tests.anormalize.sh debug ./tests.anormalize.sh debug
./tests.aarbology.sh debug
   
release: all-release release: all-release
mkdir -p $(addsuffix -release, $(BINFOLDER)) mkdir -p $(addsuffix -release, $(BINFOLDER))
...@@ -100,6 +101,7 @@ release: all-release ...@@ -100,6 +101,7 @@ release: all-release
./tests.aderivation.aintegral.sh release ./tests.aderivation.aintegral.sh release
./tests.astringology.sh release ./tests.astringology.sh release
./tests.anormalize.sh release ./tests.anormalize.sh release
./tests.aarbology.sh release
   
clean : clean-debug clean-release clean : clean-debug clean-release
$(RM) -r bin-debug bin-release $(RM) -r bin-debug bin-release
......
#!/usr/bin/env bash
# $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="../examples2/tree"
RES_GOOD=0
RES_FAIL=0
RES_TIME=0
RES_SEGV=0
RES_UNKN=0
# ----------------------------
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
# ----------------------------
# $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 generatePattern {
./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 2>/dev/null
}
# $1 = Occs number of occurrences expected
# $2 = command to test
# $3 = subject
# $4 = pattern
function runTest2 {
OUT=`timeout $TESTCASE_TIMEOUT bash -c "SUBJECT_FILE=\"$3\"; PATTERN_FILE=\"$4\"; $2"`
OUT=`test $1 -eq $OUT`
RET=$?
if [ $RET == 0 ]; then # ok
return 0
fi
log "$2" $RET "$3" "$4" "$OUT"
if [ $RET == 124 ]; then # timeout
return 2
elif [ $RET -ge 124 ]; then #segv
return 3
else
return 1
fi
}
function registerResult {
case $1 in
0)
echo -n "."
((RES_GOOD++))
;;
1)
echo -n "x"
((RES_FAIL++))
;;
2)
echo -n "T"
((RES_TIME++))
;;
3)
echo -n "E"
((RES_SEGV++))
;;
*)
echo -n "?"
((RES_UNKN++))
;;
esac
}
function clearResults {
RES_GOOD=0
RES_FAIL=0
RES_TIME=0
RES_SEGV=0
RES_UNKN=0
}
function outputResults {
# summary
echo -ne "\n\t"
echo "RES: GOOD:" $RES_GOOD ", FAIL:" $RES_FAIL ", TIME:" $RES_TIME ", SEGV:" $RES_SEGV, "UNKN:" $RES_UNKN
echo ""
}
# $1 - aconversions2 sequence
function runTest {
echo $1
echo -ne "\t"
clearResults
# 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 ]; then
Occs=`./aarbology2 -a exactSubtreeMatch -s "$SUBJECT_FILE" -p "$PATTERN_FILE" | ./astat2 -p quantity -s`
runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
registerResult $?
fi
done
echo -n " | "
# random tests
SUBJECT_FILE=s.xml
PATTERN_FILE=p.xml
for i in $(seq 1 $TESTCASE_ITERATIONS );
do
cat <(generateSubject) > $SUBJECT_FILE
cat <(generatePattern) > $PATTERN_FILE
Occs=`./aarbology2 -a exactSubtreeMatch -s "$SUBJECT_FILE" -p "$PATTERN_FILE" | ./astat2 -p quantity -s`
runTest2 "$Occs" "$2" "$SUBJECT_FILE" "$PATTERN_FILE"
registerResult $?
done
rm $SUBJECT_FILE
rm $PATTERN_FILE
outputResults
}
runTest "Exact Subtree Automaton" "./arun2 -t occurrences -a <(./aarbology2 -a exactSubtreeMatchingAutomaton -p \"\$PATTERN_FILE\" | ./adeterminize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p quantity -s"
...@@ -164,5 +164,5 @@ function runTest { ...@@ -164,5 +164,5 @@ function runTest {
} }
   
runTest "Exact Boyer Moore Horspool" "./astringology2 -a boyerMooreHorspool -s \"\$SUBJECT_FILE\" -p \"\$PATTERN_FILE\" | ./astat2 -p quantity -s" runTest "Exact Boyer Moore Horspool" "./astringology2 -a boyerMooreHorspool -s \"\$SUBJECT_FILE\" -p \"\$PATTERN_FILE\" | ./astat2 -p quantity -s"
runTest "Exact Pattern Matching Automaton" "./arun2 -t occurrences -a <(./astringology2 -a exactMatchingAutomaton -p \"\$PATTERN_FILE\" | ./adeterminize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p quantity -s" runTest "Exact Matching Automaton" "./arun2 -t occurrences -a <(./astringology2 -a exactMatchingAutomaton -p \"\$PATTERN_FILE\" | ./adeterminize2) -i \"\$SUBJECT_FILE\" | ./astat2 -p quantity -s"
   
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment