trackler 2.1.0.0 → 2.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/exercises/connect/description.md +2 -1
- data/common/exercises/crypto-square/canonical-data.json +2 -2
- data/common/exercises/two-bucket/canonical-data.json +27 -1
- data/lib/trackler/version.rb +1 -1
- data/tracks/c/exercises/perfect-numbers/src/example.c +8 -4
- data/tracks/clojure/config.json +5 -0
- data/tracks/clojure/exercises/secret-handshake/project.clj +4 -0
- data/tracks/clojure/exercises/secret-handshake/src/example.clj +19 -0
- data/tracks/clojure/exercises/secret-handshake/test/secret_handshake_test.clj +55 -0
- data/tracks/cpp/.travis.yml +4 -3
- data/tracks/cpp/README.md +1 -1
- data/tracks/cpp/config.json +171 -67
- data/tracks/cpp/docs/ABOUT.md +2 -2
- data/tracks/cpp/docs/INSTALLATION.md +22 -28
- data/tracks/cpp/docs/TESTS.md +1 -1
- data/tracks/cpp/exercises/anagram/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/beer-song/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/binary/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/bob/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/clock/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/clock/clock_test.cpp +188 -64
- data/tracks/cpp/exercises/clock/example.cpp +17 -12
- data/tracks/cpp/exercises/clock/example.h +1 -0
- data/tracks/cpp/exercises/crypto-square/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/difference-of-squares/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/etl/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/etl/etl_test.cpp +5 -5
- data/tracks/cpp/exercises/food-chain/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/gigasecond/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/gigasecond/example.cpp +2 -6
- data/tracks/cpp/exercises/gigasecond/example.h +2 -2
- data/tracks/cpp/exercises/gigasecond/gigasecond_test.cpp +26 -8
- data/tracks/cpp/exercises/grade-school/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/grade-school/grade_school_test.cpp +5 -6
- data/tracks/cpp/exercises/grains/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hamming/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hello-world/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/hexadecimal/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/leap/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/meetup/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/meetup/meetup_test.cpp +1 -1
- data/tracks/cpp/exercises/nth-prime/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/nucleotide-count/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/nucleotide-count/nucleotide_count_test.cpp +3 -4
- data/tracks/cpp/exercises/phone-number/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/prime-factors/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/queen-attack/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/raindrops/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/rna-transcription/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/robot-name/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/roman-numerals/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/say/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/scrabble-score/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/series/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/series/series_test.cpp +11 -11
- data/tracks/cpp/exercises/sieve/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/space-age/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/sum-of-multiples/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/triangle/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/trinary/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/word-count/CMakeLists.txt +2 -9
- data/tracks/cpp/exercises/word-count/word_count_test.cpp +14 -15
- data/tracks/go/README.md +27 -13
- data/tracks/go/config.json +1 -0
- data/tracks/go/exercises/connect/.meta/gen.go +1 -3
- data/tracks/go/exercises/connect/cases_test.go +2 -1
- data/tracks/go/exercises/custom-set/.meta/gen.go +122 -101
- data/tracks/go/exercises/custom-set/cases_test.go +13 -4
- data/tracks/go/exercises/custom-set/custom_set_test.go +2 -2
- data/tracks/go/exercises/hamming/.meta/gen.go +1 -3
- data/tracks/go/exercises/hamming/cases_test.go +7 -1
- data/tracks/go/exercises/hamming/example.go +1 -1
- data/tracks/go/exercises/hamming/hamming_test.go +1 -1
- data/tracks/go/exercises/hello-world/{hello_example_test.go → example_helloworld_test.go} +0 -0
- data/tracks/go/exercises/house/house_test.go +8 -8
- data/tracks/go/exercises/meetup/.meta/gen.go +1 -3
- data/tracks/go/exercises/meetup/cases_test.go +2 -1
- data/tracks/go/exercises/palindrome-products/example.go +1 -1
- data/tracks/go/exercises/palindrome-products/palindrome_products_test.go +1 -1
- data/tracks/go/exercises/pascals-triangle/pascals_triangle_test.go +24 -4
- data/tracks/go/exercises/rna-transcription/.meta/gen.go +1 -3
- data/tracks/go/exercises/rna-transcription/cases_test.go +2 -1
- data/tracks/go/exercises/roman-numerals/.meta/gen.go +1 -3
- data/tracks/go/exercises/roman-numerals/cases_test.go +2 -1
- data/tracks/go/exercises/roman-numerals/example.go +1 -1
- data/tracks/go/exercises/transpose/.meta/gen.go +1 -3
- data/tracks/go/exercises/transpose/cases_test.go +2 -1
- data/tracks/go/exercises/transpose/transpose_test.go +5 -0
- data/tracks/go/exercises/word-count/.meta/gen.go +1 -3
- data/tracks/go/exercises/word-count/cases_test.go +2 -1
- data/tracks/go/gen/gen.go +3 -2
- data/tracks/java/config.json +5 -0
- data/tracks/java/exercises/saddle-points/build.gradle +17 -0
- data/tracks/java/exercises/saddle-points/src/example/java/Matrix.java +44 -0
- data/tracks/java/exercises/saddle-points/src/example/java/MatrixCoordinate.java +31 -0
- data/tracks/java/exercises/saddle-points/src/main/java/Matrix.java +5 -0
- data/tracks/java/exercises/saddle-points/src/main/java/MatrixCoordinate.java +31 -0
- data/tracks/java/exercises/saddle-points/src/test/java/MatrixTest.java +82 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/javascript/.travis.yml +3 -1
- data/tracks/javascript/Makefile +2 -8
- data/tracks/javascript/SETUP.md +1 -2
- data/tracks/javascript/docs/INSTALLATION.md +3 -4
- data/tracks/javascript/docs/TESTS.md +14 -26
- data/tracks/javascript/exercises/hamming/example.js +7 -11
- data/tracks/javascript/exercises/hello-world/HINTS.md +3 -3
- data/tracks/javascript/exercises/robot-simulator/example.js +72 -73
- data/tracks/perl6/config.json +5 -0
- data/tracks/perl6/exercises/clock/Clock.pm6 +4 -0
- data/tracks/perl6/exercises/clock/Example.pm6 +12 -0
- data/tracks/perl6/exercises/clock/clock.t +534 -0
- data/tracks/perl6/exercises/clock/example.yaml +16 -0
- data/tracks/perl6/exercises/robot-name/Example.pm +11 -4
- data/tracks/php/exercises/hello-world/hello-world.php +1 -1
- data/tracks/php/exercises/hello-world/hello-world_test.php +1 -11
- data/tracks/php/exercises/robot-name/robot-name_test.php +1 -0
- data/tracks/purescript/config.json +7 -0
- data/tracks/purescript/exercises/largest-series-product/bower.json +16 -0
- data/tracks/purescript/exercises/largest-series-product/examples/src/LargestSeriesProduct.purs +31 -0
- data/tracks/purescript/exercises/largest-series-product/src/LargestSeriesProduct.purs +3 -0
- data/tracks/purescript/exercises/largest-series-product/test/Main.purs +73 -0
- data/tracks/python/exercises/sublist/sublist_test.py +94 -55
- data/tracks/ruby/README.md +38 -25
- data/tracks/ruby/exercises/hamming/example.tt +6 -4
- data/tracks/ruby/exercises/hamming/hamming_test.rb +4 -5
- data/tracks/ruby/exercises/linked-list/linked_list_test.rb +16 -0
- data/tracks/ruby/exercises/luhn/luhn_test.rb +5 -5
- data/tracks/ruby/exercises/ocr-numbers/.meta/.version +1 -0
- data/tracks/ruby/exercises/ocr-numbers/example.rb +42 -61
- data/tracks/ruby/exercises/ocr-numbers/example.tt +21 -0
- data/tracks/ruby/exercises/ocr-numbers/ocr_numbers_test.rb +63 -138
- data/tracks/ruby/lib/generator/exercise_cases.rb +43 -0
- data/tracks/ruby/lib/generator/underscore.rb +9 -0
- data/tracks/ruby/lib/hamming_cases.rb +9 -14
- data/tracks/ruby/lib/luhn_cases.rb +2 -18
- data/tracks/ruby/lib/ocr_numbers_cases.rb +20 -0
- data/tracks/ruby/lib/pig_latin_cases.rb +2 -12
- data/tracks/ruby/test/generator/underscore_test.rb +23 -0
- data/tracks/scala/config.json +316 -316
- metadata +26 -10
- data/tracks/cpp/exercises/etl/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/grade-school/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/nucleotide-count/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/series/require_equal_containers.h +0 -88
- data/tracks/cpp/exercises/word-count/require_equal_containers.h +0 -88
- data/tracks/javascript/exercises/acronym/package.json +0 -12
- data/tracks/javascript/package.json +0 -12
data/tracks/cpp/docs/ABOUT.md
CHANGED
@@ -10,8 +10,8 @@ C++ supports [procedural](https://en.wikipedia.org/wiki/Procedural_programming),
|
|
10
10
|
[object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming),
|
11
11
|
[functional](https://en.wikipedia.org/wiki/Functional_programming)
|
12
12
|
and [generic](https://en.wikipedia.org/wiki/Generic_programming)
|
13
|
-
programming. C++
|
14
|
-
Mac OS, and
|
13
|
+
programming. Compilers for C++ are available for essentially every platform,
|
14
|
+
including Windows, Mac OS, and Linux.
|
15
15
|
|
16
16
|
Key Benefits:
|
17
17
|
- Type safety
|
@@ -55,8 +55,8 @@ MacOS users can install gcc 4.8 with [Homebrew](http://brew.sh/) via
|
|
55
55
|
#### Windows
|
56
56
|
|
57
57
|
Windows users can get
|
58
|
-
[Visual Studio Community
|
59
|
-
a free download that will give you the Visual Studio
|
58
|
+
[Visual Studio Community](https://www.visualstudio.com/vs/community/),
|
59
|
+
a free download that will give you the Visual Studio IDE and the
|
60
60
|
latest version of the Microsoft Visual C++ compiler.
|
61
61
|
|
62
62
|
### Prerequisite: CMake
|
@@ -83,7 +83,7 @@ improve the CMake support.
|
|
83
83
|
|
84
84
|
[CMake 2.8.11 or later](http://www.cmake.org/) is required to use the provided build recipe.
|
85
85
|
|
86
|
-
### Prerequisite: Boost
|
86
|
+
### Prerequisite: Boost 1.59+
|
87
87
|
|
88
88
|
The unit tests use Boost.Test, the unit testing framework included with
|
89
89
|
[Boost](http://www.boost.org/index.html). You may find other libraries
|
@@ -91,7 +91,7 @@ in Boost useful to you as you work through the exercises. In particular,
|
|
91
91
|
gcc 4.8 does not have a proper implementation of the standard regular
|
92
92
|
expression library, but you can find a compatible library in Boost.
|
93
93
|
You will need to download and install Boost. As of this writing Boost
|
94
|
-
1.
|
94
|
+
1.59+ is the required version. You will need a compiled version of the
|
95
95
|
boost libraries Boost.Test, Boost.DateTime and Boost.Regex, or you will
|
96
96
|
need to download from source and build the library yourself.
|
97
97
|
|
@@ -100,33 +100,27 @@ If you are having difficulties installing Boost for use with exercism,
|
|
100
100
|
|
101
101
|
#### Linux
|
102
102
|
|
103
|
-
Linux users can get
|
103
|
+
Linux users can usually get Boost from your distribution's package manager.
|
104
|
+
If a pre-built package is unavailable for your linux distribution, try
|
105
|
+
[installing Boost from source](http://www.boost.org/doc/libs/release/more/getting_started/index.html).
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
$ sudo apt-get -qq install libboost1.55-all-dev
|
109
|
-
```
|
107
|
+
Alternately, there may be some other way to install Boost for your
|
108
|
+
distribution without installing from source. For example, you can install
|
109
|
+
Boost 1.60 for Ubuntu 16.04 LTS by using a PPA.
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
```
|
112
|
+
$ sudo add-apt-repository -y ppa:samuel-bachmann/boost
|
113
|
+
$ sudo apt-get install boost1.60
|
114
|
+
```
|
115
115
|
|
116
116
|
#### Windows
|
117
117
|
|
118
|
-
Windows users can download compiled binaries from [sourceforge](
|
119
|
-
You must download the version appropriate for your compiler.
|
120
|
-
|
121
|
-
|
122
|
-
| Compiler | Download |
|
123
|
-
|----------|----------|
|
124
|
-
| Visual Studio Express 2013 for Windows Desktop (32-bit) | [boost_1_55_0-msvc-12.0-32.exe](http://sourceforge.net/projects/boost/files/boost-binaries/1.55.0-build2/boost_1_55_0-msvc-12.0-32.exe/download) |
|
125
|
-
| Visual Studio 2013 (32-bit) | [boost_1_55_0-msvc-12.0-32.exe](http://sourceforge.net/projects/boost/files/boost-binaries/1.55.0-build2/boost_1_55_0-msvc-12.0-32.exe/download) |
|
126
|
-
| Visual Studio 2012 (32-bit) | [boost_1_55_0-msvc-11.0-32.exe](http://sourceforge.net/projects/boost/files/boost-binaries/1.55.0-build2/boost_1_55_0-msvc-11.0-32.exe/download) |
|
127
|
-
| Visual Studio 2010 (32-bit) | [boost_1_55_0-msvc-10.0-32.exe](http://sourceforge.net/projects/boost/files/boost-binaries/1.55.0-build2/boost_1_55_0-msvc-10.0-32.exe/download) |
|
118
|
+
Windows users can download compiled binaries from [sourceforge](https://sourceforge.net/projects/boost/files/boost-binaries/).
|
119
|
+
You must download the version appropriate for your compiler. Note that
|
120
|
+
the version number is different from your Visual Studio version; the
|
121
|
+
compiler version in Visual Studio 2015 is MSVC 14.0.
|
128
122
|
|
129
|
-
In
|
123
|
+
In the descriptions, 32-bit refers to the kind of code generated by your
|
130
124
|
compiler and not the operating system. Code compiled for 32-bit will run
|
131
125
|
on both 32-bit and 64-bit versions of Windows. Code compiled for 64-bit
|
132
126
|
will only run on 64-bit versions of Windows. The CMake recipes used in
|
@@ -141,7 +135,7 @@ libraries. If you don't rename the directory you will see an error
|
|
141
135
|
like this when you run CMake:
|
142
136
|
|
143
137
|
```
|
144
|
-
> cmake -DBOOST_INCLUDEDIR:PATH=D:/tmp/
|
138
|
+
> cmake -DBOOST_INCLUDEDIR:PATH=D:/tmp/boost_1_59_0 ..
|
145
139
|
-- Building for: Visual Studio 12
|
146
140
|
-- The CXX compiler identification is MSVC 18.0.30723.0
|
147
141
|
-- Check for working CXX compiler using: Visual Studio 12
|
@@ -151,9 +145,9 @@ like this when you run CMake:
|
|
151
145
|
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message):
|
152
146
|
Unable to find the requested Boost libraries.
|
153
147
|
|
154
|
-
Boost version: 1.
|
148
|
+
Boost version: 1.59.0
|
155
149
|
|
156
|
-
Boost include path: D:/tmp/
|
150
|
+
Boost include path: D:/tmp/boost_1_59_0
|
157
151
|
|
158
152
|
The following Boost libraries could not be found:
|
159
153
|
|
data/tracks/cpp/docs/TESTS.md
CHANGED
@@ -101,7 +101,7 @@ setting the `BOOST_INCLUDEDIR` variable on the command-line. Here is an
|
|
101
101
|
example using the Visual Studio 2013 generator:
|
102
102
|
|
103
103
|
```
|
104
|
-
> cmake -G "Visual Studio 12" -DBOOST_INCLUDEDIR:PATH=D:/Code/boost/
|
104
|
+
> cmake -G "Visual Studio 12" -DBOOST_INCLUDEDIR:PATH=D:/Code/boost/boost_1_59_0 ..
|
105
105
|
```
|
106
106
|
|
107
107
|
**Note:** Path locations passed to CMake always use slash (`/`) as the
|
@@ -11,7 +11,7 @@ project(${exercise} CXX)
|
|
11
11
|
set(Boost_USE_STATIC_LIBS ON)
|
12
12
|
set(Boost_USE_MULTITHREADED ON)
|
13
13
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
14
|
-
find_package(Boost 1.
|
14
|
+
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
|
15
15
|
|
16
16
|
# Enable C++11 features on gcc/clang
|
17
17
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
@@ -33,15 +33,8 @@ else()
|
|
33
33
|
set(exercise_cpp "")
|
34
34
|
endif()
|
35
35
|
|
36
|
-
# Include a test helper header if it exists
|
37
|
-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/require_equal_containers.h)
|
38
|
-
set(test_helper require_equal_containers.h)
|
39
|
-
else()
|
40
|
-
set(test_helper "")
|
41
|
-
endif()
|
42
|
-
|
43
36
|
# Build executable from sources and headers
|
44
|
-
add_executable(${exercise} ${file}_test.cpp ${
|
37
|
+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
45
38
|
|
46
39
|
# We need boost includes
|
47
40
|
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
|
@@ -11,7 +11,7 @@ project(${exercise} CXX)
|
|
11
11
|
set(Boost_USE_STATIC_LIBS ON)
|
12
12
|
set(Boost_USE_MULTITHREADED ON)
|
13
13
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
14
|
-
find_package(Boost 1.
|
14
|
+
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
|
15
15
|
|
16
16
|
# Enable C++11 features on gcc/clang
|
17
17
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
@@ -33,15 +33,8 @@ else()
|
|
33
33
|
set(exercise_cpp "")
|
34
34
|
endif()
|
35
35
|
|
36
|
-
# Include a test helper header if it exists
|
37
|
-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/require_equal_containers.h)
|
38
|
-
set(test_helper require_equal_containers.h)
|
39
|
-
else()
|
40
|
-
set(test_helper "")
|
41
|
-
endif()
|
42
|
-
|
43
36
|
# Build executable from sources and headers
|
44
|
-
add_executable(${exercise} ${file}_test.cpp ${
|
37
|
+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
45
38
|
|
46
39
|
# We need boost includes
|
47
40
|
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
|
@@ -11,7 +11,7 @@ project(${exercise} CXX)
|
|
11
11
|
set(Boost_USE_STATIC_LIBS ON)
|
12
12
|
set(Boost_USE_MULTITHREADED ON)
|
13
13
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
14
|
-
find_package(Boost 1.
|
14
|
+
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
|
15
15
|
|
16
16
|
# Enable C++11 features on gcc/clang
|
17
17
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
@@ -33,15 +33,8 @@ else()
|
|
33
33
|
set(exercise_cpp "")
|
34
34
|
endif()
|
35
35
|
|
36
|
-
# Include a test helper header if it exists
|
37
|
-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/require_equal_containers.h)
|
38
|
-
set(test_helper require_equal_containers.h)
|
39
|
-
else()
|
40
|
-
set(test_helper "")
|
41
|
-
endif()
|
42
|
-
|
43
36
|
# Build executable from sources and headers
|
44
|
-
add_executable(${exercise} ${file}_test.cpp ${
|
37
|
+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
45
38
|
|
46
39
|
# We need boost includes
|
47
40
|
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
|
@@ -11,7 +11,7 @@ project(${exercise} CXX)
|
|
11
11
|
set(Boost_USE_STATIC_LIBS ON)
|
12
12
|
set(Boost_USE_MULTITHREADED ON)
|
13
13
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
14
|
-
find_package(Boost 1.
|
14
|
+
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
|
15
15
|
|
16
16
|
# Enable C++11 features on gcc/clang
|
17
17
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
@@ -33,15 +33,8 @@ else()
|
|
33
33
|
set(exercise_cpp "")
|
34
34
|
endif()
|
35
35
|
|
36
|
-
# Include a test helper header if it exists
|
37
|
-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/require_equal_containers.h)
|
38
|
-
set(test_helper require_equal_containers.h)
|
39
|
-
else()
|
40
|
-
set(test_helper "")
|
41
|
-
endif()
|
42
|
-
|
43
36
|
# Build executable from sources and headers
|
44
|
-
add_executable(${exercise} ${file}_test.cpp ${
|
37
|
+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
45
38
|
|
46
39
|
# We need boost includes
|
47
40
|
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
|
@@ -11,7 +11,7 @@ project(${exercise} CXX)
|
|
11
11
|
set(Boost_USE_STATIC_LIBS ON)
|
12
12
|
set(Boost_USE_MULTITHREADED ON)
|
13
13
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
14
|
-
find_package(Boost 1.
|
14
|
+
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)
|
15
15
|
|
16
16
|
# Enable C++11 features on gcc/clang
|
17
17
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
@@ -33,15 +33,8 @@ else()
|
|
33
33
|
set(exercise_cpp "")
|
34
34
|
endif()
|
35
35
|
|
36
|
-
# Include a test helper header if it exists
|
37
|
-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/require_equal_containers.h)
|
38
|
-
set(test_helper require_equal_containers.h)
|
39
|
-
else()
|
40
|
-
set(test_helper "")
|
41
|
-
endif()
|
42
|
-
|
43
36
|
# Build executable from sources and headers
|
44
|
-
add_executable(${exercise} ${file}_test.cpp ${
|
37
|
+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
45
38
|
|
46
39
|
# We need boost includes
|
47
40
|
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
|
@@ -4,81 +4,205 @@
|
|
4
4
|
|
5
5
|
using namespace std;
|
6
6
|
|
7
|
-
|
7
|
+
struct timeTest {
|
8
|
+
int hour;
|
9
|
+
int minute;
|
10
|
+
string expected;
|
11
|
+
string msg;
|
12
|
+
};
|
13
|
+
|
14
|
+
vector<timeTest> timeCases = {
|
15
|
+
{8, 0, "08:00", "on the hour"},
|
16
|
+
{11, 9, "11:09", "past the hour"},
|
17
|
+
{24, 0, "00:00", "midnight is zero hours"},
|
18
|
+
{25, 0, "01:00", "hour rolls over"},
|
19
|
+
{100, 0, "04:00", "hour rolls over continuously"},
|
20
|
+
{1, 60, "02:00", "sixty minutes is next hour"},
|
21
|
+
{0, 160, "02:40", "minutes roll over"},
|
22
|
+
{0, 1723, "04:43", "minutes roll over continuously"},
|
23
|
+
{25, 160, "03:40", "hour and minutes roll over"},
|
24
|
+
{201, 3001, "11:01", "hour and minutes roll over continuously"},
|
25
|
+
{72, 8640, "00:00", "hour and minutes roll over to exactly midnight"},
|
26
|
+
{-1, 15, "23:15", "negative hour"},
|
27
|
+
{-25, 0, "23:00", "negative hour rolls over"},
|
28
|
+
{-91, 0, "05:00", "negative hour rolls over continuously"},
|
29
|
+
{1, -40, "00:20", "negative minutes"},
|
30
|
+
{1, -160, "22:20", "negative minutes roll over"},
|
31
|
+
{1, -4820, "16:40", "negative minutes roll over continuously"},
|
32
|
+
{-25, -160, "20:20", "negative hour and minutes both roll over"},
|
33
|
+
{-121, -5810, "22:10", "negative hour and minutes both roll over continuously"},
|
34
|
+
};
|
35
|
+
|
36
|
+
struct addTest {
|
37
|
+
int hour;
|
38
|
+
int minute;
|
39
|
+
int add;
|
40
|
+
string expected;
|
41
|
+
string msg;
|
42
|
+
};
|
43
|
+
|
44
|
+
vector<addTest> addCases = {
|
45
|
+
{10, 0, 3, "10:03", "add minutes"},
|
46
|
+
{6, 41, 0, "06:41", "add no minutes"},
|
47
|
+
{0, 45, 40, "01:25", "add to next hour"},
|
48
|
+
{10, 0, 61, "11:01", "add more than one hour"},
|
49
|
+
{0, 45, 160, "03:25", "add more than two hours with carry"},
|
50
|
+
{23, 59, 2, "00:01", "add across midnight"},
|
51
|
+
{5, 32, 1500, "06:32", "add more than one day (1500 min = 25 hrs)"},
|
52
|
+
{1, 1, 3500, "11:21", "add more than two days"},
|
53
|
+
{10, 3, -3, "10:00", "subtract minutes"},
|
54
|
+
{10, 3, -30, "09:33", "subtract to previous hour"},
|
55
|
+
{10, 3, -70, "08:53", "subtract more than an hour"},
|
56
|
+
{0, 3, -4, "23:59", "subtract across midnight"},
|
57
|
+
{0, 0, -160, "21:20", "subtract more than two hours"},
|
58
|
+
{6, 15, -160, "03:35", "subtract more than two hours with borrow"},
|
59
|
+
{5, 32, -1500, "04:32", "subtract more than one day (1500 min = 25 hrs)"},
|
60
|
+
{2, 20, -3000, "00:20", "subtract more than two days"},
|
61
|
+
};
|
62
|
+
|
63
|
+
// Construct two separate clocks, set times, test if they are equal.
|
64
|
+
struct hm {
|
65
|
+
int hour;
|
66
|
+
int minute;
|
67
|
+
};
|
68
|
+
|
69
|
+
struct equalTest {
|
70
|
+
string msg;
|
71
|
+
hm c1;
|
72
|
+
hm c2;
|
73
|
+
bool expected;
|
74
|
+
};
|
75
|
+
|
76
|
+
vector<equalTest> equalCases = {
|
77
|
+
{
|
78
|
+
"clocks with same time",
|
79
|
+
hm{15, 37},
|
80
|
+
hm{15, 37},
|
81
|
+
true,
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"clocks a minute apart",
|
85
|
+
hm{15, 36},
|
86
|
+
hm{15, 37},
|
87
|
+
false,
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"clocks an hour apart",
|
91
|
+
hm{14, 37},
|
92
|
+
hm{15, 37},
|
93
|
+
false,
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"clocks with hour overflow",
|
97
|
+
hm{10, 37},
|
98
|
+
hm{34, 37},
|
99
|
+
true,
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"clocks with hour overflow by several days",
|
103
|
+
hm{3, 11},
|
104
|
+
hm{99, 11},
|
105
|
+
true,
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"clocks with negative hour",
|
109
|
+
hm{22, 40},
|
110
|
+
hm{-2, 40},
|
111
|
+
true,
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"clocks with negative hour that wraps",
|
115
|
+
hm{17, 3},
|
116
|
+
hm{-31, 3},
|
117
|
+
true,
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"clocks with negative hour that wraps multiple times",
|
121
|
+
hm{13, 49},
|
122
|
+
hm{-83, 49},
|
123
|
+
true,
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"clocks with minute overflow",
|
127
|
+
hm{0, 1},
|
128
|
+
hm{0, 1441},
|
129
|
+
true,
|
130
|
+
},
|
131
|
+
{
|
132
|
+
"clocks with minute overflow by several days",
|
133
|
+
hm{2, 2},
|
134
|
+
hm{2, 4322},
|
135
|
+
true,
|
136
|
+
},
|
137
|
+
{
|
138
|
+
"clocks with negative minute",
|
139
|
+
hm{2, 40},
|
140
|
+
hm{3, -20},
|
141
|
+
true,
|
142
|
+
},
|
143
|
+
{
|
144
|
+
"clocks with negative minute that wraps",
|
145
|
+
hm{4, 10},
|
146
|
+
hm{5, -1490},
|
147
|
+
true,
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"clocks with negative minute that wraps multiple times",
|
151
|
+
hm{6, 15},
|
152
|
+
hm{6, -4305},
|
153
|
+
true,
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"clocks with negative hours and minutes",
|
157
|
+
hm{7, 32},
|
158
|
+
hm{-12, -268},
|
159
|
+
true,
|
160
|
+
},
|
161
|
+
{
|
162
|
+
"clocks with negative hours and minutes that wrap",
|
163
|
+
hm{18, 7},
|
164
|
+
hm{-54, -11513},
|
165
|
+
true,
|
166
|
+
},
|
167
|
+
};
|
168
|
+
|
169
|
+
string errorMsg(string expected, string actual, string test)
|
8
170
|
{
|
9
|
-
|
10
|
-
|
171
|
+
stringstream ret;
|
172
|
+
ret << "[" << expected << " != " << actual << "] test case: " << test;
|
173
|
+
return ret.str();
|
11
174
|
}
|
12
175
|
|
13
|
-
|
14
|
-
BOOST_AUTO_TEST_CASE(prints_past_the_hour)
|
15
|
-
{
|
16
|
-
BOOST_REQUIRE_EQUAL("11:09", string(date_independent::clock::at(11, 9)));
|
17
|
-
BOOST_REQUIRE_EQUAL("11:19", string(date_independent::clock::at(11, 19)));
|
18
|
-
}
|
19
|
-
|
20
|
-
BOOST_AUTO_TEST_CASE(can_add_minutes)
|
21
|
-
{
|
22
|
-
const auto clock = date_independent::clock::at(10).plus(3);
|
23
|
-
|
24
|
-
BOOST_REQUIRE_EQUAL("10:03", string(clock));
|
25
|
-
}
|
26
|
-
|
27
|
-
BOOST_AUTO_TEST_CASE(can_add_over_an_hour)
|
28
|
-
{
|
29
|
-
const auto clock = date_independent::clock::at(10).plus(61);
|
30
|
-
|
31
|
-
BOOST_REQUIRE_EQUAL("11:01", string(clock));
|
32
|
-
}
|
33
|
-
|
34
|
-
BOOST_AUTO_TEST_CASE(wraps_around_midnight)
|
35
|
-
{
|
36
|
-
const auto clock = date_independent::clock::at(23, 59).plus(2);
|
37
|
-
|
38
|
-
BOOST_REQUIRE_EQUAL("00:01", string(clock));
|
39
|
-
}
|
40
|
-
|
41
|
-
BOOST_AUTO_TEST_CASE(can_subtract_minutes)
|
42
|
-
{
|
43
|
-
const auto clock = date_independent::clock::at(10, 3).minus(3);
|
44
|
-
|
45
|
-
BOOST_REQUIRE_EQUAL("10:00", string(clock));
|
46
|
-
}
|
47
|
-
|
48
|
-
BOOST_AUTO_TEST_CASE(can_subtract_to_previous_hour)
|
176
|
+
BOOST_AUTO_TEST_CASE(time_tests)
|
49
177
|
{
|
50
|
-
|
178
|
+
for (timeTest t : timeCases) {
|
179
|
+
const auto actual = string(date_independent::clock::at(t.hour, t.minute));
|
51
180
|
|
52
|
-
|
181
|
+
BOOST_REQUIRE_MESSAGE(t.expected == actual, errorMsg(t.expected, actual, t.msg));
|
182
|
+
}
|
53
183
|
}
|
54
184
|
|
55
|
-
|
56
|
-
|
57
|
-
const auto clock = date_independent::clock::at(10, 3).minus(70);
|
58
|
-
|
59
|
-
BOOST_REQUIRE_EQUAL("08:53", string(clock));
|
60
|
-
}
|
61
|
-
|
62
|
-
BOOST_AUTO_TEST_CASE(can_know_if_its_equal_to_another_clock)
|
63
|
-
{
|
64
|
-
const auto clock1 = date_independent::clock::at(10, 3);
|
65
|
-
const auto clock2 = date_independent::clock::at(10, 3);
|
66
|
-
|
67
|
-
BOOST_REQUIRE(clock1 == clock2);
|
68
|
-
}
|
69
|
-
|
70
|
-
BOOST_AUTO_TEST_CASE(can_know_if_its_not_equal_to_another_clock)
|
185
|
+
#if defined(EXERCISM_RUN_ALL_TESTS)
|
186
|
+
BOOST_AUTO_TEST_CASE(add_tests)
|
71
187
|
{
|
72
|
-
|
73
|
-
|
188
|
+
for (addTest a : addCases) {
|
189
|
+
const auto actual = string(date_independent::clock::at(a.hour, a.minute).plus(a.add));
|
74
190
|
|
75
|
-
|
191
|
+
BOOST_REQUIRE_MESSAGE(a.expected == actual, errorMsg(a.expected, actual, a.msg));
|
192
|
+
}
|
76
193
|
}
|
77
194
|
|
78
|
-
BOOST_AUTO_TEST_CASE(
|
195
|
+
BOOST_AUTO_TEST_CASE(equal_tests)
|
79
196
|
{
|
80
|
-
|
81
|
-
|
82
|
-
|
197
|
+
for (equalTest e : equalCases) {
|
198
|
+
const auto clock1 = date_independent::clock::at(e.c1.hour, e.c1.minute);
|
199
|
+
const auto clock2 = date_independent::clock::at(e.c2.hour, e.c2.minute);
|
200
|
+
|
201
|
+
if (e.expected)
|
202
|
+
BOOST_REQUIRE_MESSAGE(clock1 == clock2, errorMsg(string(clock1), string(clock2), e.msg));
|
203
|
+
else
|
204
|
+
BOOST_REQUIRE_MESSAGE(clock1 != clock2,
|
205
|
+
"[" << string(clock1) << " == " << string(clock2) << "] test case: " << e.msg);
|
206
|
+
}
|
83
207
|
}
|
84
208
|
#endif
|