diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 13ce3bc0..97dea3b6 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -18,18 +18,17 @@ A clear and concise description of what you expected to happen. **Reproduction steps** Steps to reproduce the bug. - + **Platform information:** - - OS: **Windows NT-WSL-1** - - Compiler+version: **GCC 7.5.0** - - release version: **0.0.5** - +- OS: **Windows NT-WSL-2 Ubuntu 26.04** +- Compiler+version: **GCC 15.2.0** +- release version: **0.15.0** **Additional context** -Add any other context about the problem here. \ No newline at end of file +Add any other context about the problem here. diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9970dc61..424e4b8c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -15,17 +15,16 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-24.04 ] + os: [ ubuntu-26.04 ] env: - CC: gcc-13 - CXX: g++-13 + CC: gcc-15 + CXX: g++-15 # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: checkout code - uses: actions/checkout@v5 - - uses: actions/cache@v4 + - uses: certseeds/common-actions/actions/checkout@v1 + - uses: certseeds/common-actions/actions/cache@v1 env: cache-name: cache-cmake-files with: @@ -46,15 +45,12 @@ jobs: - name: Install ccache, check gcc version run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update && sudo apt-get install -y ccache + sudo apt-get update + sudo apt-get install -y ccache + sudo apt-get install -y libgtest-dev libgmock-dev gcc --version g++ --version - - name: prepare deps - run: | - bash ./third_party/install.sh - - name: Use cmake run: cmake --version @@ -89,14 +85,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-24.04 ] + os: [ ubuntu-26.04 ] # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout code - uses: actions/checkout@v5 + uses: certseeds/common-actions/actions/checkout@v1 # ensure the path and files of project - name: ensure the path and files of project diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93653ef2..520d411e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,31 +16,28 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-24.04 ] + os: [ ubuntu-26.04 ] env: - CC: gcc-13 - CXX: g++-13 + CC: gcc-15 + CXX: g++-15 # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout code - uses: actions/checkout@v5 + uses: certseeds/common-actions/actions/checkout@v1 - name: hardwares - cpu run: nproc; cat /proc/cpuinfo - name: Install ccache, check gcc version run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update && sudo apt-get install -y ccache + yes | sudo apt-get update + yes | sudo apt-get install ccache + yes | sudo apt-get install libgtest-dev libgmock-dev gcc --version g++ --version - - name: prepare deps - run: | - bash ./third_party/install.sh - - name: Use cmake run: cmake --version @@ -63,18 +60,18 @@ jobs: build: name: publish release env: - CC: gcc-13 - CXX: g++-13 + CC: gcc-15 + CXX: g++-15 if: github.repository == 'Certseeds/algorithm-template' needs: test # The type of runner that the job will run on - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout code - uses: actions/checkout@v5 + uses: certseeds/common-actions/actions/checkout@v1 - name: Branch name id: branch_name @@ -94,17 +91,6 @@ jobs: - name: ensure the path and files of project run: sudo apt-get install tree; tree; mkdir -p ./cmake_build_release - - name: prepare deps - run: | - bash ./third_party/install.sh - bash ./third_party/rename.sh - - - name: move cmake-fetchcontent to folder - working-directory: ./third_party - run: | - rm ./CMakeLists.txt - mv ./CMakeLists.release.txt ./CMakeLists.txt - - name: run script working-directory: ./script run: python3 file_template.py @@ -116,7 +102,7 @@ jobs: tree - name: release - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@v3 if: startsWith(github.ref, 'refs/tags/') with: files: ./../script_no_need.zip @@ -129,18 +115,18 @@ jobs: release-branch: name: publish release-branch env: - CC: gcc-13 - CXX: g++-13 + CC: gcc-15 + CXX: g++-15 if: github.repository == 'Certseeds/algorithm-template' needs: [ test, build ] # The type of runner that the job will run on - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: checkout code - uses: actions/checkout@v5 + uses: certseeds/common-actions/actions/checkout@v1 - name: Branch name id: branch_name @@ -152,26 +138,10 @@ jobs: env: SOURCE_NAME: ${{ steps.branch_name.outputs.SOURCE_NAME }} - - - name: prepare deps - run: | - bash ./third_party/install.sh - bash ./third_party/rename.sh - - name: git operations run: | git config --global user.name 'Certseeds' git config --global user.email '51754303+Certseeds@users.noreply.github.com' - git checkout --orphan release - - - name: move cmake-fetchcontent to folder - working-directory: ./third_party - run: | - echo '**/.github/*' > ./.gitignore - rm ./CMakeLists.txt - mv ./CMakeLists.release.txt ./CMakeLists.txt - git add -A - git commit -am "init: with deps" - name: run script working-directory: ./script diff --git a/.gitignore b/.gitignore index 68de6492..154bb199 100644 --- a/.gitignore +++ b/.gitignore @@ -297,3 +297,4 @@ $RECYCLE.BIN/ # test files begin *.test.out *.zip +node_modules diff --git a/CMakeLists.txt b/CMakeLists.txt index ab9bea1f..e7fbf885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16.6) set(PROJECT_VERSION_MAJOR 0) -set(PROJECT_VERSION_MINOR 15) +set(PROJECT_VERSION_MINOR 16) set(PROJECT_VERSION_PATCH 0) # delete endsWith strs when master merge dev project(algorithm_template @@ -18,8 +18,9 @@ string(TIMESTAMP time_str "%Y/%m/%d %H:%M:%S") MESSAGE(STATUS "Compiler In \n ${time_str}") include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeLists.txt) + +find_package(GTest REQUIRED) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/include) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party) enable_testing() file(GLOB USER_LIBS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lab_*) # regex to find libs, more flexibility diff --git a/README.md b/README.md index 6e4f717f..6ecee825 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,12 @@ OJ系统存在着一些特殊要求-因此考虑到下面的因素, 设计了一 + 上交题目无需修改类名, 方法名等等内容, 只需复制粘贴. + 支持为每个问题撰写测试用例, 并支持用户之间方便的交换测试用例 -+ 只依赖于Unix-Like系统, 支持C++17的编译器与仓库本身, 没有依赖包 ++ 只依赖于Unix-Like系统, 支持C++20的编译器与仓库本身, 没有依赖包 + 易于拓展, 提供基本算法接口与实现 ### Built With -[![catch_2][catch2_image]](https://github.com/catchorg/Catch2) +[![Google Test][gtest_image]](https://github.com/google/googletest)

(back to top)

@@ -88,7 +88,19 @@ This is an example of how to list things you need to use the software and how to #### Windows -1. WSL(推荐ubuntu 24.04), `sudo apt install build-essential ccache` +推荐使用 windows subsystem linux 2, 换好apt源之后只需要 + +``` bash +yes | sudo apt-get update +yes | sudo apt-get upgrade +yes | sudo apt-get install build-essential ccache cmake +yes | sudo apt-get install libgtest-dev libgmock-dev +``` + +> **注意**: GTest 需要和编译器在**同一环境**下安装。 +> - 系统 GCC → `apt install libgtest-dev libgmock-dev` +> - conda GCC → `conda install -c conda-forge gtest gmock` +> - 若混用 (如 conda GCC + apt GTest),CMake 可能找不到库或头文件。 + 命令行检测gcc版本 @@ -153,18 +165,18 @@ git clone https://github.com/${YOUE_GITHUB_USER_NAME}/algorithm-template.git 显然, 有更好的解决方式:使用测试框架. -+ 在本repo, 使用`Catch2`测试框架. ++ 在本repo, 使用 `Google Test` 测试框架. + 比如, 我们有四组数据, 第一组, 第二组测试边界值, 第三组使用随机数测试对偶性与正确性, 第四组测试几个手动的随机值. + 参见[test_for_lab00_A](./lab_00/A/test.cpp) + 这样一来, 我们只需要每次修改完主文件之后, run `algorithm-template_test`, 对其进行调用, 就能验证其在所有的测试用例上的正确性. -### 多个输出值的检查:`Catch::Matchers` +### 多个输出值的检查: `EXPECT_EQ` 上面的例子里, 输出值只是一个值, 所以手动检查的难度不大, 但是如果目标输出是一个数组, 那么手动检查的难度就非常大了. 举例:[Crzay Plan](https://acm.sustech.edu.cn/onlinejudge/problem.php?id=1250), 输入可能有1.1*10^6个. -这种情况下对这么多值进行直接的观察就很难, 所以我们预先将期望的值直接写在测试文件里, 用Catch2内置的Matcher比较(见[test_for_lab00_B](./lab_00/B/test.cpp)的`CHECK_THAT()`部分.) +这种情况下对这么多值进行直接的观察就很难, 所以我们预先将期望的值直接写在测试文件里, 用Google Test内置的EXPECT_EQ比较(见[test_for_lab00_B](./lab_00/B/test.cpp)部分.) PS: 当然, 这种情况也只适用于规模比较小的情况, 规模再大的话, 直接由人手动写在测试文件里也太占空间了. @@ -177,13 +189,13 @@ PS: 当然, 这种情况也只适用于规模比较小的情况, 规模再大的 而在这里, 使用`CS203_redirect`对象, 便可以省去手动输入的方式. ``` cpp -TEST_CASE("test case 1", "[test 00 C]") { +TEST(lab_00_C, test_case_1) { const CS203_redirect cr{"01.data.in", ""}; // 重定向开始, 开始run // or CS203_redirect cr{"01.data.in"}; const auto output_data = isBipartite(read()); // 重定向结束 - CHECK_FALSE(output_data); + EXPECT_FALSE(output_data); } ``` @@ -206,14 +218,13 @@ PS: 此处注意, 引用文件的相对路径, 不是直接的`test/lab_00/C/res + 这种情况下, 使用c++的重定向输出就可以较为方便的对输入进行处理, 同时保存输出方便调试. ``` cpp - TEST_CASE("test case 2", "[test 00 D]") { - SECTION("do") { + TEST(lab_00_D, test_case_2) { + { const CS203_redirect cr{"01.data.in", "01.test.out"}; auto input_data = read(); cal(input_data); - } SECTION("compare files") { - CHECK(compareFiles("01.test.out", "01.data.out")); } + EXPECT_TRUE(compareFiles("01.test.out", "01.data.out")); } ``` @@ -274,43 +285,30 @@ static const auto faster_streams = [] { 通常情况下, 可以将运行时间缩短到1/2甚至更少. -### Why choose Catch? +### Why choose googletest -1. 先来看可选项有哪些 +自 Ubuntu 22.04 开始, googletest的预编译包被打包进了官方的源中 (`libgtest-dev` 和 `libgmock-dev`), 不再需要自行编译. 因此可以直接通过系统的包管理器安装并使用. -| FrameWork | Catch2 | Google Test | CPPUnit | Boost.Test | Microsoft 单元测试框架 | -| :----------------------: | :----: | :---------: | :-----: | :--------: | :--------------------------: | -| 跨平台 | √ | √ | √ | √ | X | -| 是否需要提前在系统内安装 | X | √ | √ | √ | √(and visual studio make it) | -| 语法 | 简单 | 简单 | 复杂 | 简单 | Unknown | +``` bash +yes | sudo apt-get install libgtest-dev libgmock-dev +``` -先筛选跨平台, 去掉了Microsoft, 再筛选不需要安装, 只剩Catch2, 结束. +考虑到 windows, macos都可以使用容器来运行linux, 只需要近年的 ubuntu lts支持, 就是全平台支持. ## Roadmap + [x] 基础框架 -+ [x] Catch2 接入 ++ [x] 测试框架接入 + [x] 测试用例接入文件 -+ [x] 算法模块添加 - + [x] FFT - + [x] Tree - + [x] Trie - + [x] RB-Tree - + [x] AVL-Tree - + [x] Matrix - + [ ] AND MORE... -+ [ ] 跨平台 - + [ ] Windows(No Support becuase ccache do not support MSVC, compile cost too much time and product size) - + [x] Unix-Like + [x] CI-CD + [x] CI: GitHub-Actions提交触发 + [x] CD: Tag触发的自动Release -+ [x] leetcode题目 ++ [x] ~~leetcode题目~~ + [x] ~~预编译头文件~~ccache加速编译 -+ [x] basic文件夹添加CS205内容, 方便入门C++ - + [x] 以及一部分rust代码 -+ [ ] Cyaron测试数据生成 -+ [ ] WiKi Page ++ [x] ~~basic文件夹添加CS205内容, 方便入门C++~~ + + [x] ~~以及一部分rust代码~~ ++ [ ] ~~Cyaron测试数据生成~~ ++ [ ] ~~WiKi Page~~

