Skip to content

Commit

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

 Changes to be committed:
	modified:   README.md
	new file:   examples/aorib/buildtests.sh
	new file:   examples/aorib/eval/eval.bin
	new file:   examples/aorib/eval/eval.cpp
	new file:   examples/aorib/eval/makefile
	new file:   examples/aorib/incf/fixed
	new file:   examples/aorib/incf/makefile
	new file:   examples/aorib/incf/random
	new file:   examples/aorib/ingen/ingen.bin
	new file:   examples/aorib/ingen/ingen.cpp
	new file:   examples/aorib/ingen/makefile
	new file:   examples/aorib/lib.sh
	new file:   examples/aorib/okgen/makefile
	new file:   examples/aorib/okgen/okgen.bin
	new file:   examples/aorib/okgen/okgen.cpp
	new file:   examples/aorib/problemconfig.sh
	new file:   examples/aorib/run.sh
	new file:   examples/aorib/src/makefile
	new file:   examples/aorib/src/ok.cpp
	renamed:    src/tle.cpp -> examples/aorib/src/tle.cpp
	renamed:    src/wa.cpp -> examples/aorib/src/wa.cpp
	new file:   examples/aorib/stage/aorib.bin
	new file:   examples/aorib/stage/aorib.in
	new file:   examples/aorib/testmanifest
	new file:   examples/aorib/tests/aorib-0.in
	new file:   examples/aorib/tests/aorib-0.ok
	new file:   examples/aorib/tests/aorib-1.in
	new file:   examples/aorib/tests/aorib-1.ok
	new file:   examples/aorib/tests/aorib-10.in
	new file:   examples/aorib/tests/aorib-10.ok
	new file:   examples/aorib/tests/aorib-11.in
	new file:   examples/aorib/tests/aorib-11.ok
	new file:   examples/aorib/tests/aorib-12.in
	new file:   examples/aorib/tests/aorib-12.ok
	new file:   examples/aorib/tests/aorib-13.in
	new file:   examples/aorib/tests/aorib-13.ok
	new file:   examples/aorib/tests/aorib-14.in
	new file:   examples/aorib/tests/aorib-14.ok
	new file:   examples/aorib/tests/aorib-15.in
	new file:   examples/aorib/tests/aorib-15.ok
	new file:   examples/aorib/tests/aorib-16.in
	new file:   examples/aorib/tests/aorib-16.ok
	new file:   examples/aorib/tests/aorib-17.in
	new file:   examples/aorib/tests/aorib-17.ok
	new file:   examples/aorib/tests/aorib-18.in
	new file:   examples/aorib/tests/aorib-18.ok
	new file:   examples/aorib/tests/aorib-2.in
	new file:   examples/aorib/tests/aorib-2.ok
	new file:   examples/aorib/tests/aorib-3.in
	new file:   examples/aorib/tests/aorib-3.ok
	new file:   examples/aorib/tests/aorib-4.in
	new file:   examples/aorib/tests/aorib-4.ok
	new file:   examples/aorib/tests/aorib-5.in
	new file:   examples/aorib/tests/aorib-5.ok
	new file:   examples/aorib/tests/aorib-6.in
	new file:   examples/aorib/tests/aorib-6.ok
	new file:   examples/aorib/tests/aorib-7.in
	new file:   examples/aorib/tests/aorib-7.ok
	new file:   examples/aorib/tests/aorib-8.in
	new file:   examples/aorib/tests/aorib-8.ok
	new file:   examples/aorib/tests/aorib-9.in
	new file:   examples/aorib/tests/aorib-9.ok
	new file:   examples/aplusb/buildtests.sh
	new file:   examples/aplusb/eval/eval.bin
	new file:   examples/aplusb/eval/eval.cpp
	new file:   examples/aplusb/eval/makefile
	new file:   examples/aplusb/incf/fixed
	new file:   examples/aplusb/incf/random
	new file:   examples/aplusb/ingen/ingen.bin
	new file:   examples/aplusb/ingen/ingen.cpp
	new file:   examples/aplusb/ingen/makefile
	new file:   examples/aplusb/lib.sh
	new file:   examples/aplusb/okgen/makefile
	new file:   examples/aplusb/okgen/okgen.bin
	new file:   examples/aplusb/okgen/okgen.cpp
	new file:   examples/aplusb/problemconfig.sh
	new file:   examples/aplusb/run.sh
	renamed:    src/ok.cpp -> examples/aplusb/src/ok.cpp
	new file:   examples/aplusb/src/tle.cpp
	new file:   examples/aplusb/src/wa.cpp
	new file:   examples/aplusb/testmanifest
	new file:   examples/aplusb/tests/aplusb-0.in
	new file:   examples/aplusb/tests/aplusb-0.ok
	new file:   examples/aplusb/tests/aplusb-1.in
	new file:   examples/aplusb/tests/aplusb-1.ok
	new file:   examples/aplusb/tests/aplusb-10.in
	new file:   examples/aplusb/tests/aplusb-10.ok
	new file:   examples/aplusb/tests/aplusb-11.in
	new file:   examples/aplusb/tests/aplusb-11.ok
	new file:   examples/aplusb/tests/aplusb-12.in
	new file:   examples/aplusb/tests/aplusb-12.ok
	new file:   examples/aplusb/tests/aplusb-13.in
	new file:   examples/aplusb/tests/aplusb-13.ok
	new file:   examples/aplusb/tests/aplusb-14.in
	new file:   examples/aplusb/tests/aplusb-14.ok
	new file:   examples/aplusb/tests/aplusb-15.in
	new file:   examples/aplusb/tests/aplusb-15.ok
	new file:   examples/aplusb/tests/aplusb-16.in
	new file:   examples/aplusb/tests/aplusb-16.ok
	new file:   examples/aplusb/tests/aplusb-17.in
	new file:   examples/aplusb/tests/aplusb-17.ok
	new file:   examples/aplusb/tests/aplusb-18.in
	new file:   examples/aplusb/tests/aplusb-18.ok
	new file:   examples/aplusb/tests/aplusb-2.in
	new file:   examples/aplusb/tests/aplusb-2.ok
	new file:   examples/aplusb/tests/aplusb-3.in
	new file:   examples/aplusb/tests/aplusb-3.ok
	new file:   examples/aplusb/tests/aplusb-4.in
	new file:   examples/aplusb/tests/aplusb-4.ok
	new file:   examples/aplusb/tests/aplusb-5.in
	new file:   examples/aplusb/tests/aplusb-5.ok
	new file:   examples/aplusb/tests/aplusb-6.in
	new file:   examples/aplusb/tests/aplusb-6.ok
	new file:   examples/aplusb/tests/aplusb-7.in
	new file:   examples/aplusb/tests/aplusb-7.ok
	new file:   examples/aplusb/tests/aplusb-8.in
	new file:   examples/aplusb/tests/aplusb-8.ok
	new file:   examples/aplusb/tests/aplusb-9.in
	new file:   examples/aplusb/tests/aplusb-9.ok
	new file:   examples/tmp/buildtests.sh
	new file:   examples/tmp/eval/makefile
	new file:   examples/tmp/incf/makefile
	new file:   examples/tmp/ingen/makefile
	new file:   examples/tmp/lib.sh
	new file:   examples/tmp/okgen/makefile
	new file:   examples/tmp/problemconfig.sh
	new file:   examples/tmp/run.sh
	new file:   examples/tmp/src/makefile
	new file:   examples/tmp/testmanifest
	new file:   examples/tmp/todo
	new file:   makeproject.sh
	new file:   src/buildtests.sh
	new file:   src/lib.sh
	new file:   src/run.sh
	new file:   src/todo

 Changes not staged for commit:
	deleted:    buildtests.sh
	deleted:    eval/eval.bin
	deleted:    eval/eval.cpp
	deleted:    eval/makefile
	deleted:    incf/fixed
	deleted:    incf/random
	deleted:    ingen/ingen.bin
	deleted:    ingen/ingen.cpp
	deleted:    ingen/makefile
	deleted:    lib.sh
	deleted:    okgen/makefile
	deleted:    okgen/okgen.bin
	deleted:    okgen/okgen.cpp
	deleted:    problemconfig.sh
	deleted:    run.sh
	deleted:    testmanifest
	deleted:    tests/aplusb-0.in
	deleted:    tests/aplusb-0.ok
	deleted:    tests/aplusb-1.in
	deleted:    tests/aplusb-1.ok
	deleted:    tests/aplusb-10.in
	deleted:    tests/aplusb-10.ok
	deleted:    tests/aplusb-11.in
	deleted:    tests/aplusb-11.ok
	deleted:    tests/aplusb-12.in
	deleted:    tests/aplusb-12.ok
	deleted:    tests/aplusb-13.in
	deleted:    tests/aplusb-13.ok
	deleted:    tests/aplusb-14.in
	deleted:    tests/aplusb-14.ok
	deleted:    tests/aplusb-15.in
	deleted:    tests/aplusb-15.ok
	deleted:    tests/aplusb-16.in
	deleted:    tests/aplusb-16.ok
	deleted:    tests/aplusb-17.in
	deleted:    tests/aplusb-17.ok
	deleted:    tests/aplusb-18.in
	deleted:    tests/aplusb-18.ok
	deleted:    tests/aplusb-2.in
	deleted:    tests/aplusb-2.ok
	deleted:    tests/aplusb-3.in
	deleted:    tests/aplusb-3.ok
	deleted:    tests/aplusb-4.in
	deleted:    tests/aplusb-4.ok
	deleted:    tests/aplusb-5.in
	deleted:    tests/aplusb-5.ok
	deleted:    tests/aplusb-6.in
	deleted:    tests/aplusb-6.ok
	deleted:    tests/aplusb-7.in
	deleted:    tests/aplusb-7.ok
	deleted:    tests/aplusb-8.in
	deleted:    tests/aplusb-8.ok
	deleted:    tests/aplusb-9.in
	deleted:    tests/aplusb-9.ok
  • Loading branch information
