Skip to content

Commit 6bb3da0

Browse files
committed
Setup of Boost Test Suites and first koans
Decided to use Boost.Test for the realization of the koans. Also added the first koans dealing with integer values. Configuration for compilation is done with CMake.
1 parent 70c6385 commit 6bb3da0

7 files changed

+184
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*~
2+
build/
23

34
# Compiled Object files
45
*.slo

CMakeLists.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# CMakeLists.txt
2+
3+
cmake_minimum_required(VERSION 2.8)
4+
5+
project(CppKoans)
6+
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
7+
8+
add_definitions(
9+
-std=c++0x -g -O0
10+
)
11+
12+
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
13+
14+
set(cppkoans_SOURCES
15+
${PROJECT_SOURCE_DIR}/cppkoans.cpp
16+
${PROJECT_SOURCE_DIR}/helper.hpp
17+
)
18+
19+
add_subdirectory(koans)
20+
21+
include_directories(
22+
${Boost_INCLUDE_DIR}
23+
)
24+
25+
add_executable(CppKoans
26+
${cppkoans_SOURCES}
27+
)
28+
29+
target_link_libraries(CppKoans
30+
${Boost_LIBRARIES}
31+
)

cppkoans.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
*
3+
*/
4+
5+
#define BOOST_TEST_DYN_LINK
6+
#define BOOST_TEST_MODULE CppKoans
7+
#include <boost/test/unit_test.hpp>
8+
#include "helper.hpp"
9+
10+
BOOST_GLOBAL_FIXTURE( KoansConfig );
11+
12+
BOOST_AUTO_TEST_SUITE( dont_be_afraid )
13+
// defined in koans/00_the_start.cpp
14+
BOOST_AUTO_TEST_SUITE_END() // End of dont_be_afraid
15+
16+
BOOST_AUTO_TEST_SUITE( variable_types )
17+
// defined in koans/01_variable_types.cpp
18+
BOOST_AUTO_TEST_SUITE_END() // End of variable_types

helper.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
*
3+
*/
4+
5+
#include <boost/test/unit_test.hpp>
6+
7+
struct KoansConfig {
8+
KoansConfig() {
9+
boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
10+
}
11+
~KoansConfig() {}
12+
};
13+
14+
#define FILL_THE_NUMBER_IN 1

koans/00_the_start.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
*
3+
*/
4+
5+
#define BOOST_TEST_DYN_LINK
6+
#include "../helper.hpp"
7+
#include <boost/test/unit_test.hpp>
8+
9+
BOOST_AUTO_TEST_SUITE( dont_be_afraid )
10+
11+
BOOST_AUTO_TEST_CASE( cpp_is_not_too_hard )
12+
{
13+
BOOST_TEST_MESSAGE( "C++ is not too hard to learn!" );
14+
BOOST_TEST_MESSAGE( "Read the output of 'CppKoans' after you compiled it." );
15+
BOOST_TEST_MESSAGE( "Then go to the source file of the first error." );
16+
BOOST_TEST_MESSAGE( "And make the test pass." );
17+
BOOST_TEST_MESSAGE( "We start right here:" );
18+
BOOST_CHECK( false );
19+
BOOST_CHECK_MESSAGE( false, "That was easy, wasn't it?" );
20+
BOOST_TEST_MESSAGE( "Go on while you walk the path to enlightment ..." );
21+
}
22+
23+
BOOST_AUTO_TEST_SUITE_END() // End of dont_be_afraid
24+
25+
// EOF

