few, FINALLY BUILDED
This commit is contained in:
parent
b50153dcfe
commit
c96be01371
11 changed files with 18204 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
cpp/hello-world/.exercism/metadata.json
|
||||||
28
cpp/hello-world/.exercism/config.json
Normal file
28
cpp/hello-world/.exercism/config.json
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"authors": [
|
||||||
|
"samsondstl"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"elyashiv",
|
||||||
|
"jackhughesweb",
|
||||||
|
"KevinWMatthews",
|
||||||
|
"patricksjackson",
|
||||||
|
"sturzl"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"hello_world.cpp",
|
||||||
|
"hello_world.h"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"hello_world_test.cpp"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/example.cpp",
|
||||||
|
".meta/example.h"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"blurb": "Exercism's classic introductory exercise. Just say \"Hello, World!\".",
|
||||||
|
"source": "This is an exercise to introduce users to using Exercism",
|
||||||
|
"source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
|
||||||
|
}
|
||||||
23
cpp/hello-world/.gitignore
vendored
Normal file
23
cpp/hello-world/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Билд-артефакты
|
||||||
|
build/
|
||||||
|
**/*build*/
|
||||||
|
*.sln
|
||||||
|
*.vcxproj*
|
||||||
|
*.cmake
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles/
|
||||||
|
Makefile
|
||||||
|
|
||||||
|
.cache/
|
||||||
|
|
||||||
|
# Бинарники
|
||||||
|
*.out
|
||||||
|
*.exe
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Отладка
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.dSYM/
|
||||||
67
cpp/hello-world/CMakeLists.txt
Normal file
67
cpp/hello-world/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
# Get the exercise name from the current directory
|
||||||
|
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||||
|
|
||||||
|
# Basic CMake project
|
||||||
|
cmake_minimum_required(VERSION 3.5.1)
|
||||||
|
|
||||||
|
# Name the project after the exercise
|
||||||
|
project(${exercise} CXX)
|
||||||
|
|
||||||
|
# Get a source filename from the exercise name by replacing -'s with _'s
|
||||||
|
string(REPLACE "-" "_" file ${exercise})
|
||||||
|
|
||||||
|
# Implementation could be only a header
|
||||||
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
|
||||||
|
set(exercise_cpp ${file}.cpp)
|
||||||
|
else()
|
||||||
|
set(exercise_cpp "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Use the common Catch library?
|
||||||
|
if(EXERCISM_COMMON_CATCH)
|
||||||
|
# For Exercism track development only
|
||||||
|
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $<TARGET_OBJECTS:catchlib>)
|
||||||
|
elseif(EXERCISM_TEST_SUITE)
|
||||||
|
# The Exercism test suite is being run, the Docker image already
|
||||||
|
# includes a pre-built version of Catch.
|
||||||
|
find_package(Catch2 REQUIRED)
|
||||||
|
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
|
||||||
|
target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain)
|
||||||
|
# When Catch is installed system wide we need to include a different
|
||||||
|
# header, we need this define to use the correct one.
|
||||||
|
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
|
||||||
|
else()
|
||||||
|
# Build executable from sources and headers
|
||||||
|
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(${exercise} PROPERTIES
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED OFF
|
||||||
|
CXX_EXTENSIONS OFF
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
|
||||||
|
set_target_properties(${exercise} PROPERTIES
|
||||||
|
COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configure to run all the tests?
|
||||||
|
if(${EXERCISM_RUN_ALL_TESTS})
|
||||||
|
target_compile_definitions(${exercise} PRIVATE EXERCISM_RUN_ALL_TESTS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Tell MSVC not to warn us about unchecked iterators in debug builds
|
||||||
|
# Treat warnings as errors
|
||||||
|
# Treat type conversion warnings C4244 and C4267 as level 4 warnings, i.e. ignore them in level 3
|
||||||
|
if(${MSVC})
|
||||||
|
set_target_properties(${exercise} PROPERTIES
|
||||||
|
COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS
|
||||||
|
COMPILE_FLAGS "/WX /w44244 /w44267")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Run the tests on every build
|
||||||
|
add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise})
|
||||||
61
cpp/hello-world/HELP.md
Normal file
61
cpp/hello-world/HELP.md
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
Running the tests involves running `cmake -G` and then using the build command appropriate for your platform.
|
||||||
|
Detailed instructions on how to do this can be found on the [Running the Tests][cpp-tests-instructions] page for C++ on exercism.org.
|
||||||
|
|
||||||
|
## Passing the Tests
|
||||||
|
|
||||||
|
When you start a new exercise locally, the files are configured so that only the first test is performed.
|
||||||
|
Get that first test compiling, linking and passing by following the [three rules of test-driven development][three-laws-of-tdd].
|
||||||
|
Create just enough structure by declaring namespaces, functions, classes, etc., to satisfy any compiler errors and get the test to fail.
|
||||||
|
Then write just enough code to get the test to pass.
|
||||||
|
Once you've done that, uncomment the next test by moving the line `if defined(EXERCISM_RUN_ALL_TESTS)` past the next test.
|
||||||
|
|
||||||
|
See the example below from the Bob exercise (file `bob_test.cpp`, line 15):
|
||||||
|
|
||||||
|
```diff
|
||||||
|
-#if defined(EXERCISM_RUN_ALL_TESTS)
|
||||||
|
TEST_CASE("shouting")
|
||||||
|
{
|
||||||
|
REQUIRE("Whoa, chill out!" == bob::hey("WATCH OUT!"));
|
||||||
|
}
|
||||||
|
+#if defined(EXERCISM_RUN_ALL_TESTS)
|
||||||
|
```
|
||||||
|
|
||||||
|
Moving this line past the next test may result in compile errors as new constructs may be invoked that you haven't yet declared or defined.
|
||||||
|
Again, fix the compile errors minimally to get a failing test, then change the code minimally to pass the test, refactor your implementation for readability and expressiveness and then go on to the next test.
|
||||||
|
|
||||||
|
Try to use standard C++17 facilities in preference to writing your own low-level algorithms or facilities by hand.
|
||||||
|
|
||||||
|
[cpp-tests-instructions]: https://exercism.org/docs/tracks/cpp/tests
|
||||||
|
[three-laws-of-tdd]: http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit hello_world.cpp hello_world.h` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [C++ track's documentation](https://exercism.org/docs/tracks/cpp)
|
||||||
|
- The [C++ track's programming category on the forum](https://forum.exercism.org/c/programming/cpp)
|
||||||
|
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
To get help if you're having trouble, you can use one of the following resources:
|
||||||
|
|
||||||
|
- [`c++-faq` tag on StackOverflow](https://stackoverflow.com/tags/c%2b%2b-faq/info)
|
||||||
|
- [C++ FAQ from isocpp.com](https://isocpp.org/faq)
|
||||||
|
- [CppReference](http://en.cppreference.com/) is a wiki reference to the C++ language and standard library
|
||||||
|
- [C traps and pitfalls](http://www.slideshare.net/LegalizeAdulthood/c-traps-and-pitfalls-for-c-programmers) is useful if you are new to C++, but have programmed in C
|
||||||
39
cpp/hello-world/README.md
Normal file
39
cpp/hello-world/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Hello World
|
||||||
|
|
||||||
|
Welcome to Hello World on Exercism's C++ Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
The classical introductory exercise.
|
||||||
|
Just say "Hello, World!".
|
||||||
|
|
||||||
|
["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment.
|
||||||
|
|
||||||
|
The objectives are simple:
|
||||||
|
|
||||||
|
- Modify the provided code so that it produces the string "Hello, World!".
|
||||||
|
- Run the test suite and make sure that it succeeds.
|
||||||
|
- Submit your solution and check it at the website.
|
||||||
|
|
||||||
|
If everything goes well, you will be ready to fetch your first real exercise.
|
||||||
|
|
||||||
|
[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @samsondstl
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @elyashiv
|
||||||
|
- @jackhughesweb
|
||||||
|
- @KevinWMatthews
|
||||||
|
- @patricksjackson
|
||||||
|
- @sturzl
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program
|
||||||
9
cpp/hello-world/hello_world.cpp
Normal file
9
cpp/hello-world/hello_world.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "hello_world.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace hello_world {
|
||||||
|
|
||||||
|
string hello() { return "Goodbye, Mars!"; }
|
||||||
|
|
||||||
|
} // namespace hello_world
|
||||||
22
cpp/hello-world/hello_world.h
Normal file
22
cpp/hello-world/hello_world.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// This is an include guard.
|
||||||
|
// You could alternatively use '#pragma once'
|
||||||
|
// See https://en.wikipedia.org/wiki/Include_guard
|
||||||
|
#if !defined(HELLO_WORLD_H)
|
||||||
|
#define HELLO_WORLD_H
|
||||||
|
|
||||||
|
// Include the string header so that we have access to 'std::string'
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Declare a namespace for the function(s) we are exporting.
|
||||||
|
// https://en.cppreference.com/w/cpp/language/namespace
|
||||||
|
namespace hello_world {
|
||||||
|
|
||||||
|
// Declare the 'hello()' function, which takes no arguments and returns a
|
||||||
|
// 'std::string'. The function itself is defined in the hello_world.cpp source
|
||||||
|
// file. Because it is inside of the 'hello_world' namespace, it's full name is
|
||||||
|
// 'hello_world::hello()'.
|
||||||
|
std::string hello();
|
||||||
|
|
||||||
|
} // namespace hello_world
|
||||||
|
|
||||||
|
#endif
|
||||||
15
cpp/hello-world/hello_world_test.cpp
Normal file
15
cpp/hello-world/hello_world_test.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Include the header file with the definitions of the functions you create.
|
||||||
|
#include "hello_world.h"
|
||||||
|
|
||||||
|
// Include the test framework.
|
||||||
|
#ifdef EXERCISM_TEST_SUITE
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
#else
|
||||||
|
#include "test/catch.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Declares a single test.
|
||||||
|
TEST_CASE("test_hello") {
|
||||||
|
// Check if your function returns "Hello, World!".
|
||||||
|
REQUIRE(hello_world::hello() == "Hello, World!");
|
||||||
|
}
|
||||||
17937
cpp/hello-world/test/catch.hpp
Normal file
17937
cpp/hello-world/test/catch.hpp
Normal file
File diff suppressed because it is too large
Load diff
2
cpp/hello-world/test/tests-main.cpp
Normal file
2
cpp/hello-world/test/tests-main.cpp
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue