Create functional tests where arguments are given, use a parameterized test. testSimpleInit(size): the first constructor works as expected. getTiles shows suitable values. The edges of the board (the smallest and biggest conceivable values) are accessible and contain the values that they have to (BASE_TILE_SCORE). testCustomInit(x, y, expected): the second constructor works as expected. On positions where values smaller than three were passed, the board contains the value BASE_TILE_SCORE. If you pass an array to the constructor and later modify a value in it, the respective tile retains the originally passed value. If you modify an element in the return value of getTiles(), and get the value of the respective tile again, this newly received content has to be the originally set value. testMoves(): take four or five steps and check that the board’s contents are changed just right. Include a step that tries to move to the x coordinate Integer.MIN_VALUE and another one that moves to the y coordinate 666. Include a step that tries to move outside of the board. In this case, check that both the position and the board’s contents are unchanged. public class WalkingBoard { privateint[][] tiles; //getter method bhgu privateintx; privateinty; publicstaticfinalintBASE_TILE_SCORE=3;   publicWalkingBoard(intsize) { this.tiles=newint[size][size]; for (inti=0; i < size; i++) { for (intj=0; j < size; j++) { this.tiles[i][j] = BASE_TILE_SCORE;} } this.x=0; this.y=0; } publicWalkingBoard(int[][] tiles) { this.x=0; this.y=0; int[][] copy=newint[tiles.length][]; for (inti=0; i <tiles.length; i++) { introwLength= tiles[i].length; copy[i] = new int[rowLength]; for (intj=0; j < rowLength; j++) { copy[i][j] = Math.max(this.BASE_TILE_SCORE, tiles[i][j]); } } this.tiles= copy; } publicint[] getPosition() { returnnewint[]{x, y}; } publicbooleanisValidPosition(intx, inty) { return x >=0&& x <tiles.length&& y >=0&& y < tiles[0].length; //indexing - tiles 0;; tiles[0].length--> how to do it if uniform } publicintgetTile(intx, inty) { if (isValidPosition(x, y)) { return tiles[x][y]; } elsethrownewIllegalArgumentException("Invalid Position"); } publicint[][] getTiles(){ int[][] copy=newint[tiles.length][]; for (inti=0; i <tiles.length; i++) { introwLength= tiles[i].length; copy[i] = new int[rowLength]; for (intj=0; j < rowLength; j++) { copy[i][j] = tiles[i][j]; } } return copy; } publicstaticintgetXStep(Directiondirection) { switch (direction) { case UP: return1; case DOWN: return-1; case RIGHT: return0; case LEFT: return-0; default: thrownewIllegalArgumentException("Invalid direction"); } } publicstaticintgetYStep(Directiondirection) { switch (direction) { case UP: return0; case DOWN: return0; case RIGHT: return1; case LEFT: return-1; default: thrownewIllegalArgumentException("Invalid direction"); } } publicintmoveAndSet(Directiondirection, intvalue) { intnewX= x +getXStep(direction); intnewY= y +getYStep(direction); if (newX <0|| newX >=tiles.length|| newY <0|| newY >= tiles[newX].length) { return0; } else { x = newX; y = newY; intoldValue= tiles[x][y]; tiles[x][y] = value; return oldValue; } }   publicintsetAndMove(Directiondirection, intvalue) { tiles[x][y] = value; intnewX= x +getXStep(direction); intnewY= y +getYStep(direction); if (newX <0|| newX >=tiles.length|| newY <0|| newY >= tiles[newX].length) { return0; } else { x = newX; y = newY; return tiles[x][y]; } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Create functional tests where arguments are given, use a parameterized test.
  • testSimpleInit(size): the first constructor works as expected.
    • getTiles shows suitable values.
    • The edges of the board (the smallest and biggest conceivable values) are accessible and contain the values that they have to (BASE_TILE_SCORE).
  • testCustomInit(x, y, expected): the second constructor works as expected.
    • On positions where values smaller than three were passed, the board contains the value BASE_TILE_SCORE.
    • If you pass an array to the constructor and later modify a value in it, the respective tile retains the originally passed value.
    • If you modify an element in the return value of getTiles(), and get the value of the respective tile again, this newly received content has to be the originally set value.
  • testMoves(): take four or five steps and check that the board’s contents are changed just right.
  • Include a step that tries to move to the x coordinate Integer.MIN_VALUE and another one that moves to the y coordinate 666.
    • Include a step that tries to move outside of the board. In this case, check that both the position and the board’s contents are unchanged.
public class WalkingBoard {
privateint[][] tiles; //getter method bhgu
privateintx;
privateinty;
publicstaticfinalintBASE_TILE_SCORE=3;

 

publicWalkingBoard(intsize) {
this.tiles=newint[size][size];
for (inti=0; i < size; i++) {
for (intj=0; j < size; j++) {
this.tiles[i][j] = BASE_TILE_SCORE;}
}
this.x=0;
this.y=0;
}
publicWalkingBoard(int[][] tiles) {
this.x=0;
this.y=0;
int[][] copy=newint[tiles.length][];
for (inti=0; i <tiles.length; i++) {
introwLength= tiles[i].length;
copy[i] = new int[rowLength];
for (intj=0; j < rowLength; j++) {
copy[i][j] = Math.max(this.BASE_TILE_SCORE, tiles[i][j]);
}
}
this.tiles= copy;
}
publicint[] getPosition() {
returnnewint[]{x, y};
}
publicbooleanisValidPosition(intx, inty) {
return x >=0&& x <tiles.length&& y >=0&& y < tiles[0].length; //indexing - tiles 0;; tiles[0].length--> how to do it if uniform
}
publicintgetTile(intx, inty) {
if (isValidPosition(x, y)) {
return tiles[x][y];
}
elsethrownewIllegalArgumentException("Invalid Position");
}
publicint[][] getTiles(){
int[][] copy=newint[tiles.length][];
for (inti=0; i <tiles.length; i++) {
introwLength= tiles[i].length;
copy[i] = new int[rowLength];
for (intj=0; j < rowLength; j++) {
copy[i][j] = tiles[i][j];
}
}
return copy;
}
publicstaticintgetXStep(Directiondirection) {
switch (direction) {
case UP:
return1;
case DOWN:
return-1;
case RIGHT:
return0;
case LEFT:
return-0;
default:
thrownewIllegalArgumentException("Invalid direction");
}
}
publicstaticintgetYStep(Directiondirection) {
switch (direction) {
case UP:
return0;
case DOWN:
return0;
case RIGHT:
return1;
case LEFT:
return-1;
default:
thrownewIllegalArgumentException("Invalid direction");
}
}
publicintmoveAndSet(Directiondirection, intvalue) {
intnewX= x +getXStep(direction);
intnewY= y +getYStep(direction);
if (newX <0|| newX >=tiles.length|| newY <0|| newY >= tiles[newX].length) {
return0;
} else {
x = newX;
y = newY;
intoldValue= tiles[x][y];
tiles[x][y] = value;
return oldValue;
}
}
 
publicintsetAndMove(Directiondirection, intvalue) {
tiles[x][y] = value;
intnewX= x +getXStep(direction);
intnewY= y +getYStep(direction);
if (newX <0|| newX >=tiles.length|| newY <0|| newY >= tiles[newX].length) {
return0;
} else {
x = newX;
y = newY;
return tiles[x][y];
}
}
}
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education