koans/01_variable_types.cpp

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
*
3+
*/
4+
5+
#define BOOST_TEST_DYN_LINK
6+
#include "../helper.hpp"
7+
#include <boost/test/unit_test.hpp>
8+
9+
BOOST_AUTO_TEST_SUITE( variable_types )
10+
11+
12+
BOOST_AUTO_TEST_SUITE( integers_are_standard )
13+
14+
BOOST_AUTO_TEST_CASE( simple_integer_numbers )
15+
{
16+
int an_integer = 42;
17+
// You should replace 'FILL_THE_NUMBER_IN' with the propper value to satisfy the equation
18+
BOOST_CHECK_MESSAGE( an_integer == FILL_THE_NUMBER_IN, "This equality should be satisfied." );
19+
}
20+
21+
BOOST_AUTO_TEST_CASE( integers_have_a_size )
22+
{
23+
int an_integer = 1;
24+
BOOST_CHECK_MESSAGE( sizeof( int ) == FILL_THE_NUMBER_IN, "How big is an integer?" );
25+
BOOST_CHECK_MESSAGE( sizeof( an_integer ) == FILL_THE_NUMBER_IN, "How big is an_integer?" );
26+
}
27+
28+
BOOST_AUTO_TEST_CASE( integers_can_be_negative )
29+
{
30+
int an_integer = 42;
31+
int another_integer = -42;
32+
BOOST_CHECK_MESSAGE( an_integer < another_integer, "Which is bigger?" );
33+
}
34+
35+
BOOST_AUTO_TEST_SUITE_END() // End of integers_are_standard
36+
37+
38+
BOOST_AUTO_TEST_SUITE( floating_points )
39+
40+
BOOST_AUTO_TEST_CASE( simple_floats )
41+
{
42+
float a_float = 4.2;
43+
BOOST_CHECK_MESSAGE( a_float == FILL_THE_NUMBER_IN, "This equality should be satisfied." );
44+
}
45+
46+
BOOST_AUTO_TEST_CASE( floats_have_a_size )
47+
{
48+
int a_float = 4.2;
49+
BOOST_CHECK_MESSAGE( sizeof( float ) == FILL_THE_NUMBER_IN, "How big is a float?" );
50+
BOOST_CHECK_MESSAGE( sizeof( a_float ) == FILL_THE_NUMBER_IN, "How big is a_float?" );
51+
}
52+
53+
BOOST_AUTO_TEST_SUITE_END() // End of floating_points
54+
55+
56+
BOOST_AUTO_TEST_SUITE( bigger_numbers )
57+
58+
BOOST_AUTO_TEST_CASE( going_double_precision ) {
59+
60+
}
61+
62+
BOOST_AUTO_TEST_CASE( doubles_have_a_size )
63+
{
64+
int a_double = 4.2;
65+
BOOST_CHECK_MESSAGE( sizeof( double ) == FILL_THE_NUMBER_IN, "How big is a double?" );
66+
BOOST_CHECK_MESSAGE( sizeof( a_double ) == FILL_THE_NUMBER_IN, "How big is a_double?" );
67+
}
68+
69+
BOOST_AUTO_TEST_SUITE_END() // End of bigger_numbers
70+
71+
72+
BOOST_AUTO_TEST_SUITE( going_even_bigger )
73+
74+
BOOST_AUTO_TEST_CASE( size_of_biggest_number )
75+
{
76+
BOOST_TEST_MESSAGE("The size of long doubles vary from system to system.");
77+
long double a_long_double = 4.2;
78+
BOOST_CHECK_MESSAGE( sizeof( long double ) == FILL_THE_NUMBER_IN, "How big is a long double on your machine?" );
79+
BOOST_CHECK_MESSAGE( sizeof( a_long_double ) == FILL_THE_NUMBER_IN, "How big is a_long_double?" );
80+
}
81+
82+
BOOST_AUTO_TEST_SUITE_END() // End of going_even_bigger
83+
84+
85+
BOOST_AUTO_TEST_SUITE_END() // End of variable_types
86+
87+
// EOF

koans/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# koans/CMakeList.txt
2+
3+
set(cppkoans_SOURCES
4+
${cppkoans_SOURCES}
5+
${PROJECT_SOURCE_DIR}/koans/00_the_start.cpp
6+
${PROJECT_SOURCE_DIR}/koans/01_variable_types.cpp
7+
PARENT_SCOPE
8+
)

0 commit comments

Comments
 (0)