@@ -133,7 +133,70 @@ TEST_CASE("Graph node operations", "[NODE]") {
133133}
134134
135135
136- TEST_CASE (" Node creation" ,
136+ TEST_CASE (" Insert node with specific id" , " [NODE]" ) {
137+
138+ auto filename = make_empty_config_file ();
139+ DSRGraph G (random_string (10 ), rand () % 1200 , filename);
140+
141+ SECTION (" Insert a node with a specific id" ) {
142+ auto node_name = random_string ();
143+ uint64_t specific_id = 5000 ;
144+ auto n = Node::create<testtype_node_type>(node_name);
145+ n.id (specific_id);
146+ std::optional<uint64_t > r = G.insert_node_with_id (n);
147+ REQUIRE (r.has_value ());
148+ REQUIRE (r.value () == specific_id);
149+ std::optional<Node> retrieved = G.get_node (specific_id);
150+ REQUIRE (retrieved.has_value ());
151+ REQUIRE (retrieved->name () == node_name);
152+ }
153+
154+ SECTION (" Insert a node with a duplicate id fails" ) {
155+ auto n1 = Node::create<testtype_node_type>(random_string ());
156+ uint64_t specific_id = 6000 ;
157+ n1.id (specific_id);
158+ std::optional<uint64_t > r1 = G.insert_node_with_id (n1);
159+ REQUIRE (r1.has_value ());
160+
161+ auto n2 = Node::create<testtype_node_type>(random_string ());
162+ n2.id (specific_id);
163+ std::optional<uint64_t > r2 = G.insert_node_with_id (n2);
164+ REQUIRE_FALSE (r2.has_value ());
165+ }
166+
167+ SECTION (" Insert a node with empty name generates a name" ) {
168+ uint64_t specific_id = 7000 ;
169+ auto n = Node::create<testtype_node_type>(" " );
170+ n.id (specific_id);
171+ std::optional<uint64_t > r = G.insert_node_with_id (n);
172+ REQUIRE (r.has_value ());
173+ std::optional<Node> retrieved = G.get_node (specific_id);
174+ REQUIRE (retrieved.has_value ());
175+ REQUIRE_FALSE (retrieved->name ().empty ());
176+ }
177+
178+ SECTION (" Insert a node with a duplicate name generates a new name" ) {
179+ auto shared_name = random_string ();
180+ uint64_t id1 = 8000 , id2 = 8001 ;
181+
182+ auto n1 = Node::create<testtype_node_type>(shared_name);
183+ n1.id (id1);
184+ std::optional<uint64_t > r1 = G.insert_node_with_id (n1);
185+ REQUIRE (r1.has_value ());
186+
187+ auto n2 = Node::create<testtype_node_type>(shared_name);
188+ n2.id (id2);
189+ std::optional<uint64_t > r2 = G.insert_node_with_id (n2);
190+ REQUIRE (r2.has_value ());
191+
192+ std::optional<Node> retrieved = G.get_node (id2);
193+ REQUIRE (retrieved.has_value ());
194+ REQUIRE (retrieved->name () != shared_name);
195+ }
196+ }
197+
198+
199+ TEST_CASE (" Node creation" ,
137200 " [Node]" ) {
138201
139202
0 commit comments