Skip to content

Commit de97abf

Browse files
authored
Merge pull request #11 from UMM-CSci-Systems/add-badges
Add badges and clean up GitHub Actions
2 parents 1357392 + 0915543 commit de97abf

File tree

6 files changed

+56
-23
lines changed

6 files changed

+56
-23
lines changed

.github/workflows/arraymerge_gtest.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
name: array-merge-gtest
22

3-
on: [push, pull_request]
4-
# paths:
5-
# - 'array_merge/**'
3+
# The `workflow_dispatch` lets us manually trigger this action
4+
# through the GitHub web interface. See
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
6+
# for more details.
7+
# We probably want to re-run the `array_merge` checks if the
8+
# definition of `mergesort` changes since this depends on that.
9+
on:
10+
push:
11+
paths:
12+
- 'array_merge/**'
13+
- 'mergesort/mergesort.[ch]'
14+
workflow_dispatch:
615

716
jobs:
817
build:
@@ -29,4 +38,3 @@ jobs:
2938
- name: Run test
3039
run: ./array_merge_test
3140
working-directory: array_merge
32-

.github/workflows/arraymerge_test_valgrind.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
name: array-merge-test-valgrind
22

3-
on: [push, pull_request]
4-
# paths:
5-
# - 'array_merge/**'
3+
# The `workflow_dispatch` lets us manually trigger this action
4+
# through the GitHub web interface. See
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
6+
# for more details.
7+
# We probably want to re-run the `array_merge` checks if the
8+
# definition of `mergesort` changes since this depends on that.
9+
on:
10+
push:
11+
paths:
12+
- 'array_merge/**'
13+
- 'mergesort/mergesort.[ch]'
14+
workflow_dispatch:
615

716
jobs:
817
build:

.github/workflows/mergesort_gtest.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: mergesort-gtest
22

3-
on: [push, pull_request]
4-
# paths:
5-
# - 'mergesort/**'
3+
# The `workflow_dispatch` lets us manually trigger this action
4+
# through the GitHub web interface. See
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
6+
# for more details.
7+
on:
8+
push:
9+
paths:
10+
- 'mergesort/**'
11+
workflow_dispatch:
612

713
jobs:
814
build:
@@ -29,4 +35,3 @@ jobs:
2935
- name: Run test
3036
run: ./mergesort_test
3137
working-directory: mergesort
32-

.github/workflows/mergesort_test_valgrind.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: mergesort-test-valgrind
22

3-
on: [push, pull_request]
4-
# paths:
5-
# - 'mergesort/**'
3+
# The `workflow_dispatch` lets us manually trigger this action
4+
# through the GitHub web interface. See
5+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
6+
# for more details.
7+
on:
8+
push:
9+
paths:
10+
- 'mergesort/**'
11+
workflow_dispatch:
612

713
jobs:
814
build:

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Background <!-- omit in toc -->
1+
# C and programming with dynamic arrays <!-- omit in toc -->
2+
3+
[![Mergesort tests](../../workflows/mergesort-gtest/badge.svg)](../../actions?query=workflow%3A"mergesort-gtest")
4+
[![Mergesort Valgrind](../../workflows/mergesort-test-valgrind/badge.svg)](../../actions?query=workflow%3A"mergesort-test-valgrind")
5+
[![Array merge tests](../../workflows/array-merge-gtest/badge.svg)](../../actions?query=workflow%3A"array-merge-gtest")
6+
[![Array merge Valgrind](../../workflows/array-merge-test-valgrind/badge.svg)](../../actions?query=workflow%3A"array-merge-test-valgrind")
27

