Skip to content
Snippets Groups Projects
Commit 0111d199 authored by Baruta Daniel Mihail's avatar Baruta Daniel Mihail
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
checker:
image:
name: jokeswar/perfect-assignment
FROM jokeswar/base-ctl
RUN echo "Hello from Docker"
COPY ./checker ${CHECKER_DATA_DIRECTORY}
#!/bin/bash
cd "$(dirname "$0")" || exit 1
EXECUTABLE="../src/perfect"
TIMEOUT_DURATION=10
test_err()
{
local temp_output=''
temp_output="$(mktemp)"
timeout "$TIMEOUT_DURATION" xargs -a ./input/input1 -0 -I{} bash -c "$EXECUTABLE {} > $temp_output 2>&1"
diff -Zq "$temp_output" "./references/ref1" > /dev/null 2>&1
return $?
}
test_single()
{
local temp_output=''
temp_output="$(mktemp)"
timeout "$TIMEOUT_DURATION" xargs -a ./input/input2 -0 -I{} bash -c "$EXECUTABLE {} > $temp_output 2>&1"
diff -Zq "$temp_output" "./references/ref2" > /dev/null 2>&1
return $?
}
test_multiple()
{
local temp_output=''
temp_output="$(mktemp)"
timeout "$TIMEOUT_DURATION" xargs -a ./input/input3 -0 -I{} bash -c "$EXECUTABLE {} > $temp_output 2>&1"
diff -Zq "$temp_output" "./references/ref3" > /dev/null 2>&1
return $?
}
test_edge()
{
local temp_output=''
temp_output="$(mktemp)"
timeout "$TIMEOUT_DURATION" xargs -a ./input/input4 -0 -I{} bash -c "$EXECUTABLE {} > $temp_output 2>&1"
diff -Zq "$temp_output" "./references/ref4" > /dev/null 2>&1
return $?
}
setup()
{
pushd ../src > /dev/null || exit 1
make -s build
popd > /dev/null || exit 1
}
cleanup()
{
pushd ../src > /dev/null || exit 1
make -s clean
popd > /dev/null || exit 1
}
test_fun_array=( \
test_err "Name 1" 5 \
test_single "Name 2" 5 \
test_multiple "Name 3" 5 \
test_edge "Name 4" 5 \
)
test_all()
{
local score=0
for i in $(seq 0 "$((${#test_fun_array[@]} / 3 - 1))") ; do
test_index=$((i * 3))
description=${test_fun_array[$((test_index + 1))]}
points=${test_fun_array[$((test_index + 2))]}
echo -e "Testing\t\t$description"
if ${test_fun_array["$test_index"]} ; then
score=$((score + points))
fi
done
echo -e "\nTotal: $score"
}
setup
test_all
cleanup
1
\ No newline at end of file
3
\ No newline at end of file
0
\ No newline at end of file
Not enough arguments!
1
1 1 1
local.sh 0 → 100755
#!/bin/bash
cd "$(dirname "$0")" || exit 1
#=============================================================================
#=================================== UTILS ===================================
#=============================================================================
LOG_INFO() {
echo "[INFO] $1"
}
#=============================================================================
#=============================================================================
#=============================================================================
print_help() {
echo "Usage:"
echo ""
echo "local.sh [-h|--help] [--remove_image] [argumets_for_checker]"
echo ""
echo " --remove_image - remove the checker's docker image after the run"
echo " -h|--help - prints this message"
echo " argumets_for_checker - list of space separated arguments to be passed to the checker"
echo ""
}
main() {
local script_args=()
local remove_image=''
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
print_help
exit 0
;;
--remove_image)
remove_image='true'
;;
*)
script_args+=("$1")
;;
esac
shift
done
image_name="$(basename "$(pwd)")"
LOG_INFO "Building image..."
docker build -q -t "$image_name" .
tmpdir="$(mktemp -d)"
cp -R ./* "$tmpdir"
LOG_INFO "Running checker..."
docker run --rm \
--name "$image_name-container" \
--mount type=bind,source="$tmpdir",target=/build \
"$image_name" /bin/bash /build/checker/checker.sh "${script_args[@]}"
if [ -n "$remove_image" ] ; then
LOG_INFO "Cleaning up..."
docker rmi -f "$image_name":latest
fi
}
main "$@"
build: main.c
gcc main.c -o perfect
.PHONY: clean
clean:
rm perfect
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Not enough arguments!\n");
return 1;
}
int number = atoi(argv[1]);
for (int i = 0; i < number; i++)
printf("1 ");
printf("\n");
return 0;
}
File added
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