commit
ecb3c6b24a
@ -0,0 +1,2 @@
|
||||
build
|
||||
.vscode
|
@ -0,0 +1,43 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(test)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
||||
|
||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
# Prevent overriding the parent project's compiler/linker
|
||||
# settings on Windows
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Add googletest directly to our build. This defines
|
||||
# the gtest and gtest_main targets.
|
||||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL)
|
||||
|
||||
# The gtest/gtest_main targets carry header search path
|
||||
# dependencies automatically when using CMake 2.8.11 or
|
||||
# later. Otherwise we have to add them here ourselves.
|
||||
if (CMAKE_VERSION VERSION_LESS 2.8.11)
|
||||
include_directories("${gtest_SOURCE_DIR}/include")
|
||||
endif()
|
||||
|
||||
set(GCC_COVERAGE_COMPILE_FLAGS "-g -O0 -coverage -fprofile-arcs -ftest-coverage")
|
||||
set(GCC_COVERAGE_LINK_FLAGS "-coverage -lgcov")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest)
|
@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
|
||||
project(googletest-download NONE)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googletest
|
||||
# URL ${CMAKE_SOURCE_DIR}/thirdparty/gtest/googletest-release-1.8.0.zip
|
||||
URL https://github.com/google/googletest/archive/release-1.12.1.zip
|
||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(sphere)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "--coverage")
|
||||
|
||||
add_library(sphere sphere.cc)
|
@ -0,0 +1,59 @@
|
||||
#include "sphere.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
Sphere::Sphere() {
|
||||
this->orig_x = 0.0;
|
||||
this->orig_y = 0.0;
|
||||
this->orig_z = 0.0;
|
||||
this->radius = 0.0;
|
||||
}
|
||||
|
||||
Sphere::Sphere(float ox, float oy, float oz, float rad) {
|
||||
this->orig_x = ox;
|
||||
this->orig_y = oy;
|
||||
this->orig_z = oz;
|
||||
if (rad >= 0)
|
||||
this->radius = rad;
|
||||
else
|
||||
this->radius = 0;
|
||||
}
|
||||
|
||||
float* Sphere::getOrigin() {
|
||||
float* result = new float[3]{this->orig_x, this->orig_y, this->orig_z};
|
||||
return result;
|
||||
}
|
||||
|
||||
float Sphere::getRadius() {
|
||||
return this->radius;
|
||||
}
|
||||
|
||||
void Sphere::setOrigin(float ox, float oy, float oz) {
|
||||
this->orig_x = ox;
|
||||
this->orig_y = oy;
|
||||
this->orig_z = oy;
|
||||
}
|
||||
|
||||
void Sphere::setRadius(float rad) {
|
||||
this->radius = 0;
|
||||
}
|
||||
|
||||
bool Sphere::intersect(Sphere& other) {
|
||||
float dist = sqrt(pow(this->orig_x - other.orig_x, 2) + pow(this->orig_y - other.orig_y, 2) + pow(this->orig_z - other.orig_z, 2));
|
||||
return true;
|
||||
}
|
||||
|
||||
float Sphere::SurfaceArea() {
|
||||
return 4 * M_PI * pow(this->radius, 2);
|
||||
}
|
||||
|
||||
float Sphere::Volume() {
|
||||
return (4 / 3) * M_PI * pow(this->radius, 2);
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, const Sphere& sphere) {
|
||||
os << "[( " << sphere.orig_x << ", " << sphere.orig_y << ", " << sphere.orig_z << "), " << sphere.radius << "]";
|
||||
return os;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
|
||||
class Sphere {
|
||||
public:
|
||||
Sphere();
|
||||
Sphere(float ox, float oy, float oz, float rad);
|
||||
float SurfaceArea();
|
||||
float Volume();
|
||||
void setOrigin(float ox, float oy, float oz);
|
||||
void setRadius(float rad);
|
||||
float* getOrigin();
|
||||
float getRadius();
|
||||
bool intersect(Sphere&);
|
||||
friend std::ostream& operator<<(std::ostream&, const Sphere&);
|
||||
|
||||
private:
|
||||
float orig_x, orig_y, orig_z;
|
||||
float radius;
|
||||
};
|
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
project(unittest)
|
||||
|
||||
include_directories(../src)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "--coverage")
|
||||
# Now simply link against gtest or gtest_main as needed.
|
||||
|
||||
add_executable(utest test_test.cc)
|
||||
target_link_libraries(utest gtest_main)
|
||||
target_link_libraries(utest sphere)
|
||||
enable_testing()
|
@ -0,0 +1,10 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "sphere.h"
|
||||
|
||||
TEST(SphereTest, ConstructorTest) {
|
||||
Sphere sph(0, 1, 2, 3);
|
||||
EXPECT_EQ(sph.getOrigin()[0], 0);
|
||||
EXPECT_EQ(sph.getOrigin()[1], 1);
|
||||
EXPECT_EQ(sph.getOrigin()[2], 2);
|
||||
EXPECT_EQ(sph.getRadius(), 3);
|
||||
}
|
Loading…
Reference in new issue