Skip to content

Commit d24245a

Browse files
committed
added sample koan episode and instructions on creating new koans
The sample koans episode and the instructions in README.markdown should describe the procedure of adding and creating new kaons and episodes sufficently.
1 parent eae962e commit d24245a

8 files changed

+264
-5
lines changed

README.markdown

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#CppKoans
22

33
Inspired by [RubyKoans](https://github.com/edgecase/ruby_koans) and
4-
[JavaScript-Koans](https://github.com/liammclennan/JavaScript-Koans), this is an attemt to write
5-
such koans for C/C++.
4+
[JavaScript-Koans](https://github.com/liammclennan/JavaScript-Koans), this is
5+
an attemt to write such koans for C/C++.
66

77
Some ideas were taken from [PointerKoans](https://github.com/paytonrules/PointerKoan).
88

@@ -39,7 +39,8 @@ I just tested it with a recent GCC.
3939
Now follow the instructions printed from the very beginning.
4040

4141
The files, you will need to edit are in `CppKoans/koans`.
42-
Each time you saved a file and want to rerun the koans, you need to compile it first.
42+
Each time you saved a file and want to rerun the koans, you need to compile it
43+
first.
4344
Thus, walking the path to enlightment is a repetition of these steps:
4445

4546
1. Edit and save a file in `CppKoans/koans`
@@ -49,6 +50,26 @@ Thus, walking the path to enlightment is a repetition of these steps:
4950
3. Read the master's reply with `./CppKoans/build/CppKoans`
5051

5152

53+
##Adding further Koans
54+
###To existing episodes
55+
Just define a new `private void` function without parameters in the bottom
56+
section of the episode's header file it should belong to.
57+
Then go to the implementation file of that episode and implement your new koan.
58+
Finally add your newly created koan to the `run()` function in the header file
59+
of that episode and increase the `num_tests` counter by one (or whatevery amount
60+
of koans you added).
61+
62+
###New episodes
63+
There is a sample episode, which can be used as a template for new episodes.
64+
After copying and renaming of `~/headers/koanXX_sample_koans.hpp` and
65+
`~/koans/koanXX_sample_koans.cpp` the following steps are necessary:
66+
67+
1. add the implementation file to `~/koans/CMakeLists.txt`
68+
69+
2. add the header file to `~/headers/all_koans.hpp`
70+
71+
3. enable and activate the new episode in `~/cppkoans.cpp`
72+
73+
5274
##Licence
53-
MIT License
54-
Copyright 2012 Torbjörn Klatt <opensource eht torbjoern minus klatt dot de>
75+
MIT License Copyright 2012 Torbjörn Klatt - opensource eht torbjoern minus klatt dot de

cppkoans.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ int main()
4848
// Koan 03: further types
4949
Koan03_further_types koan03 = Koan03_further_types( &status );
5050

51+
// Koan 04: arrays
52+
Koan04_arrays koan04 = Koan04_arrays( &status );
53+
54+
// Koan XX: sample koans
55+
// KoanXX_sample_koans koanXX = KoanXX_sample_koans( &status );
56+
5157
// Welcome message
5258
status.start();
5359

@@ -56,6 +62,8 @@ int main()
5662
koan01.run();
5763
koan02.run();
5864
koan03.run();
65+
koan04.run();
66+
// koanXX.run();
5967

6068
// Done.
6169
return( 0 );

headers/all_koans.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
#include "koan01_number_types.hpp"
2828
#include "koan02_character_types.hpp"
2929
#include "koan03_further_types.hpp"
30+
#include "koan04_arrays.hpp"
31+
// When an episode of koans is added, it must be appended here
32+
// #include "koanXX_sample_koans.hpp"
3033

3134
// EOF

headers/koan04_arrays.hpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright (c) 2012 Torbjörn Klatt <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#include "../helper.hpp"
27+
28+
#ifndef KOAN04_ARRAYS_HPP
29+
#define KOAN04_ARRAYS_HPP
30+
31+
class Koan04_arrays : Koan
32+
{
33+
private:
34+
KoanHandler *status; //!
35+
static const int num_tests = 1; //!
36+
37+
public:
38+
/**
39+
*
40+
*/
41+
Koan04_arrays( KoanHandler *status ) : status( status ) {
42+
status->register_koans( num_tests );
43+
}
44+
/**
45+
*
46+
*/
47+
~Koan04_arrays() {}
48+
49+
/**
50+
*
51+
*/
52+
void run() {
53+
status->eval_koan( *this, static_cast<void ( Koan:: * )()>( &Koan04_arrays::listing_things ) );
54+
55+
status->episode_done( "fourth" );
56+
}
57+
58+
/**
59+
*
60+
*/
61+
static int get_num_tests() {
62+
return num_tests;
63+
}
64+
65+
private:
66+
// REMARK: Do not forget to increase this.num_tests when you add another koan
67+
void listing_things();
68+
};
69+
70+
#endif // KOAN04_ARRAYS_HPP
71+
72+
// EOF

headers/koanXX_sample_koans.hpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright (c) 2012 Torbjörn Klatt <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#include "../helper.hpp"
27+
28+
// Do not to forget to rename the preprocessor directives as well!
29+
#ifndef KOANXX_SAMPLE_KOANS_HPP
30+
#define KOANXX_SAMPLE_KOANS_HPP
31+
32+
// Rename the Episode
33+
class KoanXX_sample_koans : Koan
34+
{
35+
private:
36+
KoanHandler *status; //!
37+
// When ever a koan is added at the very bottom, this counter needs to be
38+
// increased.
39+
static const int num_tests = 1; //!
40+
41+
public:
42+
/**
43+
*
44+
*/
45+
KoanXX_sample_koans( KoanHandler *status ) : status( status ) {
46+
status->register_koans( num_tests );
47+
}
48+
/**
49+
*
50+
*/
51+
~KoanXX_sample_koans() {}
52+
53+
/**
54+
*
55+
*/
56+
void run() {
57+
// For each koan in this episode, one line needs to be written.
58+
// The koans are executed in the order they are called here.
59+
status->eval_koan( *this, static_cast<void ( Koan:: * )()>( &KoanXX_sample_koans::a_sample_koan ) );
60+
61+
status->episode_done( "the-so-and-so'th" );
62+
}
63+
64+
/**
65+
*
66+
*/
67+
static int get_num_tests() {
68+
return num_tests;
69+
}
70+
71+
private:
72+
// Add further Koans down here by defining their name.
73+
// The implementation of these is done in ~/koans/koanXX_sample_koans.cpp
74+
// REMARK: Do not forget to increase this.num_tests when you add another koan
75+
void a_sample_koan();
76+
};
77+
78+
#endif // KOAN04_ARRAYS_HPP
79+
80+
// EOF

koans/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ set(cppkoans_SOURCES
66
${PROJECT_SOURCE_DIR}/koans/koan01_number_types.cpp
77
${PROJECT_SOURCE_DIR}/koans/koan02_character_types.cpp
88
${PROJECT_SOURCE_DIR}/koans/koan03_further_types.cpp
9+
${PROJECT_SOURCE_DIR}/koans/koan04_arrays.cpp
10+
# When an episode of koans is added, it must be appended here
11+
# ${PROJECT_SOURCE_DIR}/koans/koanXX_sample_koans.cpp
912
PARENT_SCOPE
1013
)

koans/koan04_arrays.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright (c) 2012 Torbjörn Klatt <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#include "../headers/koan04_arrays.hpp"
27+
28+
void Koan04_arrays::listing_things()
29+
{
30+
int two_numbers[] = { 3, 4 };
31+
// You should use two_numbers to retreive the value
32+
ASSERT_EQUAL( 3, FILL_THE_NUMBER_IN );
33+
}
34+
35+
// EOF

koans/koanXX_sample_koans.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright (c) 2012 Torbjörn Klatt <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person
5+
obtaining a copy of this software and associated documentation
6+
files (the "Software"), to deal in the Software without
7+
restriction, including without limitation the rights to use,
8+
copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following
11+
conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
#include "../headers/koanXX_sample_koans.hpp"
27+
28+
// The implementations of the different koans of this episode is done here.
29+
// Don't forget to rename the above include.
30+
31+
void KoanXX_sample_koans::a_sample_koan()
32+
{
33+
bool test = false;
34+
ASSERT_EQUAL( test, true );
35+
}
36+
37+
// EOF

0 commit comments

Comments
 (0)