Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coa-tp4-graphs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxime Lalisse
coa-tp4-graphs
Commits
7313fa2d
Commit
7313fa2d
authored
1 year ago
by
Maxime Lalisse
Browse files
Options
Downloads
Patches
Plain Diff
Q6
parent
e2e6db93
Branches
main
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/graph_t.hpp
+20
-0
20 additions, 0 deletions
include/graph_t.hpp
test/test_gnt
+0
-0
0 additions, 0 deletions
test/test_gnt
test/test_gnt.cpp
+68
-0
68 additions, 0 deletions
test/test_gnt.cpp
with
88 additions
and
0 deletions
include/graph_t.hpp
+
20
−
0
View file @
7313fa2d
...
...
@@ -85,6 +85,26 @@ public:
}
}
Graph
deep_copy
()
const
{
Graph
copy
;
for
(
const
auto
&
[
id
,
node
]
:
nodes
)
{
copy
.
nodes
[
id
]
=
Node
{
id
,
std
::
make_shared
<
ND
>
(
*
node
.
data
)};
}
for
(
const
auto
&
[
id
,
edge
]
:
edges
)
{
copy
.
edges
[
id
]
=
Edge
{
id
,
edge
.
source_id
,
edge
.
dest_id
,
std
::
make_shared
<
ED
>
(
*
edge
.
data
)};
}
for
(
const
auto
&
[
source
,
dests
]
:
dests
)
{
copy
.
dests
[
source
]
=
std
::
vector
<
int
>
();
for
(
auto
d
:
dests
)
{
copy
.
dests
[
source
].
push_back
(
d
);
}
}
return
copy
;
}
inline
int
add_node
(
const
ND
&
m
)
{
Node
node
;
node
.
node_id
=
id_counter
;
...
...
This diff is collapsed.
Click to expand it.
test/test_gnt
+
0
−
0
View file @
7313fa2d
No preview for this file type
This diff is collapsed.
Click to expand it.
test/test_gnt.cpp
+
68
−
0
View file @
7313fa2d
...
...
@@ -179,3 +179,71 @@ SCENARIO("Decorators", "[graph t]")
}
}
}
// Test deep copy
SCENARIO
(
"Deep copy"
,
"[graph t]"
)
{
GIVEN
(
"A graph with some items"
)
{
Graph
<
string
,
EdgeProps
>
g
;
int
a
=
g
.
add_node
(
"A"
);
int
b
=
g
.
add_node
(
"B"
);
int
c
=
g
.
add_node
(
"C"
);
int
d
=
g
.
add_node
(
"D"
);
EdgeProps
_ab
,
_ac
,
_bd
,
_cd
;
_ab
.
set_string
(
"msg-ab"
);
_ac
.
set_string
(
"msg-ac"
);
_bd
.
set_string
(
"msg-bd"
);
_cd
.
set_string
(
"msg-cd"
);
_ab
.
set_length
(
1.0
);
_ac
.
set_length
(
2.0
);
_bd
.
set_length
(
3.0
);
_cd
.
set_length
(
4.0
);
int
ab
=
g
.
add_edge
(
_ab
,
a
,
b
);
int
ac
=
g
.
add_edge
(
_ac
,
a
,
c
);
int
bd
=
g
.
add_edge
(
_bd
,
b
,
d
);
int
cd
=
g
.
add_edge
(
_cd
,
c
,
d
);
REQUIRE
(
*
g
.
get_node_data
(
a
)
==
"A"
);
REQUIRE
(
*
g
.
get_node_data
(
b
)
==
"B"
);
REQUIRE
(
*
g
.
get_node_data
(
c
)
==
"C"
);
REQUIRE
(
*
g
.
get_node_data
(
d
)
==
"D"
);
REQUIRE
(
ab
==
0
);
REQUIRE
(
ac
==
1
);
EdgeProps
__ab
=
*
g
.
get_edge_data
(
ab
);
EdgeProps
__ac
=
*
g
.
get_edge_data
(
ac
);
EdgeProps
__cd
=
*
g
.
get_edge_data
(
cd
);
EdgeProps
__bd
=
*
g
.
get_edge_data
(
bd
);
REQUIRE
(
__ab
.
get_string
()
==
"msg-ab"
);
REQUIRE
(
__ac
.
get_string
()
==
"msg-ac"
);
REQUIRE
(
__cd
.
get_string
()
==
"msg-cd"
);
REQUIRE
(
__bd
.
get_string
()
==
"msg-bd"
);
vector
<
int
>
succ_a
=
{
b
,
c
};
REQUIRE
(
g
.
get_successors
(
a
)
==
succ_a
);
vector
<
int
>
succ_b
=
{
d
};
REQUIRE
(
g
.
get_successors
(
b
)
==
succ_b
);
vector
<
int
>
prec_d
=
{
b
,
c
};
REQUIRE
(
g
.
get_predecessors
(
d
)
==
prec_d
);
WHEN
(
"Copying the graph"
)
{
Graph
g1
(
g
);
THEN
(
"We obtain the same graph, with the same indexes"
)
{
REQUIRE
(
g1
.
get_predecessors
(
d
)
==
prec_d
);
}
}
WHEN
(
"Changing the copy"
)
{
Graph
g2
(
g
);
EdgeProps
_bc
;
_bc
.
set_string
(
"msg-bc"
);
_bc
.
set_length
(
5.0
);
g2
.
add_edge
(
_bc
,
b
,
c
);
THEN
(
"The original is not changed"
)
{
REQUIRE
(
g
.
get_successors
(
b
).
size
()
==
1
);
REQUIRE
(
g2
.
get_successors
(
b
).
size
()
==
2
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment