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
ad57a986
Commit
ad57a986
authored
1 year ago
by
Maxime Lalisse
Browse files
Options
Downloads
Patches
Plain Diff
q3: decorators
parent
73a65549
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_gnt.cpp
+77
-0
77 additions, 0 deletions
test/test_gnt.cpp
with
77 additions
and
0 deletions
test/test_gnt.cpp
+
77
−
0
View file @
ad57a986
...
...
@@ -107,3 +107,80 @@ SCENARIO("Shortest paths", "[graph nt]")
}
}
}
class
EdgeData
{
std
::
string
str
;
double
l
;
public:
void
set_string
(
const
std
::
string
&
s
)
{
str
=
s
;
}
std
::
string
get_string
()
const
{
return
str
;
}
void
set_length
(
double
len
)
{
l
=
len
;
}
double
get_length
(
double
len
)
const
{
return
l
;
}
};
SCENARIO
(
"Decorators"
,
"[graph nt]"
)
{
GIVEN
(
"A graph with some items"
)
{
Graph
<
string
,
EdgeData
>
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"
);
EdgeData
_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
);
EdgeData
__ab
=
g
.
get_edge_data
(
ab
);
EdgeData
__ac
=
g
.
get_edge_data
(
ac
);
EdgeData
__cd
=
g
.
get_edge_data
(
cd
);
EdgeData
__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
);
EdgeData
_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