Tamio Vesa Nakajima authored and Tamio Vesa Nakajima committed May 20, 2018
1 parent af592ae commit facd3fe
Show file tree
Hide file tree
Showing 135 changed files with 1,400 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Hello.
This is a bundle of scripts used to prepare competitive programming problems

File descriptions:
To make a project, while in this directory, call ./makeproject */path/to/where/project/should/be*.

README.md | This readme
Description of a project's structure:

File name | Description
--------- | -----------
problemconfig.sh | A script that sets problem configuration variables (i.e. $problemname, $timelimit)
lib.sh | A bash library, used for the scripts in this bundle
Expand Down
73 changes: 73 additions & 0 deletions examples/aorib/buildtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#
# This builds all tests using testmanifest
# Tamio-Vesa Nakajima

# include the library
source lib.sh

# include the configuration
source problemconfig.sh

# Make stage (as git deletes it)
mkdir -p stage

# We will want to remember this:
currtest=0

# Loop over lines of
cat testmanifest | while read instr; do
# Parse a line of testmanifest
set $instr
numberoftests=$1
incf=$2
totalpoints=$3
points=$(($totalpoints / $numberoftests))

for nr in `seq $currtest $(($currtest + $numberoftests - 1))` ; do
echo $nr
#################
# Build input:
#################

