diff options
author | prathamesh | 2013-05-06 11:56:16 +0530 |
---|---|---|
committer | prathamesh | 2013-05-08 12:21:37 +0530 |
commit | 6667efae7acb86f60b0ebd4dabb959bed759bc16 (patch) | |
tree | a0d7a22670e91427e82cd6037c8bd29155d38b51 /testapp/docs | |
parent | 8b6ac259503323bc3d8333382d3769e5d10f162a (diff) | |
download | online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.tar.gz online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.tar.bz2 online_test-6667efae7acb86f60b0ebd4dabb959bed759bc16.zip |
Function to check C-C++ code
Added a function which compiles C and C++ code submitted by the student.
1) If compilation is successful, then the submitted code is tested using
test-cases.
2) To test the function written by the student, a C++ file calls the
function and passes the argument to the function. Then the function
checks for the expected return value.
3) If the return value is as expected, then a different set of arguments
are passed, and the output is checked.
4) If for all set of arguments the output is as expected then the student
code is graded correct else the error is displayed to the student.
Changed the way the code is graded.
Previously, the algorithm checked the student code for all test-cases.
If all the test-cases were satisfied, the last-line
of the program was reached and printed "All Correct". So at
any point if a test-case fails, the last line is not reached as
the program was terminate. When the string "All Correct" was
found in the output, the code was graded as RIGHT else WRONG.
This is not a proper way for code checking, as the student code *may*
contain a print statement with the string('All Correct'), and thus
can get program RIGHT even though it is WRONG.
So now the student code is tested as follows:
1) The code checks for all test-cases.
2) If all test-cases are satisfied then it returns 0.
3) If any one of the test-case fails, the program is terminated and will return 1.
4) Now depending on the return status(0 or 1), it will grade the code.
a) if 0 then RIGHT
b) if 1 then WRONG
This ensures, no manipulation from student side.
Diffstat (limited to 'testapp/docs')
-rw-r--r-- | testapp/docs/add.c | 4 | ||||
-rw-r--r-- | testapp/docs/add.cpp | 6 | ||||
-rw-r--r-- | testapp/docs/array_sum.c | 10 | ||||
-rw-r--r-- | testapp/docs/array_sum.cpp | 10 | ||||
-rw-r--r-- | testapp/docs/fact.c | 10 | ||||
-rw-r--r-- | testapp/docs/fact.cpp | 16 | ||||
-rw-r--r-- | testapp/docs/greatest.c | 15 | ||||
-rw-r--r-- | testapp/docs/greatest.cpp | 15 | ||||
-rw-r--r-- | testapp/docs/hello_name.c | 16 | ||||
-rwxr-xr-x | testapp/docs/main.cpp | 30 | ||||
-rwxr-xr-x | testapp/docs/main2.c | 28 | ||||
-rwxr-xr-x | testapp/docs/main_array_sum.cpp | 32 | ||||
-rwxr-xr-x | testapp/docs/main_fact.cpp | 30 | ||||
-rwxr-xr-x | testapp/docs/main_greatest.cpp | 32 | ||||
-rwxr-xr-x | testapp/docs/main_hello_name.c | 29 | ||||
-rwxr-xr-x | testapp/docs/main_palindrome.cpp | 30 | ||||
-rw-r--r-- | testapp/docs/palindrome.c | 20 | ||||
-rw-r--r-- | testapp/docs/palindrome.cpp | 19 | ||||
-rwxr-xr-x | testapp/docs/sample.c | 20 | ||||
-rwxr-xr-x | testapp/docs/sample.cpp | 7 |
20 files changed, 379 insertions, 0 deletions
diff --git a/testapp/docs/add.c b/testapp/docs/add.c new file mode 100644 index 0000000..c829971 --- /dev/null +++ b/testapp/docs/add.c @@ -0,0 +1,4 @@ +int add(int a,int b) +{ + return a-b; +} diff --git a/testapp/docs/add.cpp b/testapp/docs/add.cpp new file mode 100644 index 0000000..d3b7897 --- /dev/null +++ b/testapp/docs/add.cpp @@ -0,0 +1,6 @@ +#include<stdio.h> +int add(int a,int b) +{ + printf("All Correct"); + return a; +} diff --git a/testapp/docs/array_sum.c b/testapp/docs/array_sum.c new file mode 100644 index 0000000..619a23c --- /dev/null +++ b/testapp/docs/array_sum.c @@ -0,0 +1,10 @@ +int array_sum(int a[5]) +{ + int i=0, sum=0; + for(i=0;i<5;i++) + { + sum = sum + a[i]; + } + return sum; +} + diff --git a/testapp/docs/array_sum.cpp b/testapp/docs/array_sum.cpp new file mode 100644 index 0000000..9b82d3b --- /dev/null +++ b/testapp/docs/array_sum.cpp @@ -0,0 +1,10 @@ +int array_sum(int a[]) +{ + int i=0, sum=0; + for(i=0;i<5;i++) + { + sum = sum + a[i]; + } + return sum; +} + diff --git a/testapp/docs/fact.c b/testapp/docs/fact.c new file mode 100644 index 0000000..e3665f5 --- /dev/null +++ b/testapp/docs/fact.c @@ -0,0 +1,10 @@ +int factorial(int a) +{ + int i,fact=1; + for(i=1;i<=a;a--) + { + fact=fact*a; + } + return fact; + +} diff --git a/testapp/docs/fact.cpp b/testapp/docs/fact.cpp new file mode 100644 index 0000000..f9b7458 --- /dev/null +++ b/testapp/docs/fact.cpp @@ -0,0 +1,16 @@ +#include<stdio.h> +int fact = 1; +int factorial(int a) +{ + printf("%d\n",a); + if(a<1) + { + printf("\nfinal"); + return 1; + } + else + { + printf("count\n"); + return a*factorial(a-1); + } +} diff --git a/testapp/docs/greatest.c b/testapp/docs/greatest.c new file mode 100644 index 0000000..0194855 --- /dev/null +++ b/testapp/docs/greatest.c @@ -0,0 +1,15 @@ +int greatest(int a,int b,int c) +{ + if(a>b && a>c) + { + return a; + } + else if(b>c) + { + return b; + } + else + { + return c; + } +} diff --git a/testapp/docs/greatest.cpp b/testapp/docs/greatest.cpp new file mode 100644 index 0000000..0194855 --- /dev/null +++ b/testapp/docs/greatest.cpp @@ -0,0 +1,15 @@ +int greatest(int a,int b,int c) +{ + if(a>b && a>c) + { + return a; + } + else if(b>c) + { + return b; + } + else + { + return c; + } +} diff --git a/testapp/docs/hello_name.c b/testapp/docs/hello_name.c new file mode 100644 index 0000000..8fa2519 --- /dev/null +++ b/testapp/docs/hello_name.c @@ -0,0 +1,16 @@ +#include<string.h> +#include<stdio.h> + +char *message(char a[]) +{ + return (strcat("hello",a)); +} + +main() +{ + printf("he\n"); + char q[]="re"; + char s[20]; + s= message(q); + printf("%s",s); +} diff --git a/testapp/docs/main.cpp b/testapp/docs/main.cpp new file mode 100755 index 0000000..ffd110e --- /dev/null +++ b/testapp/docs/main.cpp @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> + +extern int add(int, int); + +template <class T> + +void check(T expect, T result) +{ + if (expect == result) + { + //printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("\nIncorrect:\n Expected %d got %d \n",expect,result); + exit (1); + } +} + +int main(void) +{ + int result; + result = add(0,0); + check(0, result); + result = add(2,3); + check(5,result); + printf("All Correct\n"); + return 0; +} diff --git a/testapp/docs/main2.c b/testapp/docs/main2.c new file mode 100755 index 0000000..3d28ff6 --- /dev/null +++ b/testapp/docs/main2.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <stdlib.h> + +extern int add(int, int, int); + +template <class T> +void check(T expect,T result) +{ + if (expect == result) + { + printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("Incorrect:\n Expected %d got %d \n",expect,result); + exit (0); + } +} + +int main(void) +{ + int result; + result = add(0,0,0); + check(0, result); + result = add(2,3,3); + check(8,result); + printf("All Correct\n"); +} diff --git a/testapp/docs/main_array_sum.cpp b/testapp/docs/main_array_sum.cpp new file mode 100755 index 0000000..72eee46 --- /dev/null +++ b/testapp/docs/main_array_sum.cpp @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <stdlib.h> + +extern int array_sum(int []); + +template <class T> + +void check(T expect,T result) +{ + if (expect == result) + { + //printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("\nIncorrect:\n Expected %d got %d \n",expect,result); + exit (1); + } +} + +int main(void) +{ + int result; + int a[55555] = {1,2,3,0,0}; + result = array_sum(a); + check(6, result); + int b[] = {1,2,3,4,5}; + result = array_sum(b); + check(15,result); + printf("All Correct\n"); + return 0; +} diff --git a/testapp/docs/main_fact.cpp b/testapp/docs/main_fact.cpp new file mode 100755 index 0000000..ff65456 --- /dev/null +++ b/testapp/docs/main_fact.cpp @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> + +extern int factorial(int); + +template <class T> + +void check(T expect, T result) +{ + if (expect == result) + { + //printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("\nIncorrect:\n Expected %d got %d \n",expect,result); + exit (1); + } +} + +int main(void) +{ + int result; + result = factorial(0); + check(1, result); + result = factorial(3); + check(6, result); + printf("All Correct\n"); + return 0; +} diff --git a/testapp/docs/main_greatest.cpp b/testapp/docs/main_greatest.cpp new file mode 100755 index 0000000..fe9ff5b --- /dev/null +++ b/testapp/docs/main_greatest.cpp @@ -0,0 +1,32 @@ +#include <stdio.h> +#include <stdlib.h> + +extern int greatest(int, int, int); + +template <class T> + +void check(T expect, T result) +{ + if (expect == result) + { + //printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("\nIncorrect:\n Expected %d got %d \n",expect,result); + exit (1); + } +} + +int main(void) +{ + int result; + result = greatest(1, 2, 3); + check(3, result); + result = greatest(5, 9, 2); + check(9, result); + result = greatest(7, 2, 4); + check(7, result); + printf("All Correct\n"); + return 0; +} diff --git a/testapp/docs/main_hello_name.c b/testapp/docs/main_hello_name.c new file mode 100755 index 0000000..71b83a2 --- /dev/null +++ b/testapp/docs/main_hello_name.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> + + +void check(char expect[], char result[]) +{ + if (expect == result) + { + printf("Correct:expected %s got %s \n",expect,result); + } + else + { + printf("ERROR:expected %s got %s \n",expect,result); + exit (0); + } +} + +int main(void) +{ + char result[20]; + char A[20]=" pratham"; + char B[20]=" sir"; + result[20] = message(A); + printf("%s",result); + check("hello pratham", result); + result[20] = message(B); + check("hello sir",result); + printf("All Correct\n"); +} diff --git a/testapp/docs/main_palindrome.cpp b/testapp/docs/main_palindrome.cpp new file mode 100755 index 0000000..a5d67b5 --- /dev/null +++ b/testapp/docs/main_palindrome.cpp @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> + +extern bool palindrome(int); + +template <class T> + +void check(T expect, T result) +{ + if (expect == result) + { + //printf("Correct:\n Expected %d got %d \n",expect,result); + } + else + { + printf("\nIncorrect:\n Expected %d got %d \n",expect,result); + exit (1); + } +} + +int main(void) +{ + bool result; + result = palindrome(123); + check(false, result); + result = palindrome(121); + check(true, result); + printf("All Correct\n"); + return 0; +} diff --git a/testapp/docs/palindrome.c b/testapp/docs/palindrome.c new file mode 100644 index 0000000..236d963 --- /dev/null +++ b/testapp/docs/palindrome.c @@ -0,0 +1,20 @@ +#include <stdbooll.h> +bool palindrome(int a) +{ + int n1, rev = 0, rem; + n1 = a; + while (a > 0) + { + rem = a % 10; + rev = rev * 10 + rem; + a = a / 10; + } + if (n1 == rev) + { + return true; + } + else + { + return false; + } +} diff --git a/testapp/docs/palindrome.cpp b/testapp/docs/palindrome.cpp new file mode 100644 index 0000000..aae5dd1 --- /dev/null +++ b/testapp/docs/palindrome.cpp @@ -0,0 +1,19 @@ +bool palindrome(int n) +{ + int n1, rev = 0, rem; + n1 = n; + while (n > 0) + { + rem = n % 10; + rev = rev * 10 + rem; + n = n / 10; + } + if (n1 == rev) + { + return true; + } + else + { + return false; + } +} diff --git a/testapp/docs/sample.c b/testapp/docs/sample.c new file mode 100755 index 0000000..660f862 --- /dev/null +++ b/testapp/docs/sample.c @@ -0,0 +1,20 @@ +#include<stdio.h> + +void main(int argc , char * argv[]) +{ + int i,sum=0; + +/* if(argc!=3) + { + printf("you have forgot to type numbers."); + exit(1); + } +*/ + printf("The sum is : "); + + for(i=1;i<argc;i++) + sum = sum + atoi(argv[i]); + + printf("%d",sum); + +} diff --git a/testapp/docs/sample.cpp b/testapp/docs/sample.cpp new file mode 100755 index 0000000..ab77b85 --- /dev/null +++ b/testapp/docs/sample.cpp @@ -0,0 +1,7 @@ +#include <iostream> +#include<cstdlib> +int main(int argc, char* argv[]) +{ + std::cout << atoi(argv[1])+atoi(argv[2]) << std::endl; + return 0; +} |