Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI
Commits
628678f5
Commit
628678f5
authored
3 years ago
by
Gino Valente
Browse files
Options
Downloads
Patches
Plain Diff
Added depth calc test
parent
34a4b7dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kayak_core/src/tree.rs
+52
-0
52 additions, 0 deletions
kayak_core/src/tree.rs
with
52 additions
and
0 deletions
kayak_core/src/tree.rs
+
52
−
0
View file @
628678f5
...
@@ -1188,6 +1188,58 @@ mod tests {
...
@@ -1188,6 +1188,58 @@ mod tests {
assert_eq!
(
expected
,
tree
);
assert_eq!
(
expected
,
tree
);
}
}
#[test]
fn
should_recalculate_depths
()
{
let
a
=
Index
::
from_raw_parts
(
0
,
0
);
let
b
=
Index
::
from_raw_parts
(
1
,
0
);
let
c
=
Index
::
from_raw_parts
(
2
,
0
);
let
d
=
Index
::
from_raw_parts
(
3
,
0
);
let
mut
expected
=
Tree
::
default
();
expected
.add
(
a
,
None
);
expected
.add
(
b
,
Some
(
a
));
expected
.add
(
c
,
Some
(
b
));
expected
.add
(
d
,
Some
(
c
));
// Test: Reverse-insertion order and recalculate from root
let
mut
tree
=
Tree
::
default
();
tree
.add
(
c
,
Some
(
b
));
tree
.add
(
b
,
Some
(
a
));
tree
.add
(
d
,
Some
(
c
));
tree
.add
(
a
,
None
);
assert_eq!
(
expected
.root_node
,
tree
.root_node
);
assert_eq!
(
expected
.parents
,
tree
.parents
);
assert_eq!
(
expected
.children
,
tree
.children
);
assert_ne!
(
expected
.depths
,
tree
.depths
);
tree
.recalculate_depths
(
None
);
assert_eq!
(
expected
.root_node
,
tree
.root_node
);
assert_eq!
(
expected
.parents
,
tree
.parents
);
assert_eq!
(
expected
.children
,
tree
.children
);
assert_eq!
(
expected
.depths
,
tree
.depths
);
// Test: Swapped insertions and recalculate from parent
let
mut
tree
=
Tree
::
default
();
tree
.add
(
a
,
None
);
tree
.add
(
b
,
Some
(
a
));
tree
.add
(
d
,
Some
(
c
));
tree
.add
(
c
,
Some
(
b
));
assert_eq!
(
expected
.root_node
,
tree
.root_node
);
assert_eq!
(
expected
.parents
,
tree
.parents
);
assert_eq!
(
expected
.children
,
tree
.children
);
assert_ne!
(
expected
.depths
,
tree
.depths
);
tree
.recalculate_depths
(
Some
(
b
));
assert_eq!
(
expected
.root_node
,
tree
.root_node
);
assert_eq!
(
expected
.parents
,
tree
.parents
);
assert_eq!
(
expected
.children
,
tree
.children
);
assert_eq!
(
expected
.depths
,
tree
.depths
);
}
#[test]
#[test]
fn
should_have_correct_depth
()
{
fn
should_have_correct_depth
()
{
let
mut
tree
=
Tree
::
default
();
let
mut
tree
=
Tree
::
default
();
...
...
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