SlideShare a Scribd company logo
1 of 19
Download to read offline
JEE KURZUS 13. HÉT
SETENY.JANOS@TIGRA.HU
1
Előző órai feladat
Milyen kezdő értékeket adjunk?
2
private void incrementNeighbours(int bombX, int bombY) {

int startX = 

int endX = 



int startY = 

int endY = 



for (int x = startX; x <= endX; ++x) {

for (int y = startY; y <= endY; ++y) {

if ( ) {

field[y][x] = field[y][x] + 1;

}

}

}

}
Előző órai feladat
Milyen esetben rosszak a kezdőértékek?
3
private void incrementNeighbours(int bombX, int bombY) {

int startX = bombX - 1;

int endX = bombX + 1;



int startY = bombY - 1;

int endY = bombY + 1;



for (int x = startX; x <= endX; ++x) {

for (int y = startY; y <= endY; ++y) {

if ( ) {

field[y][x] = field[y][x] + 1;

}

}

}

}
Előző órai feladat
Ez jó, de rövidebben hogyan lehet?
4
private void incrementNeighbours(int bombX, int bombY) {


int startX = bombX - 1;

if (startX < 0) {

startX = 0;

}

int endX = bombX + 1;

if (endX > width - 1) {

endX = width - 1;

}

int startY = bombY - 1;

if (startY < 0) {

startY = 0;

}

int endY = bombY + 1;

if (endY > width - 1) {

endY = width - 1;

}

...
}
Előző órai feladat
Milyen föltétel kell az if-be?
5
private void incrementNeighbours(int bombX, int bombY) {

int startX = Math.max(0, bombX - 1);

int endX = Math.min(width - 1, bombX + 1);



int startY = Math.max(0, bombY - 1);

int endY = Math.min(height - 1, bombY + 1);



for (int x = startX; x <= endX; ++x) {

for (int y = startY; y <= endY; ++y) {

if ( ) {

field[y][x] = field[y][x] + 1;

}

}

}

}
Előző órai feladat
Ez a teljes megvalósítása a metódusnak
6
private void incrementNeighbours(int bombX, int bombY) {

int startX = Math.max(0, bombX - 1);

int endX = Math.min(width - 1, bombX + 1);



int startY = Math.max(0, bombY - 1);

int endY = Math.min(height - 1, bombY + 1);



for (int x = startX; x <= endX; ++x) {

for (int y = startY; y <= endY; ++y) {

if (field[y][x] != BOMB) {

field[y][x] = field[y][x] + 1;

}

}

}

}
Valóban teljes?
7
Valóban teljes?
8
PIT mutation test report
9
PIT mutation test report
10
Robbanást hogyan jelezzünk
amikor int[][] a visszatérési érték?
11
public class Mask {





public static int[][] unmask(
MineField mineField, int[][] mask, int clickX, int clickY) {


if (mineField.at(clickX, clickY) == BOMB) {

}



int[][] newMask = deepCopy(mask);

return unmaskCell(mineField, mask, newMask, clickX, clickY);

}
Robbanást hogyan jelezzünk
amikor int[][] a visszatérési érték?
12
public class Mask {



public static class Explosion extends Exception {

}





public static int[][] unmask(
MineField mineField, int[][] mask, int clickX, int clickY) {


if (mineField.at(clickX, clickY) == BOMB) {

throw new Explosion();
}



int[][] newMask = deepCopy(mask);

return unmaskCell(mineField, mask, newMask, clickX, clickY);

}
A 0-ák megjelenítése
13
1. A 0-ákat fölfedni

2. Környezetében minden 0-t fölfedni

3. A határvonalon lévő értékeket is fölfedni

4. Az aknákat takarva hagyni
14
private static int[][] unmaskCell(
MineField mineField, int[][] mask, int[][] newMask, int x, int y) {


if () {

newMask[y][x] = 0;

return unmaskNeighbours(mineField, mask, newMask, x, y);



} else if () {

newMask[y][x] = 0;

return newMask;



} else {

return newMask;

}

}
15
private static int[][] unmaskCell(
MineField mineField, int[][] mask, int[][] newMask, int x, int y) {


if (mineField.at(x, y) == 0) {

newMask[y][x] = 0;

return unmaskNeighbours(mineField, mask, newMask, x, y);



} else if (mineField.at(x, y) != BOMB) {

newMask[y][x] = 0;

return newMask;



} else {

return newMask;

}

}
16
private static int[][] unmaskCell(
MineField mineField, int[][] mask, int[][] newMask, int x, int y) {


if (mineField.at(x, y) == 0 && newMask[y][x] == 1) {

newMask[y][x] = 0;

return unmaskNeighbours(mineField, mask, newMask, x, y);



} else if (mineField.at(x, y) != BOMB) {

newMask[y][x] = 0;

return newMask;



} else {

return newMask;

}

}
17
private static int[][] unmaskNeighbours(
MineField mineField, int[][] mask, int[][] newMask,
int cellX, int cellY) {


int startY =

int endY =


int startX =

int endX =



for (int y = startY; y <= endY; ++y) {

for (int x = startX; x <= endX; ++x) {



}

}

return newMask;

}
18
private static int[][] unmaskNeighbours(
MineField mineField, int[][] mask, int[][] newMask,
int cellX, int cellY) {


int startY = Math.max(0, cellY - 1);

int endY = Math.min(mineField.getHeight() - 1, cellY + 1);



int startX = Math.max(0, cellX - 1);

int endX = Math.min(mineField.getWidth() - 1, cellX + 1);



for (int y = startY; y <= endY; ++y) {

for (int x = startX; x <= endX; ++x) {

}

}

return newMask;

}
19
private static int[][] unmaskNeighbours(
MineField mineField, int[][] mask, int[][] newMask,
int cellX, int cellY) {


int startY = Math.max(0, cellY - 1);

int endY = Math.min(mineField.getHeight() - 1, cellY + 1);



int startX = Math.max(0, cellX - 1);

int endX = Math.min(mineField.getWidth() - 1, cellX + 1);



for (int y = startY; y <= endY; ++y) {

for (int x = startX; x <= endX; ++x) {

unmaskCell(mineField, mask, newMask, x, y);

}

}

return newMask;

}

More Related Content

More from Janos Seteny

More from Janos Seteny (12)

Jee kurzus 12. het
Jee kurzus 12. hetJee kurzus 12. het
Jee kurzus 12. het
 
Jee kurzus 11. het
Jee kurzus 11. hetJee kurzus 11. het
Jee kurzus 11. het
 
Jee kurzus 10. het
Jee kurzus 10. hetJee kurzus 10. het
Jee kurzus 10. het
 
Jee kurzus 9. het
Jee kurzus 9. hetJee kurzus 9. het
Jee kurzus 9. het
 
Jee kurzus 8. het
Jee kurzus 8. hetJee kurzus 8. het
Jee kurzus 8. het
 
Jee kurzus 7. het
Jee kurzus 7. hetJee kurzus 7. het
Jee kurzus 7. het
 
Jee kurzus 6. het
Jee kurzus 6. hetJee kurzus 6. het
Jee kurzus 6. het
 
Jee kurzus 5. het
Jee kurzus 5. hetJee kurzus 5. het
Jee kurzus 5. het
 
Jee kurzus 4. het
Jee kurzus 4. hetJee kurzus 4. het
Jee kurzus 4. het
 
Jee kurzus 3. het
Jee kurzus 3. hetJee kurzus 3. het
Jee kurzus 3. het
 
Jee kurzus 2. het
Jee kurzus 2. hetJee kurzus 2. het
Jee kurzus 2. het
 
Jee kurzus 1 het
Jee kurzus 1 hetJee kurzus 1 het
Jee kurzus 1 het
 

Jee kurzus 13. het