38
This lab is a collection of several C programming exercises with an
49
emphasis on arrays, pointers, and memory management.
@@ -50,7 +55,7 @@ in the test code. If the test code calls some function `f()` that returns an
5055
array or string that is allocated somewhere in `f` (or a function `f` calls),
5156
then that memory is lost if the test code doesn't free up that returned array.
5257
So if `valgrind` says there's a leak where some memory is allocated in a function
53-
and then returned to the test code, then the fix is _in the test code_. In general
58+
and then returned to the test code, then the fix is *in the test code*. In general
5459
we don't encourage you to fiddle with the
5560
test code (you could always just change the test code to say everything
5661
passes!), but if the memory leaks to the test code, then that's where the
@@ -88,7 +93,7 @@ To compile the test code use the following:
8893
g++ -Wall -g -o foo_test foo.c foo_test.cpp -lgtest -pthread -std=c++0x
8994
```
9095

91-
_Notice that this uses `g++` instead of `gcc`._ This because the `gtest`
96+
*Notice that this uses `g++` instead of `gcc`.* This because the `gtest`
9297
is technically a C++ library, but it also works for "plain" C code, which
9398
is all we need it for here. The `-g` flag isn't strictly necessary; it
9499
causes a variety of useful debugging information to be included in
@@ -105,7 +110,7 @@ the `gtest` library (that's the `-l` part) when generating the executable.
105110
:bangbang: Remember: For each problem you should at a minimum
106111

107112
- Pass our tests, and
108-
- Have _no_ memory leaks, as confirmed by `valgrind`.
113+
- Have *no* memory leaks, as confirmed by `valgrind`.
109114
- Remove any print statements, comments, or other code that you used to debug your code before you turn it in.
110115

111116
Also, please don't lose your brains and forget good programming practices just because you're working in a new language. C can be quite difficult to read under the best of circumstances, and using miserable names like `res`, `res2`, and `res3` doesn't help. *Use functions* to break up complicated bits of logic; it's really not fun when a group turns in a solution that is one huge function, especially when there are several instances of repeated logic.
@@ -134,7 +139,7 @@ void mergesort(int size, int values[]);
134139
```
135140
136141
This is a
137-
_destructive_ sorting operation, i.e., it should alter the array that it's
142+
*destructive* sorting operation, i.e., it should alter the array that it's
138143
given by rearranging the elements in that that array. Note that since C
139144
doesn't know how large arrays are, we pass in
140145
the size as an argument.
@@ -156,7 +161,7 @@ as you certainly wouldn't want a common operation like sorting to leak a
156161
bunch of memory every time it's called. Again, `valgrind` should be your
157162
friend.
158163
159-
:bangbang: C does (now) support _dynamically_ allocate
164+
:bangbang: C does (now) support *dynamically* allocate
160165
arrays for local use without using `malloc` or `calloc`.
161166
For this lab **do not do that**.
162167
Make sure that in your recursive calls to `mergesort` that you use `calloc`
@@ -183,10 +188,10 @@ is the length of the corresponding sub-array in `values`. If
183188
`sizes[3]==10`, for example, then `values[3]` will be an array of 10
184189
integers.
185190

186-
_Note how inherently icky it is to have to pass all this bookkeeping
191+
*Note how inherently icky it is to have to pass all this bookkeeping
187192
information around, and how many wonderfully unpleasant errors can
188193
result from doing this incorrectly. It's a **lot** safer if arrays know
189-
how big they are._
194+
how big they are.*
190195

191196
`array_merge` should then generate a single sorted list (small to large) of the
192197
unique values (i.e., no duplicates) in `values`. Since we haven't yet

Tips_and_suggestions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Groups often have off-by-one errors where they weren't allocating
5959

6060
We have sometimes seen a subtle mistake where folks went through something like the following sequence of steps:
6161

62-
1. Dynamically allocate an array that was potentially empty (because _n=0_): `int *a = calloc(n, sizeof(int));`.
62+
1. Dynamically allocate an array that was potentially empty (because *n=0*): `int *a = calloc(n, sizeof(int));`.
6363
2. Copy some data into that array using a loop that (correctly) did nothing if *n=0*.
6464
3. Access the first item in the array, which might not actually be there, e.g., `int i = a[0];`.
6565
4. Protect the remainder of the code (through an `if` or loop with appropriate bounds) so that the value taken from the array was never *used* if n=0.

0 commit comments

Comments
 (0)