Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
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
Model registry
Operate
Environments
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
steven.liatti
poo2019numeric
Commits
bdf5a810
Commit
bdf5a810
authored
5 years ago
by
tanguy.dietrich
Browse files
Options
Downloads
Patches
Plain Diff
Ecriture de .populate() pour le BinaryHeap
parent
4f543c18
No related branches found
No related tags found
2 merge requests
!2
Tanguy
,
!1
David
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/structure/BinaryHeap.java
+11
-0
11 additions, 0 deletions
src/main/java/ch/hepia/structure/BinaryHeap.java
src/test/java/ch/hepia/structure/AppTest.java
+7
-3
7 additions, 3 deletions
src/test/java/ch/hepia/structure/AppTest.java
with
18 additions
and
3 deletions
src/main/java/ch/hepia/structure/BinaryHeap.java
+
11
−
0
View file @
bdf5a810
...
@@ -4,6 +4,7 @@ import java.util.List;
...
@@ -4,6 +4,7 @@ import java.util.List;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.function.DoubleFunction
;
import
java.util.function.DoubleFunction
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.Random
;
final
public
class
BinaryHeap
final
public
class
BinaryHeap
{
{
...
@@ -22,6 +23,15 @@ final public class BinaryHeap
...
@@ -22,6 +23,15 @@ final public class BinaryHeap
this
.
sort
();
this
.
sort
();
}
}
public
static
void
populate
(
BinaryHeap
heap
,
int
size
)
{
Random
rand
=
new
Random
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
heap
.
push
(
rand
.
nextInt
(
100
));
}
}
private
void
sort
()
private
void
sort
()
{
{
int
index
=
this
.
size
()-
1
;
int
index
=
this
.
size
()-
1
;
...
@@ -65,6 +75,7 @@ final public class BinaryHeap
...
@@ -65,6 +75,7 @@ final public class BinaryHeap
{
{
System
.
out
.
println
(
val
);
System
.
out
.
println
(
val
);
}
}
System
.
out
.
println
(
""
);
}
}
public
int
size
()
public
int
size
()
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/structure/AppTest.java
+
7
−
3
View file @
bdf5a810
...
@@ -11,9 +11,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
...
@@ -11,9 +11,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
class
BinaryHeapTest
class
BinaryHeapTest
{
{
@Test
@Test
void
BinaryHeap
Push
Test
()
void
BinaryHeap
MainOpreation
Test
()
{
{
BinaryHeap
bHeap
=
new
BinaryHeap
();
BinaryHeap
bHeap
=
new
BinaryHeap
();
BinaryHeap
bHeapRand
=
new
BinaryHeap
();
BinaryHeap
.
populate
(
bHeapRand
,
20
);
bHeap
.
push
(
100
);
bHeap
.
push
(
100
);
bHeap
.
push
(
19
);
bHeap
.
push
(
19
);
bHeap
.
push
(
36
);
bHeap
.
push
(
36
);
...
@@ -24,7 +26,9 @@ class BinaryHeapTest
...
@@ -24,7 +26,9 @@ class BinaryHeapTest
bHeap
.
push
(
2
);
bHeap
.
push
(
2
);
bHeap
.
push
(
7
);
bHeap
.
push
(
7
);
bHeap
.
push
(
40
);
bHeap
.
push
(
40
);
bHeap
.
print
();
//bHeap.print();
//assertEquals();
//bHeapRand.print();
assertEquals
(
bHeap
.
size
(),
10
);
assertEquals
(
bHeapRand
.
size
(),
20
);
}
}
}
}
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