trackler 2.2.1.86 → 2.2.1.87
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/reverse-string/metadata.yml +0 -1
- data/tracks/bash/CONTRIBUTING.md +129 -28
- data/tracks/bash/config/exercise_readme.go.tmpl +10 -4
- data/tracks/bash/exercises/acronym/README.md +8 -11
- data/tracks/bash/exercises/acronym/{acronym_tests.sh → acronym_test.sh} +0 -0
- data/tracks/bash/exercises/anagram/README.md +6 -1
- data/tracks/bash/exercises/anagram/anagram_test.sh +1 -1
- data/tracks/bash/exercises/armstrong-numbers/README.md +10 -2
- data/tracks/bash/exercises/atbash-cipher/README.md +6 -6
- data/tracks/bash/exercises/bob/README.md +8 -1
- data/tracks/bash/exercises/collatz-conjecture/README.md +11 -2
- data/tracks/bash/exercises/collatz-conjecture/{collatz_test.sh → collatz_conjecture_test.sh} +6 -6
- data/tracks/bash/exercises/difference-of-squares/README.md +6 -1
- data/tracks/bash/exercises/error-handling/README.md +13 -5
- data/tracks/bash/exercises/error-handling/error_handling_test.sh +18 -22
- data/tracks/bash/exercises/error-handling/example.sh +7 -6
- data/tracks/bash/exercises/gigasecond/.meta/hints.md +0 -5
- data/tracks/bash/exercises/gigasecond/README.md +36 -1
- data/tracks/bash/exercises/grains/README.md +10 -2
- data/tracks/bash/exercises/hamming/README.md +6 -1
- data/tracks/bash/exercises/hello-world/README.md +7 -2
- data/tracks/bash/exercises/leap/README.md +7 -2
- data/tracks/bash/exercises/luhn/README.md +7 -2
- data/tracks/bash/exercises/nucleotide-count/README.md +13 -22
- data/tracks/bash/exercises/pangram/README.md +7 -2
- data/tracks/bash/exercises/phone-number/README.md +10 -4
- data/tracks/bash/exercises/raindrops/README.md +6 -1
- data/tracks/bash/exercises/reverse-string/README.md +11 -2
- data/tracks/bash/exercises/rna-transcription/README.md +7 -2
- data/tracks/bash/exercises/roman-numerals/README.md +11 -2
- data/tracks/bash/exercises/triangle/README.md +5 -4
- data/tracks/bash/exercises/two-fer/README.md +7 -9
- data/tracks/bash/exercises/word-count/README.md +6 -2
- data/tracks/bash/exercises/word-count/example.sh +22 -13
- data/tracks/bash/scripts/canonical_data_check.sh +112 -0
- data/tracks/c/exercises/acronym/src/{example.h → acronym.h} +0 -0
- data/tracks/c/exercises/gigasecond/.meta/hints.md +124 -0
- data/tracks/c/exercises/gigasecond/README.md +126 -0
- data/tracks/c/exercises/isogram/src/{example.h → isogram.h} +0 -0
- data/tracks/c/exercises/meetup/.meta/hints.md +124 -0
- data/tracks/c/exercises/meetup/README.md +142 -12
- data/tracks/c/exercises/pangram/src/{example.h → pangram.h} +0 -0
- data/tracks/c/exercises/space-age/.meta/hints.md +124 -0
- data/tracks/c/exercises/space-age/README.md +127 -2
- data/tracks/elisp/bin/test-examples +11 -14
- data/tracks/elisp/config.json +9 -1
- data/tracks/elisp/exercises/acronym/README.md +13 -0
- data/tracks/elisp/exercises/acronym/acronym-test.el +28 -0
- data/tracks/elisp/exercises/acronym/acronym.el +11 -0
- data/tracks/elisp/exercises/acronym/example.el +14 -0
- data/tracks/elisp/exercises/bob/example.el +1 -3
- data/tracks/elisp/exercises/hamming/README.md +2 -0
- data/tracks/elisp/exercises/hamming/hamming-test.el +35 -12
- data/tracks/elisp/exercises/hamming/hamming.el +0 -3
- data/tracks/fsharp/exercises/custom-set/CustomSetTest.fs +206 -132
- data/tracks/fsharp/exercises/custom-set/Example.fs +2 -0
- data/tracks/fsharp/generators/Generators.fs +61 -0
- data/tracks/go/config.json +25 -2
- data/tracks/go/exercises/acronym/acronym_test.go +8 -0
- data/tracks/go/exercises/alphametics/.meta/gen.go +72 -0
- data/tracks/go/exercises/alphametics/.meta/hints.md +38 -0
- data/tracks/go/exercises/alphametics/README.md +93 -0
- data/tracks/go/exercises/alphametics/alphametics_test.go +33 -0
- data/tracks/go/exercises/alphametics/cases_test.go +59 -0
- data/tracks/go/exercises/alphametics/example.go +212 -0
- data/tracks/go/exercises/atbash-cipher/.meta/gen.go +6 -4
- data/tracks/go/exercises/atbash-cipher/cases_test.go +2 -2
- data/tracks/go/exercises/change/.meta/gen.go +7 -5
- data/tracks/go/exercises/change/cases_test.go +2 -2
- data/tracks/go/exercises/collatz-conjecture/.meta/gen.go +5 -3
- data/tracks/go/exercises/collatz-conjecture/cases_test.go +2 -2
- data/tracks/go/exercises/connect/.meta/gen.go +5 -3
- data/tracks/go/exercises/connect/cases_test.go +2 -2
- data/tracks/go/exercises/flatten-array/.meta/gen.go +5 -3
- data/tracks/go/exercises/flatten-array/cases_test.go +2 -2
- data/tracks/go/exercises/meetup/.meta/gen.go +19 -8
- data/tracks/go/exercises/meetup/cases_test.go +2 -2
- data/tracks/go/exercises/simple-linked-list/README.md +47 -0
- data/tracks/go/exercises/simple-linked-list/example.go +74 -0
- data/tracks/go/exercises/simple-linked-list/linked_list_test.go +210 -0
- data/tracks/idris/config.json +2 -2
- data/tracks/java/exercises/all-your-base/.meta/src/reference/java/BaseConverter.java +1 -5
- data/tracks/java/exercises/all-your-base/.meta/version +1 -1
- data/tracks/java/exercises/all-your-base/src/test/java/BaseConverterTest.java +34 -10
- data/tracks/java/exercises/bob/README.md +2 -0
- data/tracks/java/exercises/kindergarten-garden/.meta/version +1 -0
- data/tracks/java/exercises/kindergarten-garden/src/test/java/KindergartenGardenTest.java +0 -55
- data/tracks/java/exercises/meetup/.meta/version +1 -0
- data/tracks/java/exercises/meetup/src/test/java/MeetupTest.java +32 -0
- data/tracks/java/exercises/parallel-letter-frequency/README.md +1 -0
- data/tracks/java/exercises/proverb/README.md +16 -10
- data/tracks/java/exercises/rail-fence-cipher/README.md +5 -6
- data/tracks/java/exercises/two-fer/README.md +1 -1
- data/tracks/java/exercises/word-search/.meta/version +1 -1
- data/tracks/java/exercises/word-search/src/test/java/WordSearcherTest.java +240 -2
- data/tracks/javascript/.eslintignore +0 -1
- data/tracks/javascript/exercises/palindrome-products/example.js +3 -3
- data/tracks/kotlin/docs/INSTALLATION.md +77 -68
- data/tracks/kotlin/docs/TESTS.md +41 -39
- data/tracks/perl6/exercises/acronym/acronym.t +20 -8
- data/tracks/perl6/exercises/acronym/example.yaml +1 -1
- data/tracks/perl6/exercises/all-your-base/all-your-base.t +108 -66
- data/tracks/perl6/exercises/all-your-base/example.yaml +2 -2
- data/tracks/perl6/exercises/allergies/allergies.t +39 -15
- data/tracks/perl6/exercises/allergies/example.yaml +2 -2
- data/tracks/perl6/exercises/anagram/anagram.t +73 -40
- data/tracks/perl6/exercises/anagram/example.yaml +1 -1
- data/tracks/perl6/exercises/atbash-cipher/atbash-cipher.t +38 -15
- data/tracks/perl6/exercises/atbash-cipher/example.yaml +1 -1
- data/tracks/perl6/exercises/bob/bob.t +77 -27
- data/tracks/perl6/exercises/bob/example.yaml +1 -1
- data/tracks/perl6/exercises/flatten-array/example.yaml +1 -1
- data/tracks/perl6/exercises/flatten-array/flatten-array.t +20 -8
- data/tracks/perl6/exercises/luhn/example.yaml +1 -1
- data/tracks/perl6/exercises/luhn/luhn.t +42 -16
- data/tracks/perl6/exercises/roman-numerals/README.md +68 -0
- data/tracks/php/exercises/gigasecond/gigasecond_test.php +1 -1
- data/tracks/python/docs/ABOUT.md +2 -2
- metadata +27 -10
- data/tracks/bash/docs/EXERCISE_README_INSERT.md +0 -3
- data/tracks/bash/exercises/word-count/example.awk +0 -12
- data/tracks/java/exercises/alphametics/src/main/java/.keep +0 -0
@@ -17,9 +17,14 @@ Convert a number to a string, the contents of which depend on the number's facto
|
|
17
17
|
- 34 has four factors: 1, 2, 17, and 34.
|
18
18
|
- In raindrop-speak, this would be "34".
|
19
19
|
|
20
|
+
|
20
21
|
Run the tests with:
|
21
22
|
|
22
|
-
|
23
|
+
```bash
|
24
|
+
bats raindrops_test.sh
|
25
|
+
```
|
26
|
+
|
27
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
23
28
|
|
24
29
|
## Source
|
25
30
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Reverse String
|
1
|
+
# Reverse String
|
2
2
|
|
3
3
|
Reverse a string
|
4
4
|
|
@@ -6,9 +6,18 @@ For example:
|
|
6
6
|
input: "cool"
|
7
7
|
output: "looc"
|
8
8
|
|
9
|
+
|
10
|
+
Run the tests with:
|
11
|
+
|
12
|
+
```bash
|
13
|
+
bats reverse_string_test.sh
|
14
|
+
```
|
15
|
+
|
16
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
17
|
+
|
9
18
|
## Source
|
10
19
|
|
11
|
-
Introductory challenge to reverse an input string
|
20
|
+
Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
|
12
21
|
|
13
22
|
## Submitting Incomplete Solutions
|
14
23
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RNA Transcription
|
2
2
|
|
3
3
|
Given a DNA strand, return its RNA complement (per RNA transcription).
|
4
4
|
|
@@ -18,9 +18,14 @@ each nucleotide with its complement:
|
|
18
18
|
* `T` -> `A`
|
19
19
|
* `A` -> `U`
|
20
20
|
|
21
|
+
|
21
22
|
Run the tests with:
|
22
23
|
|
23
|
-
|
24
|
+
```bash
|
25
|
+
bats rna_transcription_test.sh
|
26
|
+
```
|
27
|
+
|
28
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
24
29
|
|
25
30
|
## Source
|
26
31
|
|
@@ -16,7 +16,7 @@ into stone tablets).
|
|
16
16
|
|
17
17
|
```text
|
18
18
|
1 => I
|
19
|
-
|
19
|
+
10 => X
|
20
20
|
7 => VII
|
21
21
|
```
|
22
22
|
|
@@ -42,9 +42,18 @@ In Roman numerals 1990 is MCMXC:
|
|
42
42
|
|
43
43
|
See also: http://www.novaroma.org/via_romana/numbers.html
|
44
44
|
|
45
|
+
|
46
|
+
Run the tests with:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
bats roman_numerals_test.sh
|
50
|
+
```
|
51
|
+
|
52
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
53
|
+
|
45
54
|
## Source
|
46
55
|
|
47
|
-
The Roman Numeral Kata
|
56
|
+
The Roman Numeral Kata [http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals](http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals)
|
48
57
|
|
49
58
|
## Submitting Incomplete Solutions
|
50
59
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -22,17 +22,18 @@ The case where the sum of the lengths of two sides _equals_ that of the
|
|
22
22
|
third is known as a _degenerate_ triangle - it has zero area and looks like
|
23
23
|
a single line. Feel free to add your own code/tests to check for degenerate triangles.
|
24
24
|
|
25
|
-
## Tests
|
26
25
|
|
27
26
|
Run the tests with:
|
28
27
|
|
29
28
|
```bash
|
30
|
-
|
29
|
+
bats triangle_test.sh
|
31
30
|
```
|
32
31
|
|
32
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
33
|
+
|
33
34
|
## Source
|
34
35
|
|
35
|
-
The
|
36
|
+
The Ruby Koans triangle project, parts 1 & 2 [http://rubykoans.com](http://rubykoans.com)
|
36
37
|
|
37
38
|
## Submitting Incomplete Solutions
|
38
|
-
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
39
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
|
4
4
|
|
5
|
-
```
|
5
|
+
```text
|
6
6
|
"One for X, one for me."
|
7
7
|
```
|
8
8
|
|
@@ -11,21 +11,19 @@ When X is a name or "you".
|
|
11
11
|
If the given name is "Alice", the result should be "One for Alice, one for me."
|
12
12
|
If no name is given, the result should be "One for you, one for me."
|
13
13
|
|
14
|
-
## Instructions
|
15
|
-
|
16
|
-
Submissions are encouraged to be general, within reason. Having said that, it's
|
17
|
-
also important not to over-engineer a solution.
|
18
14
|
|
19
|
-
It's important to remember that the goal is to make code as expressive and
|
20
|
-
readable as we can.
|
21
15
|
|
22
16
|
Run the tests with:
|
23
17
|
|
24
|
-
|
18
|
+
```bash
|
19
|
+
bats two_fer_test.sh
|
20
|
+
```
|
21
|
+
|
22
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
25
23
|
|
26
24
|
## Source
|
27
25
|
|
28
|
-
This is an exercise to introduce users to basic programming constructs, just after
|
26
|
+
This is an exercise to introduce users to basic programming constructs, just after Hello World. [https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)
|
29
27
|
|
30
28
|
## Submitting Incomplete Solutions
|
31
29
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -4,7 +4,7 @@ Given a phrase, count the occurrences of each word in that phrase.
|
|
4
4
|
|
5
5
|
For example for the input `"olly olly in come free"`
|
6
6
|
|
7
|
-
```
|
7
|
+
```text
|
8
8
|
olly: 2
|
9
9
|
in: 1
|
10
10
|
come: 1
|
@@ -14,7 +14,11 @@ free: 1
|
|
14
14
|
|
15
15
|
Run the tests with:
|
16
16
|
|
17
|
-
|
17
|
+
```bash
|
18
|
+
bats word_count_test.sh
|
19
|
+
```
|
20
|
+
|
21
|
+
After the first test(s) pass, continue by commenting out or removing the `skip` annotations prepending other tests.
|
18
22
|
|
19
23
|
## Source
|
20
24
|
|
@@ -1,21 +1,30 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
input="$1"
|
3
|
+
input="$1"
|
4
4
|
|
5
|
-
if [ ! -n "${input}" ]
|
5
|
+
if [[ ! -n "${input}" ]]
|
6
6
|
then
|
7
7
|
echo "Usage: $0 <input>"
|
8
|
-
exit
|
8
|
+
exit
|
9
9
|
fi
|
10
10
|
|
11
|
-
|
11
|
+
echo "$input" \
|
12
|
+
| tr '[:upper:]' '[:lower:]' \
|
13
|
+
| tr '.,:&@$%^!' ' ' \
|
14
|
+
| awk -f <(cat - <<-'HEREDOC'
|
15
|
+
{
|
16
|
+
for (field_index = 1; field_index <= NF; field_index++)
|
17
|
+
{
|
18
|
+
result[$field_index]++
|
19
|
+
}
|
20
|
+
}
|
21
|
+
END {
|
22
|
+
for (field_index in result)
|
23
|
+
{
|
24
|
+
printf "%s: %d\n", field_index, result[field_index]
|
25
|
+
}
|
26
|
+
}
|
27
|
+
HEREDOC
|
28
|
+
)
|
12
29
|
|
13
|
-
|
14
|
-
then
|
15
|
-
echo "Awk program file not found."
|
16
|
-
exit 1;
|
17
|
-
fi
|
18
|
-
|
19
|
-
echo "$input" | tr '[:upper:]' '[:lower:]' | tr '.,:&@$%^!' ' ' | awk -f "${awk_progfile}";
|
20
|
-
|
21
|
-
exit $?;
|
30
|
+
exit $?
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
print_usage() {
|
4
|
+
echo "Usage: ./canonical_data_check.sh -t path/to/track -s path/to/problem/specifications"
|
5
|
+
}
|
6
|
+
|
7
|
+
# Execution begins
|
8
|
+
|
9
|
+
command -v jq >/dev/null 2>&1 || {
|
10
|
+
echo >&2 "This script requires jq but it's not installed. Aborting."
|
11
|
+
exit 1
|
12
|
+
}
|
13
|
+
|
14
|
+
num_args=$#
|
15
|
+
|
16
|
+
if [ $num_args -eq 0 ]
|
17
|
+
then
|
18
|
+
print_usage
|
19
|
+
exit 0
|
20
|
+
fi
|
21
|
+
|
22
|
+
path_to_track=
|
23
|
+
path_to_problem_specifications=
|
24
|
+
|
25
|
+
while getopts ":t:s:" option
|
26
|
+
do
|
27
|
+
case "$option" in
|
28
|
+
"t")
|
29
|
+
path_to_track="$OPTARG"
|
30
|
+
;;
|
31
|
+
"s")
|
32
|
+
path_to_problem_specifications="$OPTARG"
|
33
|
+
;;
|
34
|
+
*)
|
35
|
+
echo "Unrecognized option. Aborting."
|
36
|
+
print_usage
|
37
|
+
exit 1
|
38
|
+
;;
|
39
|
+
esac
|
40
|
+
done
|
41
|
+
|
42
|
+
if [ -z "$path_to_track" ]
|
43
|
+
then
|
44
|
+
echo "Path to track missing."
|
45
|
+
print_usage
|
46
|
+
exit 1
|
47
|
+
fi
|
48
|
+
|
49
|
+
if [ -z "$path_to_problem_specifications" ]
|
50
|
+
then
|
51
|
+
echo "Path to problem specifications missing."
|
52
|
+
print_usage
|
53
|
+
exit 1
|
54
|
+
fi
|
55
|
+
|
56
|
+
config_file_path="$path_to_track/config.json"
|
57
|
+
|
58
|
+
if ! [ -f "$config_file_path" ]
|
59
|
+
then
|
60
|
+
echo "Config file not found at $config_file_path."
|
61
|
+
exit 1
|
62
|
+
fi
|
63
|
+
|
64
|
+
track_exercise_slugs=$(jq '.exercises[] | select(has("deprecated") | not) | .slug' $config_file_path | tr -d "\"")
|
65
|
+
update_needed_count=0
|
66
|
+
|
67
|
+
for slug in $track_exercise_slugs
|
68
|
+
do
|
69
|
+
canonical_data_folder_path="$path_to_problem_specifications/exercises/$slug"
|
70
|
+
|
71
|
+
if ! [ -d "$canonical_data_folder_path" ]
|
72
|
+
then
|
73
|
+
echo "Canonical data folder $canonical_data_folder_path not found. Aborting."
|
74
|
+
exit 1
|
75
|
+
fi
|
76
|
+
|
77
|
+
canonical_data_file_path="$canonical_data_folder_path/canonical-data.json"
|
78
|
+
|
79
|
+
if ! [ -f "$canonical_data_file_path" ]
|
80
|
+
then
|
81
|
+
# echo "$slug: no canonical data found."
|
82
|
+
continue
|
83
|
+
fi
|
84
|
+
|
85
|
+
canonical_data_version=$(jq '.version' $canonical_data_file_path | tr -d "\"")
|
86
|
+
|
87
|
+
track_exercise_version_file_path="$path_to_track/exercises/$slug/.meta/version"
|
88
|
+
|
89
|
+
if ! [ -f "$track_exercise_version_file_path" ]
|
90
|
+
then
|
91
|
+
echo "$slug: needs update or version file (v$canonical_data_version)."
|
92
|
+
update_needed_count=$((update_needed_count + 1))
|
93
|
+
continue
|
94
|
+
fi
|
95
|
+
|
96
|
+
track_data_version=$(cat $track_exercise_version_file_path)
|
97
|
+
|
98
|
+
if [ "$track_data_version" = "$canonical_data_version" ]
|
99
|
+
then
|
100
|
+
# echo "$slug: up-to-date."
|
101
|
+
continue
|
102
|
+
else
|
103
|
+
update_needed_count=$((update_needed_count + 1))
|
104
|
+
echo "$slug: needs update (v$track_data_version -> v$canonical_data_version)."
|
105
|
+
fi
|
106
|
+
|
107
|
+
done
|
108
|
+
|
109
|
+
if [ $update_needed_count -eq 0 ]
|
110
|
+
then
|
111
|
+
echo "All exercises are up to date!"
|
112
|
+
fi
|
File without changes
|
@@ -0,0 +1,124 @@
|
|
1
|
+
## Exercises without stub implementations
|
2
|
+
|
3
|
+
Like the majority of C programs you will write, this exercise comes without any header file (`*.h`) or source file (`*.c`).
|
4
|
+
|
5
|
+
|
6
|
+
### Add the required files
|
7
|
+
|
8
|
+
You will need to create these yourself as part of the exercise.
|
9
|
+
This is so that you get to practice deciding on and creating the program's interface yourself, which is an important part of programming in C.
|
10
|
+
It does mean that when you first try to run the tests, they won't compile.
|
11
|
+
They will give you an error similar to:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
make: *** No rule to make target 'src/exercise_name.c', needed by 'tests.out'. Stop.
|
15
|
+
```
|
16
|
+
|
17
|
+
This error occurs because the `makefile` attempts to use a file that hasn't been created yet (`exercise_name.c`).
|
18
|
+
To resolve this error you will need to add a matching file to the `src` directory.
|
19
|
+
For example, for the error above you would add a file called `exercise_name.c`.
|
20
|
+
|
21
|
+
When you try to run the tests again you will get a slightly different error.
|
22
|
+
|
23
|
+
```bash
|
24
|
+
make: *** No rule to make target 'src/exercise_name.h', needed by 'tests.out'. Stop.
|
25
|
+
```
|
26
|
+
|
27
|
+
Again the `makefile` still needs another file that has yet to be created (`exercise_name.h`).
|
28
|
+
The solution to this error is similar to the last, add the matching file to the `src` directory.
|
29
|
+
For example, for the above error you would add a file called `exercise_name.h`
|
30
|
+
|
31
|
+
|
32
|
+
### Add the required declarations
|
33
|
+
|
34
|
+
Running the tests a third time you see you will get new errors, similar to:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
Compiling tests.out
|
38
|
+
src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic]
|
39
|
+
cc1: all warnings being treated as errors
|
40
|
+
test/test_exercise_name.c:13:1: error: unknown type name ‘bar_t’; did you mean ‘__bar_t’?
|
41
|
+
bar_t b = foo(a, 2.5);
|
42
|
+
^~~~~~
|
43
|
+
__bar_t
|
44
|
+
test/test_exercise_name.c:15:14: error: storage size of fizz isn’t known
|
45
|
+
struct baz fizz;
|
46
|
+
^~~~
|
47
|
+
test/test_exercise_name.c:29:20: error: implicit declaration of function ‘foo’ [-Werror=implicit-function-declaration]
|
48
|
+
bar_t b = foo_function(fizz, 2.5);
|
49
|
+
```
|
50
|
+
|
51
|
+
This error means that you need to add function, type and variable decarations to the header file to match those the test file is attempting to use.
|
52
|
+
In doing this you will need to look at the build errors and the test code to determine what needs to be declared in the header file.
|
53
|
+
|
54
|
+
For example, for the error above you should declare a type named `bar_t`, a `struct` called `baz` and a function named `foo()`.
|
55
|
+
Additionally we can tell from looking at the above errors that function `foo()` has two parameters.
|
56
|
+
|
57
|
+
The first parameter is passed an argument of `fizz` and thus should have a type of `struct baz`.
|
58
|
+
The second parameter is passed `2.5` and so could have one of two types, either `float` or `double`.
|
59
|
+
You will need to look at the test code to determine which.
|
60
|
+
|
61
|
+
The _names_ of the parameters are not determined by the test code and so are left up to you to decide, though in keeping with C programming practices they should be descriptive but not overly long.
|
62
|
+
|
63
|
+
Further, we can see that the the return type expected by the test code is of the type `bar_t`.
|
64
|
+
|
65
|
+
Putting this all together we end up with a function declaration that looks like the following:
|
66
|
+
|
67
|
+
```c
|
68
|
+
// The parameter names are not very good here they should be more descriptive in a real exercise.
|
69
|
+
// We have decide on a double for the second parameter in this hypothetical example.
|
70
|
+
bar_t foo(struct baz b, double d);
|
71
|
+
```
|
72
|
+
|
73
|
+
You should continue to do this for any further similar errors.
|
74
|
+
To check that you have correctly determined the required declaration, just run the tests again and analyse any errors similarly.
|
75
|
+
|
76
|
+
Additionally, remember to add any includes to the header file any headers that it itself requires.
|
77
|
+
|
78
|
+
|
79
|
+
### Include guards
|
80
|
+
|
81
|
+
Before you are finished with the header file, you should add include guards.
|
82
|
+
Include guards are used to help prevent the file from being included multiple times by accident.
|
83
|
+
If the file _was_ included multiple times then the functions and other items would be declared twice; In C this is an error because the compiler thinks you are trying to declare another _different_ function that has the same name.
|
84
|
+
|
85
|
+
To add include guards, add something similar to the following as the first two lines of the header:
|
86
|
+
|
87
|
+
```c
|
88
|
+
#ifndef EXERCISE_NAME_H
|
89
|
+
#define EXERCISE_NAME_H
|
90
|
+
```
|
91
|
+
|
92
|
+
And on the very last line:
|
93
|
+
|
94
|
+
```c
|
95
|
+
#endif
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
### Add the required definitions
|
100
|
+
|
101
|
+
Once the header file is complete you may still have build errors similar to the following:
|
102
|
+
|
103
|
+
```bash
|
104
|
+
Compiling tests.out
|
105
|
+
src/exercise_name.c:1:0: error: ISO C forbids an empty translation unit [-Werror=pedantic]
|
106
|
+
cc1: all warnings being treated as errors
|
107
|
+
makefile:24: recipe for target 'tests.out' failed
|
108
|
+
make: *** [tests.out] Error 1
|
109
|
+
```
|
110
|
+
|
111
|
+
This is because although you have _declared_ all the items you need to, they have not yet been _defined_.
|
112
|
+
To define the needed items you need to add their implementation to the `exercise_name.c` file.
|
113
|
+
For the function `foo()` from the previous example, this would look similar to:
|
114
|
+
|
115
|
+
```c
|
116
|
+
#include "exercise_name.h"
|
117
|
+
|
118
|
+
bar_t foo(struct baz b, double d)
|
119
|
+
{
|
120
|
+
// Your exercise code here
|
121
|
+
}
|
122
|
+
```
|
123
|
+
|
124
|
+
After having resolved these errors you should be ready to start making the tests pass!
|