(back to top)

@@ -390,7 +388,7 @@ Use this space to list resources you find helpful and would like to give credit [issue_LINK]: https://github.com/Certseeds/algorithm-template/issues [pr_LINK]: https://github.com/Certseeds/algorithm-template/pulls [discussion_LINK]: https://github.com/Certseeds/algorithm-template/discussions -[catch2_image]: https://raw.githubusercontent.com/catchorg/Catch2/v2.x/artwork/catch2-logo-small.png +[gtest_image]: https://raw.githubusercontent.com/google/googletest/main/docs/images/googletest.png [AGPL-shield]: https://img.shields.io/badge/License-AGPL-orange?style=for-the-badge [AGPL_Link]: http://opensource.org/licenses/AGPL [cc_by_nc_sa_4_0_shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-orange?style=for-the-badge @@ -404,8 +402,6 @@ Use this space to list resources you find helpful and would like to give credit [stars-url]: https://github.com/Certseeds/algorithm-template/stargazers [issues-shield]: https://img.shields.io/github/issues/Certseeds/algorithm-template.svg?style=for-the-badge [issues-url]: https://github.com/Certseeds/algorithm-template/issues -[license-shield]: https://img.shields.io/github/license/Certseeds/algorithm-template.svg?style=for-the-badge -[license-url]: https://github.com/Certseeds/algorithm-template/blob/master/LICENSE.md [release-shield]: https://img.shields.io/github/release/Certseeds/algorithm-template.svg?style=for-the-badge [release-url]: https://github.com/Certseeds/algorithm-template/releases [GitHub-Whexy]: https://github.com/whexy diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 5f1d9529..766b66ce 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -7,5 +7,5 @@ add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(${PROJECT_NAME} INTERFACE Catch2::Catch2WithMain) -target_compile_definitions(${PROJECT_NAME} INTERFACE ALGORITHM_TEST_MACRO) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} INTERFACE GTest::gtest_main GTest::gmock) +target_compile_definitions(${PROJECT_NAME} INTERFACE ALGORITHM_TEST_MACRO) diff --git a/include/catch_main.hpp b/include/catch_main.hpp deleted file mode 100644 index 07dff085..00000000 --- a/include/catch_main.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-or-later -// SPDX-FileCopyrightText: 2020-2025 nanoseeds -#ifndef ALGORITHM_TEMPLATE_INCLUDES_CATCH_MAIN_H -#define ALGORITHM_TEMPLATE_INCLUDES_CATCH_MAIN_H - -#include -#include -#include -#include -#include -#include -#include - -static const CS203_timer timer{}; - -#endif //ALGORITHM_TEMPLATE_INCLUDES_CATCH_MAIN_H diff --git a/include/gtest_main.hpp b/include/gtest_main.hpp new file mode 100644 index 00000000..3b5adc22 --- /dev/null +++ b/include/gtest_main.hpp @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +// SPDX-FileCopyrightText: 2020-2025 nanoseeds +#ifndef ALGORITHM_TEMPLATE_INCLUDES_GTEST_MAIN_H +#define ALGORITHM_TEMPLATE_INCLUDES_GTEST_MAIN_H + +#include +#include +#include + +static const CS203_timer timer{}; + +#endif //ALGORITHM_TEMPLATE_INCLUDES_GTEST_MAIN_H diff --git a/lab_00/A/CMakeLists.txt b/lab_00/A/CMakeLists.txt index 40897f09..7282668b 100644 --- a/lab_00/A/CMakeLists.txt +++ b/lab_00/A/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") enable_testing() add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME}_test ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp) target_compile_definitions(${PROJECT_NAME}_test PRIVATE ALGORITHM_TEST_MACRO) target_link_libraries(${PROJECT_NAME}_test PRIVATE algorithm_template_INCLUDE) diff --git a/lab_00/A/test.cpp b/lab_00/A/test.cpp index d809b2e7..e61c6f18 100644 --- a/lab_00/A/test.cpp +++ b/lab_00/A/test.cpp @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2020-2025 nanoseeds #ifdef ALGORITHM_TEST_MACRO -#include +#include #include #include #include @@ -21,36 +21,36 @@ using std::tie; using std::tuple; using std::vector; -TEST_CASE("test case 1", "[test 00 A]") { +TEST(lab_00_A, test_case_1) { const auto output1 = cal(std::make_tuple(0, 0)); auto output2 = cal(std::make_tuple(100000, 100000)); - CHECK_FALSE(output1); - CHECK(200000 == output2); + EXPECT_FALSE(output1); + EXPECT_EQ(200000, output2); } -TEST_CASE("test case 2", "[test 00 A]") { +TEST(lab_00_A, test_case_2) { auto output1 = cal(std::make_tuple(0, 100000)); auto output2 = cal(std::make_tuple(100000, 0)); - CHECK(100000 == output1); - CHECK(100000 == output2); + EXPECT_EQ(100000, output1); + EXPECT_EQ(100000, output2); } -TEST_CASE("test case 3", "[test 00 A]") { +TEST(lab_00_A, test_case_3) { std::random_device rd{}; const auto gen = std::mt19937{rd()}; const std::uniform_real_distribution<> dis{0, 100000}; auto randfun = std::bind(dis, gen); // 产生一个函数,返回0-10000的随机数 for (int i = 0; i < 20; i++) { const int a = randfun(), b = randfun(); - CHECK(cal(std::make_tuple(a, b)) == - cal(std::make_tuple(b, a))); // 确认对偶性 - CHECK(a + b == cal(std::make_tuple(a, b))); // 确认正确性 + EXPECT_EQ(cal(std::make_tuple(a, b)), + cal(std::make_tuple(b, a))); // 确认对偶性 + EXPECT_EQ(a + b, cal(std::make_tuple(a, b))); // 确认正确性 } } -TEST_CASE("test case 4", "[test 00 A]") { +TEST(lab_00_A, test_case_4) { const auto output = cal(std::make_tuple(100, 1000)); - CHECK(1100 == output); + EXPECT_EQ(1100, output); } } // namespace lab_00_A #endif // ALGORITHM_TEST_MACRO diff --git a/lab_00/B/CMakeLists.txt b/lab_00/B/CMakeLists.txt index dac0839a..cfb286b9 100644 --- a/lab_00/B/CMakeLists.txt +++ b/lab_00/B/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") enable_testing() add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME}_test ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp) target_compile_definitions(${PROJECT_NAME}_test PRIVATE ALGORITHM_TEST_MACRO) target_link_libraries(${PROJECT_NAME}_test PRIVATE algorithm_template_INCLUDE) diff --git a/lab_00/B/test.cpp b/lab_00/B/test.cpp index d5d7ec22..40ae1f14 100644 --- a/lab_00/B/test.cpp +++ b/lab_00/B/test.cpp @@ -3,7 +3,7 @@ #ifdef ALGORITHM_TEST_MACRO -#include +#include #include #include #include @@ -19,23 +19,19 @@ using std::cin; using std::cout; using std::tuple; using std::vector; -using Catch::Matchers::Equals; -using Catch::Matchers::UnorderedEquals; -using Catch::Matchers::Contains; -TEST_CASE("test case 1", "[test 00 B]") { +TEST(lab_00_B, test_case_1) { const auto vec1 = vector{8, 1, 2, 3, 4, 5, 6, 7, 1100000}; for (const auto &i: vec1) { - CHECK(cal(i) == brute_force(i)); + EXPECT_EQ(cal(i), brute_force(i)); } } -TEST_CASE("test case 2", "[test 00 B]") { +TEST(lab_00_B, test_case_2) { const auto vec1 = vector{1, 2, 3, 4, 5, 6, 7, 1100000}; const auto result = cal_warpper(vec1); const auto what_we_want = vector{1, 4, 10, 20, 35, 56, 84, 221833938333700000}; - CHECK_THAT(result, Equals({1, 4, 10, 20, 35, 56, 84, 221833938333700000})); - CHECK_THAT(result, Equals(what_we_want)); + EXPECT_EQ(result, what_we_want); } } #endif //ALGORITHM_TEST_MACRO diff --git a/lab_00/C/CMakeLists.txt b/lab_00/C/CMakeLists.txt index 62fbe7d9..32dbf05f 100644 --- a/lab_00/C/CMakeLists.txt +++ b/lab_00/C/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") enable_testing() add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME}_test ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp) target_compile_definitions(${PROJECT_NAME}_test PRIVATE ALGORITHM_TEST_MACRO) target_link_libraries(${PROJECT_NAME}_test PRIVATE algorithm_template_INCLUDE) diff --git a/lab_00/C/test.cpp b/lab_00/C/test.cpp index 0891a53b..7d76306d 100644 --- a/lab_00/C/test.cpp +++ b/lab_00/C/test.cpp @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2020-2025 nanoseeds #ifdef ALGORITHM_TEST_MACRO -#include +#include #include #include #include "main.cpp" @@ -17,47 +17,44 @@ using std::cin; using std::cout; using std::vector; -using Catch::Matchers::Equals; -using Catch::Matchers::UnorderedEquals; -using Catch::Matchers::Contains; /* * Test case 1 -> Test case 5 * 目的是为了展示只使用CS203_redirect的情况下 * 应该如何只重定向输入,不重定向输出. * */ -TEST_CASE("test case 1", "[test 00 C]") { +TEST(lab_00_C, test_case_1) { const CS203_redirect cr{"01.data.in", ""}; // 重定向开始,开始run const auto output_data = isBipartite(read()); // 重定向结束 - CHECK_FALSE(output_data); + EXPECT_FALSE(output_data); } -TEST_CASE("test case 2", "[test 00 C]") { +TEST(lab_00_C, test_case_2) { const CS203_redirect cr{"02.data.in"}; const auto output_data = isBipartite(read()); - CHECK(output_data); + EXPECT_TRUE(output_data); } -TEST_CASE("test case 3", "[test 00 C]") { +TEST(lab_00_C, test_case_3) { const CS203_redirect cr{"03.data.in"}; const auto output_data = isBipartite(read()); - CHECK(output_data); + EXPECT_TRUE(output_data); } -TEST_CASE("test case 4", "[test 00 C]") { +TEST(lab_00_C, test_case_4) { const CS203_redirect cr{"04.data.in"}; const auto output_data = isBipartite(read()); - CHECK_FALSE(output_data); + EXPECT_FALSE(output_data); } -TEST_CASE("test case 5", "[test 00 C]") { +TEST(lab_00_C, test_case_5) { const CS203_redirect cr{"05.data.in"}; const auto output_data = isBipartite(read()); - CHECK_FALSE(output_data); + EXPECT_FALSE(output_data); } /*目的在于展示,使用循环来精简Test case1~5中的工作量*/ -TEST_CASE("test case in loop", "[test 00 C]") { +TEST(lab_00_C, test_case_in_loop) { const vector strs{ "01.data.in", "02.data.in", "03.data.in", "04.data.in", @@ -67,11 +64,11 @@ TEST_CASE("test case in loop", "[test 00 C]") { for (int i = 0; i < 5; ++i) { const CS203_redirect cr{strs[i]}; const auto output_data = isBipartite(read()); - CHECK(output_data == result[i]); + EXPECT_EQ(output_data, result[i]); } } /*目的在于展示,std::tuple的打包能力*/ -TEST_CASE("test case with tuple", "[test 00 C]") { +TEST(lab_00_C, test_case_with_tuple) { const vector> input_result{ {"01.data.in", false}, {"02.data.in", true}, @@ -85,12 +82,12 @@ TEST_CASE("test case with tuple", "[test 00 C]") { tie(path, result) = tup; const CS203_redirect cr{path}; const auto output_data = isBipartite(read()); - CHECK(output_data == result); + EXPECT_EQ(output_data, result); } } /* 目的在于展示 CS203_sequence 生成重定向相关文件名的能力 * */ -TEST_CASE("test case with sequence", "[test 00 C]") { +TEST(lab_00_C, test_case_with_sequence) { CS203_sequence sequence{1, 5, 2}; // 前缀被默认设定为 空串 "" @@ -108,7 +105,7 @@ TEST_CASE("test case with sequence", "[test 00 C]") { main(); // 用括号括住是为了让CS203_redirect在这里被析构,停止重定向 } - CHECK(compareFiles(testout, dataout)); + EXPECT_TRUE(compareFiles(testout, dataout)); } } } diff --git a/lab_00/D/CMakeLists.txt b/lab_00/D/CMakeLists.txt index 564aeae5..b32e0619 100644 --- a/lab_00/D/CMakeLists.txt +++ b/lab_00/D/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") enable_testing() add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) add_executable(${PROJECT_NAME}_test ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp) target_compile_definitions(${PROJECT_NAME}_test PRIVATE ALGORITHM_TEST_MACRO) target_link_libraries(${PROJECT_NAME}_test PRIVATE algorithm_template_INCLUDE) diff --git a/lab_00/D/test.cpp b/lab_00/D/test.cpp index ad896791..f8ff6238 100644 --- a/lab_00/D/test.cpp +++ b/lab_00/D/test.cpp @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: 2020-2025 nanoseeds #ifdef ALGORITHM_TEST_MACRO -#include +#include #include #include #include "main.cpp" @@ -19,11 +19,7 @@ using std::tie; using std::tuple; using std::vector; -using Catch::Matchers::Contains; -using Catch::Matchers::Equals; -using Catch::Matchers::UnorderedEquals; - -TEST_CASE("test case 1", "[test 00 D]") { +TEST(lab_00_D, test_case_1) { const CS203_redirect cr{"01.data.in"}; // 重定向开始,开始run auto input_data = read(); @@ -31,14 +27,13 @@ TEST_CASE("test case 1", "[test 00 D]") { // 重定向结束 } -TEST_CASE("test case 2", "[test 00 D]") { - SECTION("do") { +TEST(lab_00_D, test_case_2) { + { const CS203_redirect cr{"01.data.in", "01.test.out"}; auto input_data = read(); cal(input_data); - }SECTION("compare files") { - CHECK(compareFiles("01.test.out", "01.data.out")); } + EXPECT_TRUE(compareFiles("01.test.out", "01.data.out")); } } // namespace lab_00_D diff --git a/package.json b/package.json new file mode 100644 index 00000000..31bc73ac --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "algorithm-template", + "version": "1.0.0", + "description": "", + "main": "index.js", + "keywords": [], + "author": "", + "license": "AGPL-3.0-or-later", + "packageManager": "pnpm@10.33.4", + "devDependencies": { + "@anthropic-ai/claude-code": "^2.1.212" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 00000000..f48b3b95 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,101 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + devDependencies: + '@anthropic-ai/claude-code': + specifier: ^2.1.212 + version: 2.1.212 + +packages: + + '@anthropic-ai/claude-code-darwin-arm64@2.1.212': + resolution: {integrity: sha512-QjQwqJU5XzAl1mdlnY+hQxK/pGx6/0q59BfHWiKsSeLyMBpK9avgwu+kap8kzSigSEdbo1rIABO8t2EKqzvvaA==} + cpu: [arm64] + os: [darwin] + + '@anthropic-ai/claude-code-darwin-x64@2.1.212': + resolution: {integrity: sha512-dHnDk1jQHP1xG5hMEHHvgYqXHcgBapH/s1whqDw4KlAOxycgZKd4s2YQbRuygb7HNEpTLBnnLue5+Zv+RCfLzw==} + cpu: [x64] + os: [darwin] + + '@anthropic-ai/claude-code-linux-arm64-musl@2.1.212': + resolution: {integrity: sha512-OmNXhGKaf1F3XrqYL5GnMIAFMv4Og3H4ehEREX6JLiZU2AC3ckyPawqvvhqyhoJx+a6KN59+6rEC97DyQMgo5Q==} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@anthropic-ai/claude-code-linux-arm64@2.1.212': + resolution: {integrity: sha512-PcQptwO1t9q6tkL41yjmf5jxLU7Kzce4apW6KzuDvffN8ueKzGfR+9PecyQt2W1/dD2x1fAhWjAaQA6XiP2SyQ==} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@anthropic-ai/claude-code-linux-x64-musl@2.1.212': + resolution: {integrity: sha512-AXkXlvUd/SWydG8XSEIKgq0fUHh/5+zdVj43mv+Fv0+p3Yv3vc528+tQo0NPGH3fU0weVYHarII69TgRQasP1w==} + cpu: [x64] + os: [linux] + libc: [musl] + + '@anthropic-ai/claude-code-linux-x64@2.1.212': + resolution: {integrity: sha512-NCJ/EHcC1QfAm7EUH/F5m+cE6QQO5fhceCxtnySpFu0T4+eq6tORcJcbUY/bHGsKKa8MiAmjyv3nXFWnV5h/oA==} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@anthropic-ai/claude-code-win32-arm64@2.1.212': + resolution: {integrity: sha512-SYh28kyBjPj5HYnRJ6FSK7tAGxXip2qemGo15N1V31KBQVqPgt67vvCI4E8k1+7yeCV31j3mpq6pBJi+1LDFHw==} + cpu: [arm64] + os: [win32] + + '@anthropic-ai/claude-code-win32-x64@2.1.212': + resolution: {integrity: sha512-Fz/A6+V1ezafl/Zk9DMLTpoc9yVSdUf5UT0ZNBp6m0y1PwRyq7EMXlGh9V8O+Cb5/qPJF5K01onArNkYczSjbg==} + cpu: [x64] + os: [win32] + + '@anthropic-ai/claude-code@2.1.212': + resolution: {integrity: sha512-MEasj1oaoARRKEWU7eHJ6DWC2TC8ogml9QUDihbmxYI2Ij5Ol1leW90DIj8/a0xX3lfHZOwT3gJr0JxVKa8Sxw==} + engines: {node: '>=22.0.0'} + hasBin: true + +snapshots: + + '@anthropic-ai/claude-code-darwin-arm64@2.1.212': + optional: true + + '@anthropic-ai/claude-code-darwin-x64@2.1.212': + optional: true + + '@anthropic-ai/claude-code-linux-arm64-musl@2.1.212': + optional: true + + '@anthropic-ai/claude-code-linux-arm64@2.1.212': + optional: true + + '@anthropic-ai/claude-code-linux-x64-musl@2.1.212': + optional: true + + '@anthropic-ai/claude-code-linux-x64@2.1.212': + optional: true + + '@anthropic-ai/claude-code-win32-arm64@2.1.212': + optional: true + + '@anthropic-ai/claude-code-win32-x64@2.1.212': + optional: true + + '@anthropic-ai/claude-code@2.1.212': + optionalDependencies: + '@anthropic-ai/claude-code-darwin-arm64': 2.1.212 + '@anthropic-ai/claude-code-darwin-x64': 2.1.212 + '@anthropic-ai/claude-code-linux-arm64': 2.1.212 + '@anthropic-ai/claude-code-linux-arm64-musl': 2.1.212 + '@anthropic-ai/claude-code-linux-x64': 2.1.212 + '@anthropic-ai/claude-code-linux-x64-musl': 2.1.212 + '@anthropic-ai/claude-code-win32-arm64': 2.1.212 + '@anthropic-ai/claude-code-win32-x64': 2.1.212 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 00000000..7cdd8388 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +allowBuilds: + '@anthropic-ai/claude-code': true diff --git a/script/cmake_level2_template.txt b/script/cmake_level2_template.txt index 0482182b..00d3685c 100644 --- a/script/cmake_level2_template.txt +++ b/script/cmake_level2_template.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${{CMAKE_CXX_FLAGS}}") enable_testing() add_executable(${{PROJECT_NAME}} ${{CMAKE_CURRENT_SOURCE_DIR}}/main.cpp) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) add_executable(${{PROJECT_NAME}}_test ${{CMAKE_CURRENT_SOURCE_DIR}}/test.cpp) target_compile_definitions(${{PROJECT_NAME}}_test PRIVATE ALGORITHM_TEST_MACRO) target_link_libraries(${{PROJECT_NAME}}_test PRIVATE diff --git a/script/container.sh b/script/container.sh new file mode 100644 index 00000000..92a893be --- /dev/null +++ b/script/container.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euox pipefail +main() { + local SOURCE="ghcr.io" + local GH_USERNAME="certseeds" + local IMAGE_NAME="develop" + local RUNTIME_NAME="algorithm-cpp-dev" + local dotfiles="${DOTFILES_DIR}" + # 请确认环境内存在 USERNAME, DOTFILES_DIR 这两个变量 + # 请确认环境内指定路径上有 cc 的配置文件 + podman run \ + --userns=keep-id:uid=1001 \ + -dit \ + -e HTTP_PROXY="" \ + -e HTTPS_PROXY="" \ + -e http_proxy="" \ + -e https_proxy="" \ + --name "${RUNTIME_NAME}" \ + -v $(pwd):/home/${USERNAME}/repo/algorithm-template \ + -v algorithm-cpp-venv:/home/${USERNAME}/repo/algorithm-template/.venv \ + -v algorithm-cpp-node-modules:/home/${USERNAME}/repo/algorithm-template/node_modules \ + -v algorithm-cpp-pnpm:/home/${USERNAME}/repo/algorithm-template/.pnpm-store \ + -v algorithm-cpp-cmake-build-debug:/home/${USERNAME}/repo/algorithm-template/cmake-build-debug \ + -v algorithm-cpp-cmake-build-release:/home/${USERNAME}/repo/algorithm-template/cmake-build-release \ + -v algorithm-cpp-claude:/home/${USERNAME}/.claude/ \ + "${SOURCE}/${GH_USERNAME}/${IMAGE_NAME}:latest" + podman cp "${dotfiles}"/lang/agents/cc.json "${RUNTIME_NAME}":/home/${USERNAME}/.claude/settings.json + + # run pnpm setup + # vim the claude code settings.json, to enable allow-dangerous tasks +} +main diff --git a/script/cpp_test_template.txt b/script/cpp_test_template.txt index 8284bc0c..3c8bbd38 100644 --- a/script/cpp_test_template.txt +++ b/script/cpp_test_template.txt @@ -1,6 +1,6 @@ #ifdef ALGORITHM_TEST_MACRO -#include +#include #include #include #include @@ -20,23 +20,15 @@ using std::cout; using std::tuple; using std::vector; -using Catch::Matchers::Equals; -using Catch::Matchers::UnorderedEquals; -using Catch::Matchers::Contains; - -TEST_CASE("test case 1", "[test {0}_{1}]") {{ +TEST(lab_{0}_{1}, test_case_1) {{ const auto output_data = cal(std::make_tuple(114, 514)); - CHECK(output_data == 628); - CHECK(1 + 2 == 3); - vector vec{{2, 7, 11, 15}}; - SECTION("CHECK_THAT 1") {{ - CHECK_THAT(vec, Contains({{2}})); - }}SECTION("vec matcher") {{ - CHECK_THAT(vec, UnorderedEquals({{15, 11, 7, 2}})); - }} + EXPECT_EQ(output_data, 628); + EXPECT_EQ(1 + 2, 3); + vector vec{{2, 7, 11, 15}}; + EXPECT_THAT(vec, ::testing::Contains(2)); + EXPECT_THAT(vec, ::testing::UnorderedElementsAre(15, 11, 7, 2)); }} -// CatchV3似乎不再支持[.]隐藏, 因此将sequence置为[1,0],隐藏输入 -TEST_CASE("test case with sequence", "[test {0}_{1}]") {{ +TEST(lab_{0}_{1}, test_case_with_sequence) {{ CS203_sequence sequence{{1, 0, 0}}; // // 基础设定,[1,1] sequence.set_postfix_of_datain("data.in"); // 输入数据后缀,默认为 data.in sequence.set_postfix_of_dataout("data.out"); // except输出数据后缀,默认为 data.out @@ -52,7 +44,7 @@ TEST_CASE("test case with sequence", "[test {0}_{1}]") {{ main(); // 用括号括住是为了让CS203_redirect在这里被析构,停止重定向 }} - CHECK(compareFiles(testout, dataout)); + EXPECT_TRUE(compareFiles(testout, dataout)); }} }} }} diff --git a/third_party/.gitattributes b/third_party/.gitattributes deleted file mode 100644 index 143919d0..00000000 --- a/third_party/.gitattributes +++ /dev/null @@ -1,7 +0,0 @@ -### - # @Author: nanoseeds - # @Date: 2021-01-28 16:49:38 - # @LastEditors: nanoseeds - # @LastEditTime: 2021-01-28 16:50:01 -### -* linguist-vendored diff --git a/third_party/.gitignore b/third_party/.gitignore deleted file mode 100644 index 62851048..00000000 --- a/third_party/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -* -!.gitattributes -!.gitignore -!CMakeLists.txt -!CMakeLists.release.txt -!README.md -!install.sh -!rename.sh diff --git a/third_party/CMakeLists.release.txt b/third_party/CMakeLists.release.txt deleted file mode 100644 index d5d2cf67..00000000 --- a/third_party/CMakeLists.release.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.16.6) -project(CS203_CATCH2_LIB) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -set("BUILD_${LIB_WAY}_LIBS" YES) - -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/catch2) \ No newline at end of file diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt deleted file mode 100644 index 409468dc..00000000 --- a/third_party/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.16.6) -project(CS203_CATCH2_LIB) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -set("BUILD_${LIB_WAY}_LIBS" YES) - -include(FetchContent) -CMAKE_CMP_0135() - -set(CATCH2_HASH "7e64ff8a07b324996a26f3f5d7e7dad8") -set(CATCH2_LOCAL_TAR ${CMAKE_CURRENT_SOURCE_DIR}/catch.3.13.0.tar.gz) - -message(STATUS "Using local Catch2 tarball: ${CATCH2_LOCAL_TAR}") - -# 现在只使用 file:// 协议让 FetchContent 从本地 archive 加载 -get_filename_component(_abs_tar ${CATCH2_LOCAL_TAR} ABSOLUTE) -file(TO_CMAKE_PATH ${_abs_tar} _tar_unix) # 在 Windows 上转换路径分隔 - -FetchContent_Declare( - Catch2 - URL file://${_tar_unix} - URL_HASH MD5=${CATCH2_HASH} - SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/catch2 -) - -FetchContent_MakeAvailable(Catch2) -unset(CATCH2_HASH) -unset(CATCH2_LOCAL_TAR) -unset(_abs_str) -unset(_tar_unix) diff --git a/third_party/README.md b/third_party/README.md deleted file mode 100644 index c4f353cb..00000000 --- a/third_party/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# 第三方依赖 - -## catch2 - -由于网络问题, cmake加载远程url不稳定, 因此需要下载catch2的压缩包到`third_party`目录下供读取 diff --git a/third_party/install.sh b/third_party/install.sh deleted file mode 100644 index 3cd8a7b6..00000000 --- a/third_party/install.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -euox pipefail -main() { - wget -O ./third_party/catch.3.13.0.tar.gz \ - "https://github.com/catchorg/Catch2/archive/refs/tags/v3.13.0.tar.gz" -} -main diff --git a/third_party/rename.sh b/third_party/rename.sh deleted file mode 100644 index 2bb6efbf..00000000 --- a/third_party/rename.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -set -euox pipefail -main() { - tar \ - -xzvf third_party/catch.3.13.0.tar.gz \ - -C third_party/ - # 定位到脚本所在目录(third_party) - local -r self_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - local -r tp_dir="$self_dir" - - # 开启大小写不敏感匹配以识别 Catch-/catch- - for path in "$tp_dir"/*; do - [[ -d "$path" ]] || continue - local name="$(basename -- "$path")" - - if [[ "$name" == Catch2* ]]; then - mv "./third_party/$name" "./third_party/catch2" - echo "Renamed '$name' -> 'catch2'" - exit 0 - fi - done -} -main