Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Anya Helene Bagge
inf101.v18.lab3
Commits
24e05cad
Commit
24e05cad
authored
Feb 12, 2018
by
Anya Helene Bagge
🦆
Browse files
Merge branch 'master' into 'master'
fix grid See merge request
!2
parents
0fde9d91
ef119def
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/inf101/v18/datastructures/GridTest.java
View file @
24e05cad
...
...
@@ -16,6 +16,8 @@ public class GridTest {
IGrid
grid
=
new
MyGrid
(
11
,
17
,
CellState
.
DEAD
);
// TODO: sjekk at bredde og høyde faktisk er 11 og 17
assertEquals
(
11
,
grid
.
getWidth
());
assertEquals
(
17
,
grid
.
getHeight
());
}
/**
* Tests that trying to access outside of the dimensions of the grid throws
...
...
src/inf101/v18/datastructures/MyGrid.java
View file @
24e05cad
...
...
@@ -36,13 +36,13 @@ public class MyGrid implements IGrid {
@Override
public
int
getHeight
()
{
return
0
;
// TODO: fyll inn
return
height
;
// TODO: fyll inn
}
@Override
public
int
getWidth
()
{
return
0
;
// TODO: fyll inn
return
width
;
// TODO: fyll inn
}
...
...
@@ -54,8 +54,12 @@ public class MyGrid implements IGrid {
throw
new
IndexOutOfBoundsException
();
// TODO: fyll inn
cells
.
set
(
xyToI
(
x
,
y
),
elem
);
}
private
int
xyToI
(
int
x
,
int
y
)
{
return
x
+
y
*
width
;
}
@Override
public
CellState
get
(
int
x
,
int
y
)
{
...
...
@@ -64,7 +68,7 @@ public class MyGrid implements IGrid {
if
(
y
<
0
||
y
>=
height
)
throw
new
IndexOutOfBoundsException
();
return
null
;
// TODO: fyll inn
return
cells
.
get
(
xyToI
(
x
,
y
))
;
// TODO: fyll inn
}
@Override
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment