u01/tests: Extract get_node_id function
This commit is contained in:
parent
c2804e2d3b
commit
8ea29904ea
|
@ -3,6 +3,16 @@
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
|
int get_node_id(node *n) {
|
||||||
|
// TODO: ensure the test calling this starts at node_id 0 (currently this is
|
||||||
|
// undefined based on order the tests are run)
|
||||||
|
// for the time being, this gets the offset
|
||||||
|
int id = std::stoi(n->get_name().substr(5));
|
||||||
|
// this tests if the node id was correctly extracted
|
||||||
|
REQUIRE(n->get_name() == "node_" + std::to_string(id));
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Name") {
|
TEST_CASE("Name") {
|
||||||
node *n = new node("test");
|
node *n = new node("test");
|
||||||
REQUIRE(n->get_name() == "test");
|
REQUIRE(n->get_name() == "test");
|
||||||
|
@ -37,11 +47,7 @@ TEST_CASE("Get children") {
|
||||||
TEST_CASE("Global node counting") {
|
TEST_CASE("Global node counting") {
|
||||||
node *n = new node();
|
node *n = new node();
|
||||||
|
|
||||||
// TODO: ensure this test starts at node_id 0 (currently this is undefined
|
const int node_id_start = get_node_id(n);
|
||||||
// based on order the tests are run) for the time being, this gets the offset
|
|
||||||
int node_id_start = std::stoi(n->get_name().substr(5));
|
|
||||||
// this tests if the node id was correctly extracted
|
|
||||||
REQUIRE(n->get_name() == "node_" + std::to_string(node_id_start));
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 5; i++) {
|
for (std::size_t i = 0; i < 5; i++) {
|
||||||
n->add_child(new node());
|
n->add_child(new node());
|
||||||
|
|
Reference in a new issue