Skip to content

Commit c1e0353

Browse files
committed
Add new integration tests to P0
1 parent dccf0ac commit c1e0353

File tree

9 files changed

+76
-28
lines changed

9 files changed

+76
-28
lines changed

grading/submissions/astudent/p0/main.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88

99
int main (int argc, char **argv)
1010
{
11-
// BEGIN_SOLUTION
12-
1311
const size_t BUFFER_SIZE = 4096;
1412
bool hello = true;
1513
bool goodbye = false;
14+
bool fact = false;
15+
char *fact_num = NULL;
1616
bool cat = false;
1717
char *cat_fn = NULL;
1818

1919
char c;
20-
while ((c = getopt(argc, argv, "gt:c:h:u:e:")) != -1) {
20+
while ((c = getopt(argc, argv, "gf:c:")) != -1) {
2121
switch (c) {
2222

23-
case 'g': goodbye = true; hello = false; break;
24-
case 'c': cat = true; hello = false; cat_fn = optarg; break;
23+
case 'g': goodbye = true; hello = false; break;
24+
case 'f': fact = true; hello = false; fact_num = optarg; break;
25+
case 'c': cat = true; hello = false; cat_fn = optarg; break;
2526

2627
default:
2728
printf("Invalid argument.\n");
@@ -36,6 +37,10 @@ int main (int argc, char **argv)
3637
printf("Goodbye!\n");
3738
}
3839

40+
if (fact) {
41+
printf("%d\n", factorial(strtol(fact_num, NULL, 10)));
42+
}
43+
3944
if (cat) {
4045
FILE *fin = fopen(cat_fn, "r");
4146
if (!fin) {
@@ -49,8 +54,6 @@ int main (int argc, char **argv)
4954
fclose(fin);
5055
}
5156

52-
// END_SOLUTION
53-
// BOILERPLATE: printf("Hello, CS 261!\n");
5457
return EXIT_SUCCESS;
5558
}
5659

grading/submissions/bstudent/p0/main.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88

99
int main (int argc, char **argv)
1010
{
11-
// BEGIN_SOLUTION
12-
1311
const size_t BUFFER_SIZE = 4096;
1412
bool hello = true;
1513
bool goodbye = false;
14+
bool fact = false;
15+
char *fact_num = NULL;
1616
bool cat = false;
1717
char *cat_fn = NULL;
1818

1919
char c;
20-
while ((c = getopt(argc, argv, "gt:c:h:u:e:")) != -1) {
20+
while ((c = getopt(argc, argv, "gf:c:")) != -1) {
2121
switch (c) {
2222

23-
case 'g': goodbye = true; hello = false; break;
24-
case 'c': cat = true; hello = false; cat_fn = optarg; break;
23+
case 'g': goodbye = true; hello = false; break;
24+
case 'f': fact = true; hello = false; fact_num = optarg; break;
25+
case 'c': cat = true; hello = false; cat_fn = optarg; break;
2526
}
2627
}
2728

@@ -32,6 +33,10 @@ int main (int argc, char **argv)
3233
printf("Goodbye!\n");
3334
}
3435

36+
if (fact) {
37+
printf("%d\n", factorial(strtol(fact_num, NULL, 10)));
38+
}
39+
3540
if (cat) {
3641
FILE *fin = fopen(cat_fn, "r");
3742
char buffer[BUFFER_SIZE];
@@ -41,8 +46,6 @@ int main (int argc, char **argv)
4146
fclose(fin);
4247
}
4348

44-
// END_SOLUTION
45-
// BOILERPLATE: printf("Hello, CS 261!\n");
4649
return EXIT_SUCCESS;
4750
}
4851

ref/p0-intro/main.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ int main (int argc, char **argv)
1313
const size_t BUFFER_SIZE = 4096;
1414
bool hello = true;
1515
bool goodbye = false;
16+
bool fact = false;
17+
char *fact_num = NULL;
1618
bool cat = false;
1719
char *cat_fn = NULL;
1820

1921
char c;
20-
while ((c = getopt(argc, argv, "gt:c:h:u:e:")) != -1) {
22+
while ((c = getopt(argc, argv, "gf:c:")) != -1) {
2123
switch (c) {
2224

23-
case 'g': goodbye = true; hello = false; break;
24-
case 'c': cat = true; hello = false; cat_fn = optarg; break;
25+
case 'g': goodbye = true; hello = false; break;
26+
case 'f': fact = true; hello = false; fact_num = optarg; break;
27+
case 'c': cat = true; hello = false; cat_fn = optarg; break;
2528

2629
default:
2730
printf("Invalid argument.\n");
@@ -36,6 +39,10 @@ int main (int argc, char **argv)
3639
printf("Goodbye!\n");
3740
}
3841

42+
if (fact) {
43+
printf("%d\n", factorial(strtol(fact_num, NULL, 10)));
44+
}
45+
3946
if (cat) {
4047
FILE *fin = fopen(cat_fn, "r");
4148
if (!fin) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invalid argument.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24

ref/p0-intro/tests/itests.include

+3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
run_test D_hello ""
77
run_test C_goodbye "-g"
8+
run_test B_fact "-f 4"
89
run_test B_cat "-c inputs/B_cat.txt"
910
run_test A_invalid_arg "-z"
11+
run_test A_fact_no_number "-f"
12+
run_test A_fact_letters "-f asdf"
1013
run_test A_cat_no_filename "-c"
1114
run_test A_cat_file_noexist "-c inputs/A_noexist.txt"

ref/p0-intro/tests/regen_expected.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
EXE="../intro"
4+
5+
function run_test {
6+
7+
# parameters
8+
TAG=$1
9+
ARGS=$2
10+
11+
# file paths
12+
EXPECT=expected/$TAG.txt
13+
14+
# run test
15+
$EXE $ARGS 2>/dev/null >"$EXPECT"
16+
}
17+
18+
# initialize output folders
19+
mkdir -p expected
20+
rm -f expected/*
21+
22+
# run individual tests
23+
source itests.include
24+

www/p0-intro.html

+16-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2>Project 0: Intro project</h2>
2626

2727
<h3>Regular Requirements</h3>
2828

29-
<p> These sections describe what you must do to receive credit for "completing"
29+
<p> These sections describe what you must do to receive credit for completing
3030
P0. </p>
3131

3232
<h4>Unit Requirements</h4>
@@ -82,6 +82,10 @@ <h4>Integration Requirements</h4>
8282
<li> Goodbye mode ("<tt>-g</tt>") <br />
8383
<br /> Print "<tt>Goodbye!</tt>" </li>
8484

85+
<li> Factorial mode ("<tt>-f &lt;n&gt;</tt>") <br />
86+
<br /> Print the factorial of the given number, using the
87+
<tt>factorial</tt> function described in the previous section. </li>
88+
8589
<li> Cat mode ("<tt>-c &lt;file&gt;</tt>") <br />
8690
<br /> Print each line from the given file to standard out, similar to
8791
the Unix <tt>cat</tt> utility. </li>
@@ -108,10 +112,13 @@ <h4>Testing</h4>
108112
Private:A_sumarray_null_pointer:0: Assertion 'sum_array(((void *)0), 0) == 0' failed: sum_array(((void *)0), 0) == -1, 0 == 0
109113
========================================
110114
INTEGRATION TESTS
111-
C_hello FAIL (see outputs/C_hello.diff for details)
115+
D_hello FAIL (see outputs/D_hello.diff for details)
112116
C_goodbye FAIL (see outputs/C_goodbye.diff for details)
117+
B_fact FAIL (see outputs/B_fact.diff for details)
113118
B_cat FAIL (see outputs/B_cat.diff for details)
114119
A_invalid_arg FAIL (see outputs/A_invalid_arg.diff for details)
120+
A_fact_no_number FAIL (see outputs/A_fact_no_number.diff for details)
121+
A_fact_letters FAIL (see outputs/A_fact_letters.diff for details)
115122
A_cat_no_filename FAIL (see outputs/A_cat_no_filename.diff for details)
116123
A_cat_file_noexist FAIL (see outputs/A_cat_file_noexist.diff for details)
117124
No memory leak found.
@@ -126,10 +133,13 @@ <h4>Testing</h4>
126133
100%: Checks: 8, Failures: 0, Errors: 0
127134
========================================
128135
INTEGRATION TESTS
129-
C_hello pass
136+
D_hello pass
130137
C_goodbye pass
138+
B_fact pass
131139
B_cat pass
132140
A_invalid_arg pass
141+
A_fact_no_number pass
142+
A_fact_letters pass
133143
A_cat_no_filename pass
134144
A_cat_file_noexist pass
135145
No memory leak found.
@@ -139,16 +149,11 @@ <h4>Testing</h4>
139149
<p> You should of course write your own tests as well. You should use the
140150
provided tests only as an indicator of how complete your solution is. </p>
141151

142-
<p> Note that in this project, the "integration" tests don't really test for
143-
successful integration of smaller program units; they test entirely separate
152+
<p> Note that in this project, some of the "integration" tests don't really test
153+
for successful integration of smaller program units; they test entirely separate
144154
functionality. This will not be the case in the rest of the projects. </p>
145155

146-
147-
<p> Copyright &copy; 2018 Mike Lam
148-
<a href="https://validator.w3.org/check?uri=referer">
149-
<img style="margin: 0 0 -3px 10px;" src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="15" width="50" />
150-
</a>
151-
</p>
156+
<p> Copyright &copy; 2018 Mike Lam </p>
152157

153158
</div>
154159

0 commit comments

Comments
 (0)