summaryrefslogtreecommitdiff
path: root/15_tests_subseq
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /15_tests_subseq
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to '15_tests_subseq')
-rw-r--r--15_tests_subseq/README24
-rw-r--r--15_tests_subseq/grade.txt52
-rw-r--r--15_tests_subseq/next-README31
-rwxr-xr-x15_tests_subseq/run_all.sh37
-rwxr-xr-x15_tests_subseq/test-subseqbin0 -> 16648 bytes
-rw-r--r--15_tests_subseq/test-subseq.c42
6 files changed, 186 insertions, 0 deletions
diff --git a/15_tests_subseq/README b/15_tests_subseq/README
new file mode 100644
index 0000000..9c98da7
--- /dev/null
+++ b/15_tests_subseq/README
@@ -0,0 +1,24 @@
+For this assignment, you will be writing testcases for
+your next assignment (as usual, the instructions for that assignment
+can be found in next-README).
+
+As usual, one correct and many broken implementations can be found
+in /usr/local/l2p/subseq.
+
+As with power, these are provided as compiled object files, and you
+should write a C program (in test-subseq.c) whose main function tests
+the maxSeq function. As before, it should exit with EXIT_SUCCESS if all
+tests pass, and EXIT_FAILURE if any test fails. Note that you will
+need to write the prototype for maxSeq:
+
+ size_t maxSeq(int * array, size_t n);
+
+in your test-subseq.c file, so that the compiler knows about the
+maxSeq function. The correct place to put it is after you #include
+any .h files you need, but before any other code you write.
+
+We have provided run_all.sh to help you run your test cases against
+all implementations.
+
+HINT: Think about how can you can vary not just the values in your array
+but the size as well. What about how the values change over time?
diff --git a/15_tests_subseq/grade.txt b/15_tests_subseq/grade.txt
new file mode 100644
index 0000000..37c5f52
--- /dev/null
+++ b/15_tests_subseq/grade.txt
@@ -0,0 +1,52 @@
+Grading at Thu 14 Oct 2021 02:32:07 AM UTC
+**Testing broken implementation 10 **
+-------------------------------------
+
+
+**Testing broken implementation 11 **
+-------------------------------------
+
+
+**Testing broken implementation 1 **
+-------------------------------------
+
+
+**Testing broken implementation 2 **
+-------------------------------------
+
+
+**Testing broken implementation 3 **
+-------------------------------------
+
+
+**Testing broken implementation 4 **
+-------------------------------------
+
+
+**Testing broken implementation 5 **
+-------------------------------------
+
+
+**Testing broken implementation 6 **
+-------------------------------------
+
+
+**Testing broken implementation 7 **
+-------------------------------------
+
+
+**Testing broken implementation 8 **
+-------------------------------------
+
+
+**Testing broken implementation 9 **
+-------------------------------------
+
+
+**Testing correct implementation **
+-------------------------------------
+
+
+All test programs were handled correctly
+
+Overall Grade: PASSED
diff --git a/15_tests_subseq/next-README b/15_tests_subseq/next-README
new file mode 100644
index 0000000..73a18f8
--- /dev/null
+++ b/15_tests_subseq/next-README
@@ -0,0 +1,31 @@
+
+ 1. Create a file called maxSeq.c and write the function:
+ size_t maxSeq(int * array, size_t n);
+
+ which returns the length of the maximum increasing contiguous
+ subsequence in the array. The parameter n specifies the length
+ of the array For example, if the array passed in were
+
+ { 1, 2, 1, 3, 5, 7, 2, 4, 6, 9}
+
+ this function would return 4 because the longest sequence
+ of (strictly) increasing numbers in that array is 1, 3, 5, 7
+ which has length 4. Note that 1,3,5,7,9 is an increasing
+ subsequence, but is not contiguous (finding discontiguous
+ ones efficiently takes techniques we haven't learned yet).
+
+ Note that the subseqence does not need to increase at a
+ constant rate (or follow any other pattern besides being strictly
+ increasing). 2, 4, 67, 93, 94, 102 would be a valid increasing
+ sequence of length 6.
+
+
+2. Compile and test your code using the test-subseq.c you wrote
+ previously. (as before, compile the .c files separately, and link
+ them together).
+
+3. Submit your code for maxSeq.c
+
+
+Hint:
+ Can you abstract a complex step out into a simple function? \ No newline at end of file
diff --git a/15_tests_subseq/run_all.sh b/15_tests_subseq/run_all.sh
new file mode 100755
index 0000000..33e763d
--- /dev/null
+++ b/15_tests_subseq/run_all.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+for i in /usr/local/l2p/subseq/subseq*.o
+do
+ test=`basename $i | sed 's/subseq//' | sed 's/.o//'`
+ if [ "$test" == "" ]
+ then
+ echo "**Testing correct implementation **"
+ else
+ echo "**Testing broken implementation ${test} **"
+ fi
+ echo "-------------------------------------"
+ echo ""
+
+ gcc -o test-subseq test-subseq.c $i
+ if [ "$?" != "0" ]
+ then
+ echo "Could not compile test-subseq.c with $i" > /dev/stderr
+ exit 1
+ fi
+ ./test-subseq
+ if [ "$?" != 0 ]
+ then
+ if [ "$test" == "" ]
+ then
+ echo "Your test program falsely failed the correct implementation!" > /dev/stderr
+ exit 1
+ fi
+ else
+ if [ "$test" != "" ]
+ then
+ echo "Your test program did not identify $i as broken!" > /dev/stderr
+ exit 1
+ fi
+ fi
+ echo ""
+done
diff --git a/15_tests_subseq/test-subseq b/15_tests_subseq/test-subseq
new file mode 100755
index 0000000..c1cc872
--- /dev/null
+++ b/15_tests_subseq/test-subseq
Binary files differ
diff --git a/15_tests_subseq/test-subseq.c b/15_tests_subseq/test-subseq.c
new file mode 100644
index 0000000..b239cc9
--- /dev/null
+++ b/15_tests_subseq/test-subseq.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+size_t maxSeq(int * array, size_t n);
+
+int main(void) {
+ if (maxSeq(NULL, 0)) {
+ return EXIT_FAILURE;
+ }
+
+ int array1[] = {1, 2, 3, 2};
+ int array2[] = {2, -3, 5, 6, 8};
+ int array3[] = {5};
+ int array4[] = {2, 4, 3, 6, 10, 15, -1, 7, 8, 2};
+ int array5[] = {-2};
+ int array6[] = {2,2,2,3};
+
+ if (maxSeq(array1, 0)) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array1, 4) != 3) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array2, 5) != 4) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array3, 1) != 1) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array4, 10) != 4) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array5, 1) != 1) {
+ return EXIT_FAILURE;
+ }
+ if (maxSeq(array6, 4) != 2) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}