Skip to content

Scene/unit Unit test additions and some duplicate items and bug cleanup#19

Merged
CoraBlack merged 5 commits intogkit-org:scene/unitfrom
17-qxm:scene/unit
Feb 23, 2026
Merged

Scene/unit Unit test additions and some duplicate items and bug cleanup#19
CoraBlack merged 5 commits intogkit-org:scene/unitfrom
17-qxm:scene/unit

Conversation

@17-qxm
Copy link
Copy Markdown
Contributor

@17-qxm 17-qxm commented Feb 21, 2026

Unit test additions and some duplicate items and bug cleanup

Copy link
Copy Markdown

@moyichen0219 moyichen0219 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of the iterator and the corresponding unit tests look solid. The test covers forward, reverse, and const iterations, which is great.
Nit: In the const iteration part of test_iterator, I'd suggest explicitly using const auto& u to verify that the const_iterator indeed returns a read-only reference.
This is just a minor improvement and shouldn't block the merge. Approved!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds unit tests for the Unit iterator functionality and fixes const-correctness issues in the iterator implementation. The changes address both bug fixes (incorrect const qualifier placement) and code cleanup (removing duplicate type alias declarations).

Changes:

  • Fixed const qualifier placement in iterator operators from -> reference const to const -> reference for proper const member function syntax
  • Removed duplicate using declarations for reverse iterators from unit.cpp (they already exist in unit.hpp)
  • Added comprehensive iterator unit tests covering forward iteration, reverse iteration, increment/decrement operators, and const iterators

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.

File Description
test/core/scene/test_unit_iterator.cpp New comprehensive test file for Unit iterator functionality including forward/reverse iteration and const correctness
src/core/scene/unit.cpp Fixed const qualifier placement in iterator operators and removed duplicate reverse_iterator type alias declarations
src/core/include/scene/unit.hpp Fixed const qualifier placement in iterator operator declarations and improved code formatting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

int exit_calls = 0;
std::string name_storage;

// 自定义构造函数
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is in Chinese ("自定义构造函数" means "Custom constructor"). For consistency and accessibility, consider using English for all code comments, matching the convention in the rest of the codebase (e.g., test/core/scene/test_unit.cpp uses English comments).

Copilot uses AI. Check for mistakes.
Comment on lines +91 to +96
it++;
TEST(&(*it) == children[2], "post-increment");
--it;
TEST(&(*it) == children[1], "pre-decrement");
it--;
TEST(&(*it) == children[0], "post-decrement");
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for post-increment and post-decrement operators doesn't verify the return value. Post-increment (it++) should return the iterator value before incrementing. The test should verify both that the returned value points to the correct element AND that the iterator itself was incremented. Consider: "auto old_it = it++; TEST(&(*old_it) == children[1], "post-increment returns old value"); TEST(&(*it) == children[2], "post-increment advances iterator");"

Suggested change
it++;
TEST(&(*it) == children[2], "post-increment");
--it;
TEST(&(*it) == children[1], "pre-decrement");
it--;
TEST(&(*it) == children[0], "post-decrement");
auto old_it = it++;
TEST(&(*old_it) == children[1], "post-increment returns old value");
TEST(&(*it) == children[2], "post-increment advances iterator");
auto old_it2 = it--;
TEST(&(*old_it2) == children[2], "post-decrement returns old value");
TEST(&(*it) == children[1], "post-decrement moves iterator back");
--it;
TEST(&(*it) == children[0], "pre-decrement");

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +105
bool test_iterator() {
std::cout << "\n=== test_iterator ===\n";
auto parent = TestUnit::create("parent");
std::vector<TestUnit*> children;
for (int i = 0; i < 5; ++i) {
auto child = TestUnit::create("child" + std::to_string(i));
children.push_back(child.get());
parent->add_child(std::move(child));
}
parent->process_handler();

int idx = 0;
for (auto& u : *parent) {
TEST(&u == children[idx], "iterator order matches addition");
idx++;
}
TEST(idx == 5, "iterated all 5 children");

idx = 4;
for (auto it = parent->rbegin(); it != parent->rend(); ++it) {
TEST(&(*it) == children[idx], "reverse iterator order");
idx--;
}
TEST(idx == -1, "reverse iterated all");

auto it = parent->begin();
++it;
TEST(&(*it) == children[1], "pre-increment");
it++;
TEST(&(*it) == children[2], "post-increment");
--it;
TEST(&(*it) == children[1], "pre-decrement");
it--;
TEST(&(*it) == children[0], "post-decrement");

const auto& const_parent = *parent;
idx = 0;
for (auto& u : const_parent) {
TEST(&u == children[idx], "const iterator works");
idx++;
}
return true;
}
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't verify iterator behavior with an empty parent (zero children). Consider adding a test case that verifies begin() == end() when a Unit has no children, to ensure the iterator handles this edge case correctly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you can help me, plz tell me what should I do?

Copy link
Copy Markdown
Contributor

@CoraBlack CoraBlack Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you can help me, plz tell me what should I do?

It won't response to you, please read the requirement from copilot carefully

@17-qxm
Copy link
Copy Markdown
Contributor Author

17-qxm commented Feb 22, 2026

The implementation of the iterator and the corresponding unit tests look solid. The test covers forward, reverse, and const iterations, which is great. Nit: In the const iteration part of test_iterator, I'd suggest explicitly using const auto& u to verify that the const_iterator indeed returns a read-only reference. This is just a minor improvement and shouldn't block the merge. Approved!

OK, I will try to deal with the suggestions.

This program is also maintenance by another group which named Code-landscape, and it also will have it's website called codelandscape.icu and The domain name is now under review. and it also have a QQ group chat and group owner is Cora Black. If you are interested in it, you can try to use 1084782596 to join the QQ group.

CoraBlack and others added 4 commits February 22, 2026 23:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CoraBlack CoraBlack merged commit 441fa8b into gkit-org:scene/unit Feb 23, 2026
10 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in libgkit-dev-plan Feb 23, 2026
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.

4 participants