Skip to content

Latest commit

 

History

History
228 lines (207 loc) · 4.66 KB

run.md

File metadata and controls

228 lines (207 loc) · 4.66 KB

Edit File: .bashrc

  1. Move to bottom of file (Alt + / with nano .bashrc)
  2. Copy the following contents:
ulimit -s 10000

function compile {
    g++ $1 -g -std=c++14 -Wall -Wextra -Wconversion -Wshadow -Wfatal-errors -fsanitize=address,undefined -o $2
}

function runcompiled {
    if [[ $1 == *.py ]]; then
        { time (python3 $1 <$2 >o 2>error) >/dev/null; } 2>timing
    else
        { time (./$1 <$2 >o 2>error) >/dev/null; } 2>timing
    fi
    cat timing | grep real | awk '{print $2}'
    cat error
    # Not required
    rm timing
    rm error
    # Required
    diff -y o ${2%in}[ao]?? >t || cat t || cat o
    # Not required
    rm o
    rm t
}

function run {
    clear;clear
    first_file=`ls -t *.{cpp,py} | head -n1`
    F=${1-$first_file}
    if [[ $F == *.c* ]]
    then
        compile $F sol
        runner='sol'
    else
        runner=$F
    fi
    if [ -n "$2" ]; then
        echo ---$F $2
        runcompiled $runner $2
    else
        for i in *.in; do
            echo ---$F $i
            runcompiled $runner $i
        done
    fi
}

## OPTIONAL

function runtests {
    # Arguments
        # Test generator
        # Correct script
        # Test script
        # Total tests
    clear;clear
    if [[ $2 == *.c* ]];
    then
        compile $2 correct
    fi
    if [[ $3 == *.c* ]];
    then
        compile $3 test
    fi
    ITERATIONS=${4:-50}
    completed=1
    for (( i=1; i<=ITERATIONS; i++ )) do
        echo "Test #$i"
        python3 $1 > test.in
        if [[ $2 == *.c* ]];
        then
            ./correct < test.in > test.out
        fi
        if [[ $2 == *.py ]];
        then
            python3 $2 < test.in > test.out
        fi
        error=$?
        if [[ $error -ne 0 ]]
        then
            echo "Error on test case with truth script"
            completed=0
            break
        fi
        if [[ $3 == *.c* ]];
        then
            ./test < test.in > test.cmp
        fi
        if [[ $3 == *.py ]];
        then
            python3 $3 < test.in > test.cmp
        fi
        error=$?
        if [[ $error -ne 0 ]]
        then
            echo "Error on test case with test script"
            completed=0
            break
        fi
        diff test.cmp test.out > /dev/null 2>&1
        difference=$?
        if [[ $difference -eq 1 ]]
        then
            echo "Difference found:"
            echo "test.cmp | test.out"
            diff test.cmp test.out
            completed=0
            break
        fi
    done
    rm test
    rm correct
    if [[ $completed -eq 1 ]]
    then
        echo "Completed $ITERATIONS tests successfuly."
        rm test.cmp
        rm test.in
        rm test.out
    fi
}

function checkresult {
    # Arguments
        # Test generator
        # Test script
        # Postprocessing
        # Num tests
    clear;clear
    if [[ $2 == *.c* ]];
    then
        compile $2 sol
    fi
    ITERATIONS=${4:-50}
    completed=1
    for (( i=1; i<=ITERATIONS; i++ )) do
        echo "Test #$i"
        python3 $1 > test.in
        if [[ $2 == *.c* ]];
        then
            ./sol < test.in > test.out
        fi
        if [[ $2 == *.py ]];
        then
            python3 $2 < test.in > test.out
        fi
        error=$?
        if [[ $error -ne 0 ]]
        then
            echo "Error on test case with test script"
            completed=0
            break
        fi
        python3 $3 test.in test.out > test.result
        str=GOOD
        if [[ $(< test.result) != "$str" ]]; then
            echo "Post processing failed."
            completed=0
            break
        fi
    done
    rm sol
    if [[ $completed -eq 1 ]]
    then
        echo "Completed $ITERATIONS tests successfuly."
        rm test.result
        rm test.in
        rm test.out
    fi
}
  1. Save (in nano, Ctl-X, then Y)

Template File - CPP

Call this t.cpp in the root directory for later use.

// Team Name (Monash)
#include <bits/stdc++.h>
using namespace std;

#define me (*this)
#define debug(a) cerr << #a << " = " << (a) << endl;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    return 0;
}

Template File - Python

Call this t.py in the root directory for later use.

# Team Name (Monash)

def read_ints():
    return list(map(int, input().split()))

cases = int(input())

for case in range(cases):
    # Do something.

Generate folders and template files

Run this in terminal once:

for i in {A..R}; do
    # Create subdir
    mkdir $i
    # Copy templates
    cp t.cpp $i/$i.cpp
    cp t.py $i/$i.py
    # Provided samples are downloaded, extract them.
done