Skip to content

Commit

Permalink
Overhauled documentation & examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed Jun 5, 2018
1 parent 3a4204e commit 86f63fd
Show file tree
Hide file tree
Showing 91 changed files with 426 additions and 743 deletions.
115 changes: 70 additions & 45 deletions examples/aplusb/buildtests
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@
# This builds all tests using testmanifest
# Tamio-Vesa Nakajima

# include the library
source lib
#################################
# Build necesisties
#################################

# include the configuration
cd eval || exit
make -s
cd .. || exit

cd okgen || exit
make -s
cd .. || exit

cd ingen || exit
make -s
cd .. || exit

#################################
# PROBLEM CONFIGURATION
#################################

# initialize problemconfig variables
problemname=""
timelimit=""

# shellcheck disable=SC1091
source problemconfig

# Check if problemconfig variables are set
if [ -z "$problemname" ] || [ -z "$timelimit" ] ; then
echo Bad config file
exit 1
fi

############################
# ARGUMENT PARSING
#############################
Expand All @@ -17,73 +44,71 @@ rebuild_inputs=true

while getopts "r:ho" opt; do
case $opt in
h)
echo "Usage: ./run -r(estore) [revision to restore]"
h) # Help:
echo "Usage: ./run [-r REVISION] [-o]"
echo " -r REVISION -- restores REVISION"
echo " -o -- rebuilds only the .ok files"
exit 0
;;
r)
r) # Restore old revision
rm -r tests
unzip oldtests/$OPTARG.zip
unzip "oldtests/$OPTARG.zip"
exit 0
;;
o)
o) # DO only the ok's again
rebuild_inputs=false
;;
*)
echo "Bad options"
exit 1
;;
esac
done

read -p "Name of this test revision: " testrevision

# We will want to remember this:
currtest=0
############################
# Building tests
############################

# Loop over lines of
cat testmanifest | while read instr; do
# Get test revision name
read -p "Name of this test revision: " -r testrevision

# For all lines of the test manifest:
currtest=0
while read -r instr; do
# Parse a line of testmanifest

# shellcheck disable=SC2086
set $instr
numberoftests=$1
incf=$2
totalpoints=$3
points=$(($totalpoints / $numberoftests))

for nr in `seq $currtest $(($currtest + $numberoftests - 1))` ; do
echo $nr
#################
# Build input:
#################
# Get the number of points per test
points=$((totalpoints / numberoftests))

