Skip to content

feat: 資料結構練習場 src/ds (doctest + ctest)#1

Open
GenYuLi wants to merge 1 commit into
mainfrom
feat/ds-playground
Open

feat: 資料結構練習場 src/ds (doctest + ctest)#1
GenYuLi wants to merge 1 commit into
mainfrom
feat/ds-playground

Conversation

@GenYuLi

@GenYuLi GenYuLi commented Jun 10, 2026

Copy link
Copy Markdown
Owner

對應 rust playground 的 src/ds/,建一個 header-only 的資料結構練習場:每個結構一個資料夾,旁邊放 doctest 測試,ctest 一鍵全跑(≈ cargo test)。

內容

  • ds.hpp umbrella header(≈ rust 的 ds/mod.rs)+ ds_test_main.cpp(唯一的 doctest main TU)
  • tree/ —— BinarySearchTree 作為已實作 + 已測試的範例(3 個 TEST_CASE 通過)
  • graph/ trie/ list/ —— 骨架:class 外形 + 預期 API 的 TODO 註解,測試以 doctest::skip() 跳過,實作與測試內容留白待補
  • CMakeLists.txt
    • FetchContent 接 doctest(用 SOURCE_SUBDIR 跳過其過舊的 CMakeLists,自建 interface target)
    • GLOB_RECURSE ... CONFIGURE_DEPENDS 自動收 src/ds/**/*_test.cpp 進單一 ds_tests,掛上 ctest
  • src/ds/README.md 說明用法與如何新增結構

怎麼跑

cmake -S . -B build
cmake --build build --target ds_tests
ctest --test-dir build --output-on-failure

驗證

乾淨 build 目錄下 configure / build / ctest 全綠:BST 三個測試跑、三個骨架 skip,100% tests passed

備註

  • 新增結構:開 xxx/xxx.hpp + xxx/xxx_test.cpp,不用改 CMake(GLOB 自動收)。
  • 既有的 build/ 內 CMakeCache 存的是舊 gcc 路徑(先前就存在),重建一次即可:rm -rf build && direnv exec . cmake -S . -B build

🤖 Generated with Claude Code

對應 rust playground 的 src/ds:header-only 資料結構練習場,
每個結構一個資料夾,旁邊放 doctest 測試,ctest 一鍵全跑 (≈ cargo test)。

- ds.hpp umbrella header(≈ ds/mod.rs)+ ds_test_main.cpp
- tree/ 以 BinarySearchTree 作為已實作 + 已測試的範例
- graph/ trie/ list/ 為骨架:class 外形 + 預期 API 的 TODO,
  測試以 doctest::skip() 跳過,留給之後填實作
- CMake: FetchContent 接 doctest(SOURCE_SUBDIR 跳過其過舊 CMakeLists,
  自建 interface target),GLOB_RECURSE 收 *_test.cpp 進 ds_tests,掛上 ctest
- src/ds/README.md 說明用法

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant