Skip to content

Commit 8a9ed39

Browse files
committedNov 4, 2016
initial commit
0 parents  commit 8a9ed39

16 files changed

+409
-0
lines changed
 

‎README.md

+273
Large diffs are not rendered by default.

‎images/fourth-degree-friends2.png

121 KB
Loading

‎images/friend-of-a-friend1.png

76.3 KB
Loading

‎insight_testsuite/run_tests.sh

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/bash
2+
3+
declare -r color_start="\033["
4+
declare -r color_red="${color_start}0;31m"
5+
declare -r color_green="${color_start}0;32m"
6+
declare -r color_blue="${color_start}0;34m"
7+
declare -r color_norm="${color_start}0m"
8+
9+
GRADER_ROOT=$(dirname ${BASH_SOURCE})
10+
11+
PROJECT_PATH=${GRADER_ROOT}/..
12+
13+
function print_dir_contents {
14+
local proj_path=$1
15+
echo "Project contents:"
16+
echo -e "${color_blue}$(ls ${proj_path})${color_norm}"
17+
}
18+
19+
function find_file_or_dir_in_project {
20+
local proj_path=$1
21+
local file_or_dir_name=$2
22+
if [[ ! -e "${proj_path}/${file_or_dir_name}" ]]; then
23+
echo -e "[${color_red}FAIL${color_norm}]: no ${file_or_dir_name} found"
24+
print_dir_contents ${proj_path}
25+
echo -e "${color_red}${file_or_dir_name} [MISSING]${color_norm}"
26+
exit 1
27+
fi
28+
}
29+
30+
# check project directory structure
31+
function check_project_struct {
32+
find_file_or_dir_in_project ${PROJECT_PATH} run.sh
33+
find_file_or_dir_in_project ${PROJECT_PATH} src
34+
find_file_or_dir_in_project ${PROJECT_PATH} paymo_input
35+
find_file_or_dir_in_project ${PROJECT_PATH} paymo_output
36+
}
37+
38+
# setup testing output folder
39+
function setup_testing_input_output {
40+
TEST_OUTPUT_PATH=${GRADER_ROOT}/temp
41+
if [ -d ${TEST_OUTPUT_PATH} ]; then
42+
rm -rf ${TEST_OUTPUT_PATH}
43+
fi
44+
45+
mkdir -p ${TEST_OUTPUT_PATH}
46+
47+
cp -r ${PROJECT_PATH}/src ${TEST_OUTPUT_PATH}
48+
cp -r ${PROJECT_PATH}/run.sh ${TEST_OUTPUT_PATH}
49+
cp -r ${PROJECT_PATH}/paymo_input ${TEST_OUTPUT_PATH}
50+
cp -r ${PROJECT_PATH}/paymo_output ${TEST_OUTPUT_PATH}
51+
52+
rm -r ${TEST_OUTPUT_PATH}/paymo_input/*
53+
rm -r ${TEST_OUTPUT_PATH}/paymo_output/*
54+
cp -r ${GRADER_ROOT}/tests/${test_folder}/paymo_input/batch_payment.txt ${TEST_OUTPUT_PATH}/paymo_input/batch_payment.txt
55+
cp -r ${GRADER_ROOT}/tests/${test_folder}/paymo_input/stream_payment.txt ${TEST_OUTPUT_PATH}/paymo_input/stream_payment.txt
56+
}
57+
58+
function compare_outputs {
59+
PROJECT_ANSWER_PATH1=${GRADER_ROOT}/temp/paymo_output/output1.txt
60+
PROJECT_ANSWER_PATH2=${GRADER_ROOT}/temp/paymo_output/output2.txt
61+
PROJECT_ANSWER_PATH3=${GRADER_ROOT}/temp/paymo_output/output3.txt
62+
TEST_ANSWER_PATH1=${GRADER_ROOT}/tests/${test_folder}/paymo_output/output1.txt
63+
TEST_ANSWER_PATH2=${GRADER_ROOT}/tests/${test_folder}/paymo_output/output2.txt
64+
TEST_ANSWER_PATH3=${GRADER_ROOT}/tests/${test_folder}/paymo_output/output3.txt
65+
66+
DIFF_RESULT1=$(diff -bB ${PROJECT_ANSWER_PATH1} ${TEST_ANSWER_PATH1} | wc -l)
67+
if [ "${DIFF_RESULT1}" -eq "0" ] && [ -f ${PROJECT_ANSWER_PATH1} ]; then
68+
echo -e "[${color_green}PASS${color_norm}]: ${test_folder} (output1.txt)"
69+
PASS_CNT=$(($PASS_CNT+1))
70+
else
71+
echo -e "[${color_red}FAIL${color_norm}]: ${test_folder} (output1.txt)"
72+
diff ${PROJECT_ANSWER_PATH1} ${TEST_ANSWER_PATH1}
73+
fi
74+
75+
DIFF_RESULT2=$(diff -bB ${PROJECT_ANSWER_PATH2} ${TEST_ANSWER_PATH2} | wc -l)
76+
if [ "${DIFF_RESULT2}" -eq "0" ] && [ -f ${PROJECT_ANSWER_PATH2} ]; then
77+
echo -e "[${color_green}PASS${color_norm}]: ${test_folder} (output2.txt)"
78+
PASS_CNT=$(($PASS_CNT+1))
79+
else
80+
echo -e "[${color_red}FAIL${color_norm}]: ${test_folder} (output2.txt)"
81+
diff ${PROJECT_ANSWER_PATH2} ${TEST_ANSWER_PATH2}
82+
fi
83+
84+
DIFF_RESULT3=$(diff -bB ${PROJECT_ANSWER_PATH3} ${TEST_ANSWER_PATH3} | wc -l)
85+
if [ "${DIFF_RESULT3}" -eq "0" ] && [ -f ${PROJECT_ANSWER_PATH3} ]; then
86+
echo -e "[${color_green}PASS${color_norm}]: ${test_folder} (output3.txt)"
87+
PASS_CNT=$(($PASS_CNT+1))
88+
else
89+
echo -e "[${color_red}FAIL${color_norm}]: ${test_folder} (output3.txt)"
90+
diff ${PROJECT_ANSWER_PATH3} ${TEST_ANSWER_PATH3}
91+
fi
92+
}
93+
94+
function run_all_tests {
95+
TEST_FOLDERS=$(ls ${GRADER_ROOT}/tests)
96+
NUM_TESTS=$(($(echo $(echo ${TEST_FOLDERS} | wc -w)) * 3))
97+
PASS_CNT=0
98+
99+
# Loop through all tests
100+
for test_folder in ${TEST_FOLDERS}; do
101+
102+
setup_testing_input_output
103+
104+
cd ${GRADER_ROOT}/temp
105+
bash run.sh 2>&1
106+
cd ../
107+
108+
compare_outputs
109+
done
110+
111+
echo "[$(date)] ${PASS_CNT} of ${NUM_TESTS} tests passed" >> ${GRADER_ROOT}/results.txt
112+
}
113+
114+
check_project_struct
115+
run_all_tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
time, id1, id2, amount, message
2+
2016-11-01 17:38:25, 49466, 6989, 23.74, 🦄
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
time, id1, id2, amount, message
2+
2016-11-01 17:49:26, 6989, 49466, 25.32, Spam
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trusted
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trusted
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trusted

‎paymo_input/batch_payment.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DOWNLOAD FILE AT [https://www.dropbox.com/s/y6fige3w1ohksbd/batch_payment.csv?dl=0]

‎paymo_input/stream_payment.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DOWNLOAD FILE AT [https://www.dropbox.com/s/vrn4pjlypwa2ki9/stream_payment.csv?dl=0]

‎paymo_output/output1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output for Feature 1 should go in this file.

‎paymo_output/output2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output for Feature 2 should go in this file.

‎paymo_output/output3.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output for Feature 3 should go in this file.

‎run.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# example of the run script for running the fraud detection algorithm with a python file,
4+
# but could be replaced with similar files from any major language
5+
6+
# I'll execute my programs, with the input directory paymo_input and output the files in the directory paymo_output
7+
python ./src/antifraud.py ./paymo_input/batch_payment.txt ./paymo_input/stream_payment.txt ./paymo_output/output1.txt ./paymo_output/output2.txt ./paymo_output/output3.txt

‎src/antifraud.java

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// example of program that detects suspicious transactions
2+
// fraud detection algorithm

0 commit comments

Comments
 (0)
Please sign in to comment.