Skip to content

Commit

Permalink
tmp: playground to test exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeng committed Nov 5, 2023
1 parent a7653bb commit 2ec466b
Show file tree
Hide file tree
Showing 6 changed files with 18,097 additions and 0 deletions.
66 changes: 66 additions & 0 deletions exercises/concept/doctor-data/doctor-data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Basic CMake project
cmake_minimum_required(VERSION 3.5.1)

# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# 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 $<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 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
# added "-Wno-unused-parameter" to remove compiler warnings
# should make it easier for students to run their first real code
COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter"
)
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
if(${MSVC})
set_target_properties(${exercise} PROPERTIES
COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()

# Run the tests on every build
add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise})
23 changes: 23 additions & 0 deletions exercises/concept/doctor-data/doctor-data/doctor_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "doctor_data.h"

namespace heaven {



void Vessel::make_buster() { ++busters; }
void Vessel::shoot_buster() { --busters; }

void Vessel::install_roamers(int num) { roamers += num; }

std::string get_older_bob(const Vessel& vessel1, const Vessel& vessel2) {
return vessel1.generation < vessel2.generation ? vessel1.name
: vassel2.name;
}
} // namespace heaven



robots::Flower::Flower(std::string name, int size) {this->name = "Robotica " + name; this->size = size;}
void robots::Flower::start_next_day() {if (!needs_water) ++size; needs_water = true;}
std::string robots::Flower::get_name() {return name;}
int robots::Flower::get_size() {return size;}
51 changes: 51 additions & 0 deletions exercises/concept/doctor-data/doctor-data/doctor_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <string>

namespace star_map {
enum class System {
EpsilonEridani,
Sol,
Omicron2Eridani,
DeltaEridani,
AlphaCentauri,
EpsilonIndi,
BetaHydri
};
}
namespace heaven {
class Vessel {
public:
Vessel(std::string name, int generation,
star_map::System current_system = star_map::System::Sol)
: name(name), generation(generation), current_system(current_system) {}
void make_buster();
void shoot_buster();
void install_roamers(int num);

std::string name{};
int generation{};
star_map::System current_system{};
int busters{};
int roamers{};
};

std::string get_older_bob(const Vessel& vessel1, const Vessel& vessel2);

} // namespace heaven

namespace robots {
class Flower {
private:
bool needs_water{};
int size{};
std::string name{};

public:
Flower(std::string name, int size = 0);
void give_water();
std::string get_name();
int get_size();
void start_next_day();
};
} // namespace robots
18 changes: 18 additions & 0 deletions exercises/concept/doctor-data/doctor-data/doctor_data_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "doctor_data.h"
#ifdef EXERCISM_TEST_SUITE
#include <catch2/catch.hpp>
#else
#include "test/catch.hpp"
#endif

TEST_CASE("Create different plants", "[task_1]") {
heaven::Vessel bob{"Robert Johansson", 1, star_map::System::BetaHydri};
heaven::Vessel riker{"Robert Johansson 2", 2};

robots::Flower percy = robots::Flower{"Hello", 1};
}

#if defined(EXERCISM_RUN_ALL_TESTS)


#endif
Loading

0 comments on commit 2ec466b

Please sign in to comment.