Skip to content

Commit

Permalink
Committer: Tamio Vesa Nakajima <[email protected]>
Browse files Browse the repository at this point in the history
Added a compare script

 Changes to be committed:
	modified:   examples/aplusb/buildtests
	new file:   examples/aplusb/compare
	modified:   examples/aplusb/incf/fixed
	new file:   examples/aplusb/incf/fixed2
	modified:   examples/aplusb/ingen/ingen.bin
	modified:   examples/aplusb/ingen/ingen.cpp
	modified:   examples/aplusb/lib
	new file:   examples/aplusb/oldtests/newtests.zip
	new file:   examples/aplusb/oldtests/newtests2.zip
	new file:   examples/aplusb/src/almost_ok.cpp
	new file:   examples/aplusb/stage/aplusb.bin
	new file:   examples/aplusb/stage/aplusb.in
	new file:   examples/aplusb/stage/aplusb.out
	modified:   examples/aplusb/testmanifest
	modified:   examples/aplusb/tests/aplusb-1.in
	modified:   examples/aplusb/tests/aplusb-1.ok
	modified:   examples/aplusb/tests/aplusb-10.in
	modified:   examples/aplusb/tests/aplusb-10.ok
	modified:   examples/aplusb/tests/aplusb-11.in
	modified:   examples/aplusb/tests/aplusb-11.ok
	modified:   examples/aplusb/tests/aplusb-12.in
	modified:   examples/aplusb/tests/aplusb-12.ok
	modified:   examples/aplusb/tests/aplusb-13.in
	modified:   examples/aplusb/tests/aplusb-13.ok
	modified:   examples/aplusb/tests/aplusb-14.in
	modified:   examples/aplusb/tests/aplusb-14.ok
	modified:   examples/aplusb/tests/aplusb-15.in
	modified:   examples/aplusb/tests/aplusb-15.ok
	modified:   examples/aplusb/tests/aplusb-16.in
	modified:   examples/aplusb/tests/aplusb-16.ok
	modified:   examples/aplusb/tests/aplusb-17.in
	modified:   examples/aplusb/tests/aplusb-17.ok
	modified:   examples/aplusb/tests/aplusb-18.in
	modified:   examples/aplusb/tests/aplusb-18.ok
	new file:   examples/aplusb/tests/aplusb-19.in
	new file:   examples/aplusb/tests/aplusb-19.ok
	modified:   examples/aplusb/tests/aplusb-2.in
	modified:   examples/aplusb/tests/aplusb-2.ok
	modified:   examples/aplusb/tests/aplusb-3.in
	modified:   examples/aplusb/tests/aplusb-3.ok
	modified:   examples/aplusb/tests/aplusb-4.in
	modified:   examples/aplusb/tests/aplusb-4.ok
	modified:   examples/aplusb/tests/aplusb-5.in
	modified:   examples/aplusb/tests/aplusb-5.ok
	modified:   examples/aplusb/tests/aplusb-6.in
	modified:   examples/aplusb/tests/aplusb-6.ok
	modified:   examples/aplusb/tests/aplusb-7.in
	modified:   examples/aplusb/tests/aplusb-7.ok
	modified:   examples/aplusb/tests/aplusb-8.in
	modified:   examples/aplusb/tests/aplusb-8.ok
	modified:   examples/aplusb/tests/aplusb-9.in
	modified:   examples/aplusb/tests/aplusb-9.ok
	modified:   src/buildtests
	new file:   src/compare
	modified:   src/lib
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 21, 2018
1 parent 512150d commit 27ea592
Show file tree
Hide file tree
Showing 55 changed files with 287 additions and 66 deletions.
13 changes: 1 addition & 12 deletions examples/aplusb/buildtests
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,7 @@ cat testmanifest | while read instr; do
#################

if [ $rebuild_inputs = true ] ; then
# Build input generator
cd ingen && make -s && cd ..

# Copy ingen/ingen.bin and incf/$1 into stage
cp ingen/ingen.bin stage/$problemname.bin
cp incf/$incf stage/$problemname.cf

# Build input
cd stage && ./$problemname.bin && cp $problemname.in ../tests/$problemname-$nr.in && cd ..

# Clean stage
rm stage/*
build_test_number $nr $incf
fi

###################
Expand Down
90 changes: 90 additions & 0 deletions examples/aplusb/compare
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/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
# Tamio-Vesa Nakajima

source lib
source problemconfig

srcs=""
configs=""

while getopts "hs:c:" opt ; do
case $opt in
h)
echo "Usage: ./compare -s \"source1\" -s \"source2\" -c \"config1\" \"config2\""
exit 0
;;
s)
srcs="$srcs $OPTARG"
;;
c)
configs="$configs $OPTARG"
;;
esac
done

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

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

srcs_arr=($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`
done

for i in `seq 0 $(($nr_srcs-1))` ; 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

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))

build_test_number 999 $conf

hasTle=false

for i in `seq 0 $(($nr_srcs-1))` ; do
run_src_test ${binary_arr[$i]} $problemname-999

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

cp stage/$problemname.out ${outputs_arr[$i]}
done
if [ $hasTle = true ] || ! diff --from-file ${outputs_arr[*]} > /dev/null ; then
echo -en " \r"
echo Has failed on:
cat tests/$problemname-999.in
echo With outputs:
for i in `seq 0 $(($nr_srcs-1))` ; do
echo ${srcs_arr[$i]}:
cat ${outputs_arr[$i]}
echo
done
exit 0
fi
done
done
2 changes: 1 addition & 1 deletion examples/aplusb/incf/fixed
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1 0 2
1 0 0
1 change: 1 addition & 0 deletions examples/aplusb/incf/fixed2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 100 200
Binary file modified examples/aplusb/ingen/ingen.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions examples/aplusb/ingen/ingen.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;

int main(){
Expand All @@ -8,12 +9,12 @@ int main(){
bool fixed;
int x, y;
f >> fixed >> x >> y;
cout << fixed << ' ' << x << ' ' << y << endl;

if(fixed){
g << x << ' ' << y << endl;
}
else{
srand(time(nullptr));
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
srand(seed1);
g << rand() << ' ' << rand() << endl; }
return 0; }
24 changes: 23 additions & 1 deletion examples/aplusb/lib
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ maybecp () {
fi
}

# Builds test number $1 with incf $2
build_test_number () {
source problemconfig

nr=$1
incf=$2

# Build input generator
cd ingen && make -s && cd ..

# Copy ingen/ingen.bin and incf/$1 into stage
cp ingen/ingen.bin stage/$problemname.bin
cp incf/$incf stage/$problemname.cf

# Build input
cd stage && ./$problemname.bin && cp $problemname.in ../tests/$problemname-$nr.in && cd ..

# Clean stage
rm stage/* 2> /dev/null

}

# Run the binary $1 with test $2, returning the time used in timeUsed, and leaving the output file in stage/$problemname.out
run_src_test () {
binary=$1
Expand All @@ -45,7 +67,7 @@ run_src_test () {
echo -en "Doing $testname\r"

# Clean the stage
rm stage/*
rm stage/* 2> /dev/null

# Copy the binary into the stage
cp $binary stage/$problemname.bin
Expand Down
Binary file added examples/aplusb/oldtests/newtests.zip
Binary file not shown.
Binary file added examples/aplusb/oldtests/newtests2.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/aplusb/src/almost_ok.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <fstream>
using namespace std;

int main(){
ifstream f("aplusb.in");
ofstream g("aplusb.out");
long long x, y;
f >> x >> y;
if((x+y)%100 == 0) g << -1 << endl;
else g << x+y << endl;
return 0; }
Binary file added examples/aplusb/stage/aplusb.bin
Binary file not shown.
1 change: 1 addition & 0 deletions examples/aplusb/stage/aplusb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
468168176 122451424
1 change: 1 addition & 0 deletions examples/aplusb/stage/aplusb.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-1
1 change: 1 addition & 0 deletions examples/aplusb/testmanifest
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
1 fixed 10
1 fixed2 10
18 random 90
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-1.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
100 200
4 changes: 2 additions & 2 deletions examples/aplusb/tests/aplusb-1.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
10
300
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-10.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-10.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-11.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-11.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-12.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-12.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-13.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-13.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-14.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-14.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-15.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-15.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-16.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-16.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-17.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405884291 2082194543
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-17.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3488078834
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-18.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405901098 217186145
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-18.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
1623087243
1 change: 1 addition & 0 deletions examples/aplusb/tests/aplusb-19.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1405901098 217186145
2 changes: 2 additions & 0 deletions examples/aplusb/tests/aplusb-19.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
1623087243
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-2.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-2.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-3.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-3.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-4.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-4.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-5.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-5.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-6.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-6.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-7.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-7.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-8.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394068970 1070590020
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-8.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2464658990
3205586778
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-9.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1394085777 1353065269
1405867484 1799719294
2 changes: 1 addition & 1 deletion examples/aplusb/tests/aplusb-9.ok
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5
2747151046
3205586778
13 changes: 1 addition & 12 deletions src/buildtests
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,7 @@ cat testmanifest | while read instr; do
#################

if [ $rebuild_inputs = true ] ; then
# Build input generator
cd ingen && make -s && cd ..

# Copy ingen/ingen.bin and incf/$1 into stage
cp ingen/ingen.bin stage/$problemname.bin
cp incf/$incf stage/$problemname.cf

# Build input
cd stage && ./$problemname.bin && cp $problemname.in ../tests/$problemname-$nr.in && cd ..

# Clean stage
rm stage/*
build_test_number $nr $incf
fi

###################
Expand Down
Loading

0 comments on commit 27ea592

Please sign in to comment.