# For all tests of this kind:
for ((nr=$"currtest"; nr<"$currtest"+"$numberoftests" ; nr++)) ; do
(
echo Building test "$nr"

if [ $rebuild_inputs = true ] ; then
build_test_number $nr $incf
./lib/build_test_number "$nr" "$incf"
fi

###################
# Build ok
###################

# Build ok generator
cd okgen && make -s && cd ..

# Copy ok generator and input into stage
cp okgen/okgen.bin stage/$problemname.bin
cp tests/$problemname-$nr.in stage/$problemname.in
./lib/build_ok_number "$nr" "$points"

# Indicate the number of points in the stage
echo $points > stage/$problemname.points

# Build ok
cd stage && ./$problemname.bin && cd ..

# Copy ok from stage into tests
cp stage/$problemname.ok tests/$problemname-$nr.ok

# Clean stage
rm stage/*
echo Done test "$nr"
) &
done

#update currtest
currtest=$(($currtest + $numberoftests))
done
currtest=$((currtest + numberoftests))
done < testmanifest

wait

if [ -n $testrevision ] ; then
zip -r oldtests/$testrevision.zip tests/*
# Store this revision in oldtests
if [ -n "$testrevision" ] ; then
zip -r "oldtests/$testrevision.zip" tests/*
fi
72 changes: 43 additions & 29 deletions examples/aplusb/compare
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#!/bin/bash
#
# compare -s "s1 s2" -s s3 -c "c1 c2" -c c3 compares sources s1, s2, s3 with configurations c1 c2 c3 until they diverge
# compares sources
# Tamio-Vesa Nakajima

source lib
problemname=""
timelimit=""

# shellcheck disable=SC1091
source problemconfig

if [ -z "$problemname" ] || [ -z "$timelimit" ] ; then
echo Bad config file
exit 1
fi

srcs=""
configs=""

while getopts "hs:c:" opt ; do
case $opt in
h)
echo "Usage: ./compare -s \"source1\" -s \"source2\" -c \"config1\" \"config2\""
echo "Usage: ./compare -s SRC1 ... -s SRCn -c CONF1 ... -c CONFm"
echo " -s SRC1 ... -s SRCn -- compares SRC1 to ... to SRCn"
echo " -c CONF1 ... -s CONm -- using config files CONF1 ... CONFm"
exit 0
;;
s)
Expand All @@ -21,68 +31,72 @@ while getopts "hs:c:" opt ; do
c)
configs="$configs $OPTARG"
;;
*)
echo Bad options
exit 1
;;
esac
done

if [ -z "$srcs" ] ; then
echo No sources provided
echo No sources provided >&2
exit 1
fi

if [ -z "$configs" ] ; then
echo No configs provided
echo No configs provided >&2
exit 1
fi

srcs_arr=($srcs)
# shellcheck disable=SC2086
srcs_arr=()
read -a srcs_arr -r <<< "$srcs"
nr_srcs=${#srcs_arr[@]}
outputs_arr=()
binary_arr=()
input_file=`mktemp`

for i in `seq 0 $(($nr_srcs-1))` ; do
outputs_arr[$i]=`mktemp`
binary_arr[$i]=`mktemp`
for ((i=0; i<nr_srcs; i++)) ; do
outputs_arr[$i]=$(mktemp)
binary_arr[$i]=$(mktemp)
done

for i in `seq 0 $(($nr_srcs-1))` ; do
g++ src/${srcs_arr[$i]} -std=c++11 -O2 -o ${binary_arr[$i]}
for ((i=0; i<nr_srcs; i++)) ; do
g++ "src/${srcs_arr[$i]}" -std=c++11 -O2 -o "${binary_arr[$i]}"
done

curr_test=0

path_to_tests=`realpath tests`
trap "rm $path_to_tests/$problemname-999.in" EXIT
path_to_tests=$(realpath tests)
trap 'rm $path_to_tests/$problemname-999.in' EXIT

while : ; do
for conf in $configs ; do
rm stage/* 2> /dev/null
echo -en " \r"
echo Doing test $curr_test
curr_test=$(($curr_test + 1))
echo -en " \\r" >&2
echo Doing test $curr_test >&2
curr_test=$((curr_test + 1))

build_test_number 999 $conf
./lib/build_test_number 999 "$conf"

hasTle=false

for i in `seq 0 $(($nr_srcs-1))` ; do
run_src_test ${binary_arr[$i]} $problemname-999
for((i=0; i<nr_srcs; i++)) ; do
timeUsed=$(./lib/run_src_test "${outputs_arr[$i]}" "${binary_arr[$i]}" "$problemname-999")

if (( $(echo "$timeUsed > $timelimit" | bc -l ) )) ; then
hasTle=true
fi

cp stage/$problemname.out ${outputs_arr[$i]}
done

# shellcheck disable=SC2086
if [ $hasTle = true ] || ! diff --from-file ${outputs_arr[*]} > /dev/null ; then
echo -en " \r"
echo Has failed on:
echo -en " \\r" >&2
echo Has failed on: >&2
cat tests/$problemname-999.in
echo With outputs:
for i in `seq 0 $(($nr_srcs-1))` ; do
echo ${srcs_arr[$i]}:
echo With outputs: >&2
for((i=0 ; i<nr_srcs; i++)) ; do
echo ${srcs_arr[$i]}: >&2
cat ${outputs_arr[$i]}
echo
echo >&2
done
exit 0
fi
Expand Down
Binary file removed examples/aplusb/eval/eval.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/aplusb/incf/fixed
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1 0 0
1 0 1
1 change: 0 additions & 1 deletion examples/aplusb/incf/fixed2

This file was deleted.

File renamed without changes.
Binary file removed examples/aplusb/ingen/ingen.bin
Binary file not shown.
5 changes: 1 addition & 4 deletions examples/aplusb/ingen/ingen.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;

int main(){
Expand All @@ -10,9 +9,7 @@ int main(){
int x, y;
f >> fixed >> x >> y;

if(fixed){
g << x << ' ' << y << endl;
}
if(fixed) g << x << ' ' << y << endl;
else{
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
srand(seed1);
Expand Down
Loading

0 comments on commit 86f63fd

Please sign in to comment.