# Build input generator
try "cd ingen && make -s && cd .." "input generator build fail"

# Copy ingen/ingen.bin and incf/$1 into stage
cp ingen/ingen.bin stage/$problemname.bin
try "cp incf/$incf stage/$problemname.cf" "incf/$incf doesn't exist"

# Build input
try "cd stage && ./$problemname.bin > ../tests/$problemname-$nr.in && cd .." "input generation fail"

# Clean stage
rm stage/*

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

# Build ok generator
try "cd okgen && make -s && cd .." "ok generator build fil"

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

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

# Build ok
try "cd stage && ./$problemname.bin && cd .." "ok generation fail"

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

# Clean stage
rm stage/*
done

#update currtest
currtest=$(($currtest + $numberoftests))

done
Binary file added examples/aorib/eval/eval.bin
Binary file not shown.
22 changes: 22 additions & 0 deletions examples/aorib/eval/eval.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

int main(){
ifstream fout("aorib.out");
ifstream fok("aorib.ok");

int points = 0;
fok >> points;

string s1, s2;
while(fok >> s1){
if(!bool(fout >> s2) || s1 != s2){
cerr << "WA" << endl;
cout << 0 << endl;
return 0; } }

cerr << "OK" << endl;
cout << points << endl;
return 0; }
2 changes: 2 additions & 0 deletions examples/aorib/eval/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../eval/eval.bin:
g++ eval.cpp -std=c++11 -o ../eval/eval.bin
1 change: 1 addition & 0 deletions examples/aorib/incf/fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 0 1
Empty file added examples/aorib/incf/makefile
Empty file.
1 change: 1 addition & 0 deletions examples/aorib/incf/random
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 0
Binary file added examples/aorib/ingen/ingen.bin
Binary file not shown.
16 changes: 16 additions & 0 deletions examples/aorib/ingen/ingen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include <fstream>
using namespace std;

int main(){
ifstream f("aorib.cf");
ofstream g("aorib.in");
bool fixed;
int x, y;
f >> fixed >> x >> y;

if(fixed) g << x << ' ' << y << endl;
else{
srand(time(nullptr));
g << rand() << ' ' << rand() << endl; }
return 0; }
2 changes: 2 additions & 0 deletions examples/aorib/ingen/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../ingen/ingen.bin:
g++ ingen.cpp -std=c++11 -o ../ingen/ingen.bin
100 changes: 100 additions & 0 deletions examples/aorib/lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
#
# Bash library for this project
# Tamio-Vesa Nakajima

# Tries to execute $1 ; if this succeeds, do nothing
# otherwise, output $2
try () {
if eval $1 ; then
:
else
echo $2
exit 1
fi
}

# Tries to copy $1 to $2 ; if $1 doesn't exist, creates an empty $2
maybecp () {
if [ -f $1 ] ; then
cp $1 $2
else
touch $2
fi
}

# Evaluates the binary $1 with test $2, returning the message in $message, the time used in $timeUsed and the points in $points
evaluate_src_test () {
binary=$1
testname=$2

# Get an appropriate timeout command
timeoutCommand=timeout

if [[ "$OSTYPE" == "darwin"* ]] ; then
timeoutCommand=gtimeout
fi

# Fetch the problem configuration
source problemconfig.sh

# clear any previous messages
echo -en " \r"

# Output an appropriate messgae
echo -en "Doing $testname\r"

# Clean the stage
rm stage/*

# Copy the binary into the stage
cp $binary stage/$problemname.bin

# Copy the input into the stage
cp tests/$testname.in stage/$problemname.in

# Get the problem config
source problemconfig.sh

# This string runs the competitor's executable
runExec="./$problemname.bin > /dev/null 2> /dev/null"

# This string runs the competitors executable with an appropriate timeout
runExecWithTimeout="$timeoutCommand $timelimit $runExec"

# Run the competitors executable with a timeout, and store the time used in timeUsed
timeUsed=$(cd stage && { time $runExecWithTimeout ; } 2>&1 >/dev/null \
| tail -3 \
| head -1 \
| awk -F ' ' '{print $2}' \
| awk -F 'm' '{print $2}' \
| awk -F 's' '{print $1}' && cd ..)

if (( $(echo "$timeUsed > $timelimit" | bc -l))) ; then
# Set the return values
# timeUsed is already set
message=TLE
points=0
else
# Make the evaluator
try "cd eval && make -s && cd .." "evaluator build fail"

# Copy the evaluator into the stage
cp eval/eval.bin stage/eval.bin

# Copy the ok file into the stage
cp tests/$testname.ok stage/$problemname.ok

# Create temporary files to hold the points and the eval message
pointsFile=`mktemp`
messageFile=`mktemp`

# Enter the stage and evaluate, storing the results in $pointsFile and $messageFile
try "cd stage && ./eval.bin > $pointsFile 2> $messageFile && cd .." "eval error"

# Set the return values
# timeUsed is already set
points=`cat $pointsFile`
message=`cat $messageFile`
fi
}
2 changes: 2 additions & 0 deletions examples/aorib/okgen/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../okgen/okgen.bin:
g++ okgen.cpp -std=c++11 -o ../okgen/okgen.bin
Binary file added examples/aorib/okgen/okgen.bin
Binary file not shown.
14 changes: 14 additions & 0 deletions examples/aorib/okgen/okgen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <fstream>
using namespace std;

int main(){
ifstream points("aorib.points");
ifstream f("aorib.in");
ofstream g("aorib.ok");

long long p, x, y;
f >> x >> y;
points >> p;
g << p << endl;
g << x*y << endl;
return 0; }
2 changes: 2 additions & 0 deletions examples/aorib/problemconfig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
problemname=aorib
timelimit=0.1
107 changes: 107 additions & 0 deletions examples/aorib/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash
#
# Runs sources on tests
# Tamio-Vesa Nakajima
#
# Use cases:
# ./run.sh -> runs all sources on all tests
# ./run.sh -s "a.cpp b.cpp" -s c.cpp -> runs a,b,c.cpp on all tests
# ./run.sh -t "00 01 02" -> runs all sources on tests 00, 01, 02
# ./run.sh -s a.cpp -t 00 -> runs a.cpp on 00

##########################
# GENERAL SETUP
#########################

# include the library
source lib.sh

# include the configuration
source problemconfig.sh

# make stage (as git deletes it)
mkdir -p stage

############################
# ARGUMENT PARSING
#############################

# default values for used sources and used tests

srcs=""
tests=""

while getopts "hs:t:" opt; do
case $opt in
h)
echo "Usage: ./run.sh -s [source] -t [test]"
exit 0
;;
s)
for x in $OPTARG ; do
srcs="$srcs $x"
done
;;
t)
for x in $OPTARG ; do
tests="$tests $problemname-$x"
done
;;
esac
done

if [ -z "$srcs" ] ; then
srcs=`ls -1 src | grep .cpp`
fi

if [ -z "$tests" ] ; then
tests=`ls -1 tests | grep .in | awk -F '.' '{print $1}'`
fi

tests=`echo $tests | sort -t '-' -k 1 -n`


###########################
# EVALUATING
##########################

for src in $srcs ; do
# Copy the source into the stage
try "cp src/$src stage/$problemname.cpp" "source file missing"

# Create a temporary file to hold the problem binary
binary=`mktemp`

# Build the source
try "g++ stage/$problemname.cpp -std=c++11 -o $binary -O2" "Compile error"

# Make a temporary file to hold the table:
table=`mktemp`

# $table holds the score table
echo $src > $table
echo Test Message Time Points >> $table

# For all tests
for testname in $tests ; do
# evaluate $binary on $testname, setting $message, $timeUsed, $points
evaluate_src_test $binary $testname
echo $testname.in $message $timeUsed $points >> $table
done

# Clear "Doing test ..."
echo -en " \r"

# Output the table
column -t $table

# Calculate the score
echo SCORE: `awk -F ' ' '$1 != "Test" {sum += 0 $4} END {print sum}' $table`

# Clear the temporary files
rm $table
rm $binary

# And the stage
rm stage/*
done
Empty file added examples/aorib/src/makefile
Empty file.
10 changes: 10 additions & 0 deletions examples/aorib/src/ok.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <fstream>
using namespace std;

int main(){
ifstream f("aorib.in");
ofstream g("aorib.out");
long long x, y;
f >> x >> y;
g << x*y << endl;
return 0; }
File renamed without changes.
File renamed without changes.
Binary file added examples/aorib/stage/aorib.bin
Binary file not shown.
Empty file added examples/aorib/stage/aorib.in
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/testmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 fixed 10
18 random 90
Empty file added examples/aorib/tests/aorib-0.in
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-0.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10
0
Empty file added examples/aorib/tests/aorib-1.in
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-1.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-10.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-11.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-12.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Empty file.
2 changes: 2 additions & 0 deletions examples/aorib/tests/aorib-13.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
0
Empty file.
Loading

0 comments on commit facd3fe

Please sign in to comment.