Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tp6 Flood
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
EL GAOUAL Zaid
Tp6 Flood
Commits
c9078a2d
Commit
c9078a2d
authored
2 years ago
by
BEL KHALIFA Mohamed amine
Browse files
Options
Downloads
Patches
Plain Diff
test valid2
parent
ab949f6a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/model/ArrayGrid.java
+8
-6
8 additions, 6 deletions
app/src/main/java/model/ArrayGrid.java
app/src/test/java/model/ArrayGridTest.java
+77
-77
77 additions, 77 deletions
app/src/test/java/model/ArrayGridTest.java
with
85 additions
and
83 deletions
app/src/main/java/model/ArrayGrid.java
+
8
−
6
View file @
c9078a2d
package
model
;
import
javafx.scene.paint.Color
;
public
class
ArrayGrid
implements
Grid
{
p
ublic
Cell
[][]
cells
;
p
rivate
Cell
[][]
cells
;
public
ArrayGrid
(
int
numberOfRows
,
int
numberOfColumns
)
{
if
(
numberOfRows
<=
0
||
numberOfColumns
<=
0
)
throw
new
IllegalArgumentException
(
"Le nombre de lignes ou de colonnes ne peut pas être nul ou négatif."
);
Cell
[][]
cells
=
new
Cell
[
numberOfRows
][
numberOfColumns
];
for
(
Cell
[]
column
:
cells
)
{
for
(
Cell
cell
:
column
)
{
cell
=
new
SquareCell
();
this
.
cells
=
new
Cell
[
numberOfRows
][
numberOfColumns
];
for
(
int
i
=
0
;
i
<
numberOfRows
;
i
++
)
{
for
(
int
j
=
0
;
j
<
numberOfColumns
;
j
++
)
{
cell
s
[
i
][
j
]
=
new
SquareCell
();
}
}
}
@Override
public
Cell
getCell
(
int
row
,
int
column
)
{
return
cells
[
row
][
column
];
return
this
.
cells
[
row
][
column
];
}
@Override
...
...
This diff is collapsed.
Click to expand it.
app/src/test/java/model/ArrayGridTest.java
+
77
−
77
View file @
c9078a2d
//
package model;
//
//
import javafx.scene.paint.Color;
//
import org.junit.jupiter.api.BeforeEach;
//
import org.junit.jupiter.api.Test;
//
//
import java.util.Iterator;
//
//
import static org.assertj.core.api.Assertions.assertThat;
//
import static org.assertj.core.api.Assertions.assertThatThrownBy;
//
//
class ArrayGridTest {
//
//
//
private ArrayGrid arrayGridThreeFour;
//
private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);
//
//
@BeforeEach
//
void initializeArrayGridThreeFour(){
//
arrayGridThreeFour = new ArrayGrid(3,4);
//
}
//
//
//
@Test
//
void testGetCellAndGridInitialization() {
//
assertThat(arrayGridThreeFour.getCell(0,0).getNeighbours())
//
.hasSize(2)
//
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,0), arrayGridThreeFour.getCell(0,1));
//
assertThat(arrayGridThreeFour.getCell(1,1).getNeighbours()).hasSize(4)
//
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(0,1),
//
arrayGridThreeFour.getCell(2,1),
//
arrayGridThreeFour.getCell(1,2),
//
arrayGridThreeFour.getCell(1,0));
//
assertThat(arrayGridThreeFour.getCell(2,3).getNeighbours()).hasSize(2)
//
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,3),
//
arrayGridThreeFour.getCell(2,2));
//
assertThat(arrayGridThreeFour.getCell(2,2).getNeighbours()).hasSize(3)
//
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,2),
//
arrayGridThreeFour.getCell(2,1),
//
arrayGridThreeFour.getCell(2,3));
//
}
//
//
@Test
//
void testConstructionWithIllegalParameters(){
//
assertThatThrownBy(() -> new ArrayGrid(-4,10)).isInstanceOf(IllegalArgumentException.class);
//
assertThatThrownBy(() -> new ArrayGrid(4,0)).isInstanceOf(IllegalArgumentException.class);
//
//
}
//
@Test
//
void testGetNumberOfRows() {
//
assertThat(new ArrayGrid(100,200).getNumberOfRows()).isEqualTo(100);
//
}
//
//
@Test
//
void testGetNumberOfColumns() {
//
assertThat(new ArrayGrid(100,200).getNumberOfColumns()).isEqualTo(200);
//
}
//
//
private void setArrayGridThreeFourRed(){
//
for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
//
for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
//
arrayGridThreeFour.getCell(rowIndex,columnIndex).setColor(Color.RED);
//
}
//
}
//
}
//
@Test
//
void testColor() {
//
setArrayGridThreeFourRed();
//
arrayGridThreeFour.color(cell -> Color.BLACK);
//
for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
//
for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
//
assertThat(arrayGridThreeFour.getCell(rowIndex,columnIndex).getColor()).isEqualTo(Color.BLACK);
//
}
//
}
//
}
//
package
model
;
import
javafx.scene.paint.Color
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
java.util.Iterator
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatThrownBy
;
class
ArrayGridTest
{
private
ArrayGrid
arrayGridThreeFour
;
private
final
ArrayGrid
arrayGridTwoTwo
=
new
ArrayGrid
(
2
,
2
);
@BeforeEach
void
initializeArrayGridThreeFour
(){
arrayGridThreeFour
=
new
ArrayGrid
(
3
,
4
);
}
@Test
void
testGetCellAndGridInitialization
()
{
assertThat
(
arrayGridThreeFour
.
getCell
(
0
,
0
).
getNeighbours
())
.
hasSize
(
2
)
.
containsExactlyInAnyOrder
(
arrayGridThreeFour
.
getCell
(
1
,
0
),
arrayGridThreeFour
.
getCell
(
0
,
1
));
assertThat
(
arrayGridThreeFour
.
getCell
(
1
,
1
).
getNeighbours
()).
hasSize
(
4
)
.
containsExactlyInAnyOrder
(
arrayGridThreeFour
.
getCell
(
0
,
1
),
arrayGridThreeFour
.
getCell
(
2
,
1
),
arrayGridThreeFour
.
getCell
(
1
,
2
),
arrayGridThreeFour
.
getCell
(
1
,
0
));
assertThat
(
arrayGridThreeFour
.
getCell
(
2
,
3
).
getNeighbours
()).
hasSize
(
2
)
.
containsExactlyInAnyOrder
(
arrayGridThreeFour
.
getCell
(
1
,
3
),
arrayGridThreeFour
.
getCell
(
2
,
2
));
assertThat
(
arrayGridThreeFour
.
getCell
(
2
,
2
).
getNeighbours
()).
hasSize
(
3
)
.
containsExactlyInAnyOrder
(
arrayGridThreeFour
.
getCell
(
1
,
2
),
arrayGridThreeFour
.
getCell
(
2
,
1
),
arrayGridThreeFour
.
getCell
(
2
,
3
));
}
@Test
void
testConstructionWithIllegalParameters
(){
assertThatThrownBy
(()
->
new
ArrayGrid
(-
4
,
10
)).
isInstanceOf
(
IllegalArgumentException
.
class
);
assertThatThrownBy
(()
->
new
ArrayGrid
(
4
,
0
)).
isInstanceOf
(
IllegalArgumentException
.
class
);
}
@Test
void
testGetNumberOfRows
()
{
assertThat
(
new
ArrayGrid
(
100
,
200
).
getNumberOfRows
()).
isEqualTo
(
100
);
}
@Test
void
testGetNumberOfColumns
()
{
assertThat
(
new
ArrayGrid
(
100
,
200
).
getNumberOfColumns
()).
isEqualTo
(
200
);
}
private
void
setArrayGridThreeFourRed
(){
for
(
int
rowIndex
=
0
;
rowIndex
<
3
;
rowIndex
++)
{
for
(
int
columnIndex
=
0
;
columnIndex
<
4
;
columnIndex
++)
{
arrayGridThreeFour
.
getCell
(
rowIndex
,
columnIndex
).
setColor
(
Color
.
RED
);
}
}
}
@Test
void
testColor
()
{
setArrayGridThreeFourRed
();
arrayGridThreeFour
.
color
(
cell
->
Color
.
BLACK
);
for
(
int
rowIndex
=
0
;
rowIndex
<
3
;
rowIndex
++)
{
for
(
int
columnIndex
=
0
;
columnIndex
<
4
;
columnIndex
++)
{
assertThat
(
arrayGridThreeFour
.
getCell
(
rowIndex
,
columnIndex
).
getColor
()).
isEqualTo
(
Color
.
BLACK
);
}
}
}
// @Test
// void testIterator() {
// Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
...
...
@@ -87,4 +87,4 @@
// assertThat(iterator.hasNext()).isFalse();
//
// }
//}
\ No newline at end of file
}
\ No newline at end of file
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