  • 1. JEE KURZUS 13. HÉT SETENY.JANOS@TIGRA.HU 1
  • 2. Előző órai feladat Milyen kezdő értékeket adjunk? 2 private void incrementNeighbours(int bombX, int bombY) {
 int startX = 
 int endX = 
 
 int startY = 
 int endY = 
 
 for (int x = startX; x <= endX; ++x) {
 for (int y = startY; y <= endY; ++y) {
 if ( ) {
 field[y][x] = field[y][x] + 1;
 }
 }
 }
 }
  • 3. Előző órai feladat Milyen esetben rosszak a kezdőértékek? 3 private void incrementNeighbours(int bombX, int bombY) {
 int startX = bombX - 1;
 int endX = bombX + 1;
 
 int startY = bombY - 1;
 int endY = bombY + 1;
 
 for (int x = startX; x <= endX; ++x) {
 for (int y = startY; y <= endY; ++y) {
 if ( ) {
 field[y][x] = field[y][x] + 1;
 }
 }
 }
 }
  • 4. Előző órai feladat Ez jó, de rövidebben hogyan lehet? 4 private void incrementNeighbours(int bombX, int bombY) { 
 int startX = bombX - 1;
 if (startX < 0) {
 startX = 0;
 }
 int endX = bombX + 1;
 if (endX > width - 1) {
 endX = width - 1;
 }
 int startY = bombY - 1;
 if (startY < 0) {
 startY = 0;
 }
 int endY = bombY + 1;
 if (endY > width - 1) {
 endY = width - 1;
 }
 ... }
  • 5. Előző órai feladat Milyen föltétel kell az if-be? 5 private void incrementNeighbours(int bombX, int bombY) {
 int startX = Math.max(0, bombX - 1);
 int endX = Math.min(width - 1, bombX + 1);
 
 int startY = Math.max(0, bombY - 1);
 int endY = Math.min(height - 1, bombY + 1);
 
 for (int x = startX; x <= endX; ++x) {
 for (int y = startY; y <= endY; ++y) {
 if ( ) {
 field[y][x] = field[y][x] + 1;
 }
 }
 }
 }
  • 6. Előző órai feladat Ez a teljes megvalósítása a metódusnak 6 private void incrementNeighbours(int bombX, int bombY) {
 int startX = Math.max(0, bombX - 1);
 int endX = Math.min(width - 1, bombX + 1);
 
 int startY = Math.max(0, bombY - 1);
 int endY = Math.min(height - 1, bombY + 1);
 
 for (int x = startX; x <= endX; ++x) {
 for (int y = startY; y <= endY; ++y) {
 if (field[y][x] != BOMB) {
 field[y][x] = field[y][x] + 1;
 }
 }
 }
 }
  • 9. PIT mutation test report 9
  • 10. PIT mutation test report 10
  • 11. Robbanást hogyan jelezzünk amikor int[][] a visszatérési érték? 11 public class Mask {
 
 
 public static int[][] unmask( MineField mineField, int[][] mask, int clickX, int clickY) { 
 if (mineField.at(clickX, clickY) == BOMB) {
 }
 
 int[][] newMask = deepCopy(mask);
 return unmaskCell(mineField, mask, newMask, clickX, clickY);
 }
  • 12. Robbanást hogyan jelezzünk amikor int[][] a visszatérési érték? 12 public class Mask {
 
 public static class Explosion extends Exception {
 }
 
 
 public static int[][] unmask( MineField mineField, int[][] mask, int clickX, int clickY) { 
 if (mineField.at(clickX, clickY) == BOMB) {
 throw new Explosion(); }
 
 int[][] newMask = deepCopy(mask);
 return unmaskCell(mineField, mask, newMask, clickX, clickY);
 }
  • 13. A 0-ák megjelenítése 13 1. A 0-ákat fölfedni 2. Környezetében minden 0-t fölfedni 3. A határvonalon lévő értékeket is fölfedni 4. Az aknákat takarva hagyni
  • 14. 14 private static int[][] unmaskCell( MineField mineField, int[][] mask, int[][] newMask, int x, int y) { 
 if () {
 newMask[y][x] = 0;
 return unmaskNeighbours(mineField, mask, newMask, x, y);
 
 } else if () {
 newMask[y][x] = 0;
 return newMask;
 
 } else {
 return newMask;
 }
 }
  • 15. 15 private static int[][] unmaskCell( MineField mineField, int[][] mask, int[][] newMask, int x, int y) { 
 if (mineField.at(x, y) == 0) {
 newMask[y][x] = 0;
 return unmaskNeighbours(mineField, mask, newMask, x, y);
 
 } else if (mineField.at(x, y) != BOMB) {
 newMask[y][x] = 0;
 return newMask;
 
 } else {
 return newMask;
 }
 }
  • 16. 16 private static int[][] unmaskCell( MineField mineField, int[][] mask, int[][] newMask, int x, int y) { 
 if (mineField.at(x, y) == 0 && newMask[y][x] == 1) {
 newMask[y][x] = 0;
 return unmaskNeighbours(mineField, mask, newMask, x, y);
 
 } else if (mineField.at(x, y) != BOMB) {
 newMask[y][x] = 0;
 return newMask;
 
 } else {
 return newMask;
 }
 }
  • 17. 17 private static int[][] unmaskNeighbours( MineField mineField, int[][] mask, int[][] newMask, int cellX, int cellY) { 
 int startY =
 int endY = 
 int startX =
 int endX =
 
 for (int y = startY; y <= endY; ++y) {
 for (int x = startX; x <= endX; ++x) {
 
 }
 }
 return newMask;
 }
  • 18. 18 private static int[][] unmaskNeighbours( MineField mineField, int[][] mask, int[][] newMask, int cellX, int cellY) { 
 int startY = Math.max(0, cellY - 1);
 int endY = Math.min(mineField.getHeight() - 1, cellY + 1);
 
 int startX = Math.max(0, cellX - 1);
 int endX = Math.min(mineField.getWidth() - 1, cellX + 1);
 
 for (int y = startY; y <= endY; ++y) {
 for (int x = startX; x <= endX; ++x) {
 }
 }
 return newMask;
 }
  • 19. 19 private static int[][] unmaskNeighbours( MineField mineField, int[][] mask, int[][] newMask, int cellX, int cellY) { 
 int startY = Math.max(0, cellY - 1);
 int endY = Math.min(mineField.getHeight() - 1, cellY + 1);
 
 int startX = Math.max(0, cellX - 1);
 int endX = Math.min(mineField.getWidth() - 1, cellX + 1);
 
 for (int y = startY; y <= endY; ++y) {
 for (int x = startX; x <= endX; ++x) {
 unmaskCell(mineField, mask, newMask, x, y);
 }
 }
 return newMask;
 }