模拟宇宙中天体运动,对于宇宙中的每一个天体,计算其速度和位置。满足谷歌测试框架进行测试。
涉及的类:宇宙,天体对象,天体创建工厂,数学计算类,遍历宇宙中天体类,解析文本类
设计模式:宇宙是单例,工厂是工厂方法,遍历类是观察者模式
传统方式:给定基础头文件和cmakelist.txt,用camke生成工程,在vs中编译和调试
存在问题:
mac下用clion,结果:
win7下用clion,结果:
CMakeLists.txt 语法介绍与实例演练
cmake_minimum_required(VERSION 3.18)
project(Assignment6-Solution)
find_package(Threads)
find_package(Git QUIET)
# Set compiler flags
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -pedantic -pedantic-errors -g")
# Define all testing related content here
enable_testing()
# Bring in GoogleTest
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
include_directories(${googletest_SOURCE_DIR}/googletest/include)
# Include project headers
include_directories(./include)
# Define the source files and dependencies for the executable
set(SOURCE_FILES
src/Object.cpp
src/ObjectFactory.cpp
src/Parser.cpp
src/Universe.cpp
src/Visitor.cpp
tests/main.cpp
tests/vectorTest.cpp
tests/inertiaTest.cpp
tests/visitorTest.cpp
tests/UMCTest.cpp
)
# Make the project root directory the working directory when we run
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(testing ${SOURCE_FILES})
add_dependencies(testing gtest)
target_link_libraries(testing gtest ${CMAKE_THREAD_LIBS_INIT})