id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
df3ef361-4f02-46e2-af6a-88b96dbce308 | public void test_tilt_board_left() {
Game2048Core processer = new Game2048Core();
int[][] in = null;
int[][] out = null;
int[][] expected = null;
in = new int[][] { { 2, 0, 0, 2 },
{ 2, 0, 0, 0 },
{ 0, 0, 2, 2 },
{ 2, 0, 0, 0 }
};
out = processer.tilt_board_left(in);
expected = new int[][] { { 4, 0, 0, 0 },
{ 2, 0, 0, 0 },
{ 4, 0, 0, 0 },
{ 2, 0, 0, 0 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.FAILED);
fail();
}
in = new int[][] { { 2, 2, 0, 2 },
{ 0, 0, 0, 2 },
{ 0, 0, 2, 2 },
{ 2, 4, 6, 8 }
};
expected = new int[][] { { 4, 2, 0, 0 },
{ 2, 0, 0, 0 },
{ 4, 0, 0, 0 },
{ 2, 4, 6, 8 } };
out = processer.tilt_board_left(in);
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.FAILED);
fail();
}
in = new int[][] { { 0, 0, 0, 2 },
{ 0, 2, 0, 2 },
{ 2, 4, 2, 2 },
{ 2, 4, 6, 8 } };
expected = new int[][] { { 2, 0, 0, 0 },
{ 4, 0, 0, 0 },
{ 2, 4, 4, 0 },
{ 2, 4, 6, 8 } };
out = processer.tilt_board_left(in);
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board left became", out,
expected, GameUtil.FAILED);
fail();
}
} |
f93228e9-5990-4e03-a32c-ebe37be9b7d2 | public void test_tilt_board_up() {
Game2048Core processer = new Game2048Core();
int[][] in = null;
int[][] out = null;
int[][] expected = null;
in = new int[][] { { 2, 0, 0, 2 },
{ 2, 0, 0, 0 },
{ 0, 0, 2, 2 },
{ 2, 0, 0, 0 }
};
out = processer.tilt_board_up(in);
expected = new int[][] { { 4, 0, 2, 4 },
{ 2, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board up became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board up became", out,
expected, GameUtil.FAILED);
fail();
}
in = new int[][] { { 2, 2, 2, 0 },
{ 2, 0, 4, 0 },
{ 4, 0, 2, 2 },
{ 2, 2, 0, 4 }
};
out = processer.tilt_board_up(in);
expected = new int[][] { { 4, 4, 2, 2 },
{ 4, 0, 4, 4 },
{ 2, 0, 2, 0 },
{ 0, 0, 0, 0 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board up became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board up became", out,
expected, GameUtil.FAILED);
fail();
}
} |
f90fb870-b7b3-4b37-adc8-b8e5d68df68c | public void test_tilt_board_right(){
Game2048Core processer = new Game2048Core();
int[][] in = null;
int[][] out = null;
int[][] expected = null;
in = new int[][] { { 2, 0, 0, 2 },
{ 2, 0, 0, 0 },
{ 0, 0, 2, 2 },
{ 2, 0, 0, 0 }
};
out = processer.tilt_board_right(in);
expected = new int[][] { { 0, 0, 0, 4 },
{ 0, 0, 0, 2 },
{ 0, 0, 0, 4 },
{ 0, 0, 0, 2 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board right became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board right became", out,
expected, GameUtil.FAILED);
fail();
}
in = new int[][] { { 2, 2, 2, 0 },
{ 2, 0, 4, 0 },
{ 4, 0, 2, 2 },
{ 2, 2, 0, 4 }
};
out = processer.tilt_board_right(in);
expected = new int[][] { { 0, 0, 2, 4 },
{ 0, 0, 2, 4 },
{ 0, 0, 4, 4 },
{ 0, 0, 4, 4 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board right became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board right became", out,
expected, GameUtil.FAILED);
fail();
}
} |
e251f8a2-2d37-498e-906f-87e914bdd7b3 | public void test_tilt_board_down(){
Game2048Core processer = new Game2048Core();
int[][] in = null;
int[][] out = null;
int[][] expected = null;
in = new int[][] { { 2, 0, 0, 2 },
{ 2, 0, 0, 0 },
{ 0, 0, 2, 2 },
{ 2, 0, 0, 0 }
};
out = processer.tilt_board_down(in);
expected = new int[][] { { 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 2, 0, 0, 0 },
{ 4, 0, 2, 4 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board down became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board down became", out,
expected, GameUtil.FAILED);
fail();
}
in = new int[][] { { 2, 2, 2, 0 },
{ 2, 0, 4, 0 },
{ 4, 0, 2, 2 },
{ 2, 2, 0, 4 }
};
out = processer.tilt_board_down(in);
expected = new int[][] { { 0, 0, 0, 0 },
{ 4, 0, 2, 0 },
{ 4, 0, 4, 2 },
{ 2, 4, 2, 4 } };
if (GameUtil.compareExpectToActualBoard(expected, out)) {
GameUtil.printBoard(in, "after tilt board down became", out,
expected, GameUtil.PASSED);
} else {
GameUtil.printBoard(in, "after tilt board down became", out,
expected, GameUtil.FAILED);
fail();
}
} |
4c31971c-15f5-476a-8d42-64ac179efe39 | public void test_getNumber() {
// x, y is the first element.
int x = 0, y = 0;
gameCore.resetGame();
int value = gameCore.getNumber(x, y);
if (value < 0) {
fail();
}
// y out of boundary
x = 0;
y = 5;
value = gameCore.getNumber(x, y);
assertEquals(-1, value);
// x out of boundary
x = 5;
y = 0;
value = gameCore.getNumber(x, y);
assertEquals(-1, value);
// x and y within ROWS and COLS range
x = 2;
y = 3;
value = gameCore.getNumber(x, y);
if (value < 0) {
fail();
}
} |
b93e48d0-74eb-4b23-be49-ad6397979c71 | public void test_resetGame(){
gameCore.resetGame();
int[][] board = gameCore.getBoard();
int emptyNo = GameUtil.snapshotEmptySpots(board).size();
assertEquals(GameUtil.ROWS*GameUtil.COLS-2,emptyNo);
assertTrue(gameCore.canMove());
assertFalse(gameCore.lose());
assertFalse(gameCore.win());
} |
ef0762d6-5e97-46f0-b939-e8d02eca2bbb | public void test_tilt_board_left(){
int[][] partialExpected = null;
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
int[][]after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,0,0,0},
{1,0,0,0},
{1,0,0,0},
{1,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,0,2,0},
{1,0,2,0},
{1,0,2,0},
{1,0,2,0}
};
partialExpected= new int[][]{
{1,2,0,0},
{1,2,0,0},
{1,2,0,0},
{1,2,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
after = gameCore.getBoard();
assertEquals(partialExpected[0][0],after[0][0]);
assertEquals(partialExpected[0][1],after[0][1]);
assertEquals(partialExpected[1][0],after[1][0]);
assertEquals(partialExpected[1][1],after[1][1]);
assertEquals(partialExpected[2][0],after[2][0]);
assertEquals(partialExpected[2][1],after[2][1]);
assertEquals(partialExpected[3][0],after[3][0]);
assertEquals(partialExpected[3][1],after[3][1]);
int SumOfRest = after[0][2]+after[0][3]
+ after[1][2]+after[1][3]
+ after[2][2]+after[2][3]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,0,0,2},
{1,0,0,2},
{1,0,0,2},
{1,0,0,2}
};
partialExpected= new int[][]{
{1,2,0,0},
{1,2,0,0},
{1,2,0,0},
{1,2,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
after = gameCore.getBoard();
assertEquals(partialExpected[0][0],after[0][0]);
assertEquals(partialExpected[0][1],after[0][1]);
assertEquals(partialExpected[1][0],after[1][0]);
assertEquals(partialExpected[1][1],after[1][1]);
assertEquals(partialExpected[2][0],after[2][0]);
assertEquals(partialExpected[2][1],after[2][1]);
assertEquals(partialExpected[3][0],after[3][0]);
assertEquals(partialExpected[3][1],after[3][1]);
SumOfRest = after[0][2]+after[0][3]
+ after[1][2]+after[1][3]
+ after[2][2]+after[2][3]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,2,3,4},
{1,2,3,4},
{1,2,3,4},
{1,2,3,4}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1},
{1,1,1,1}
};
partialExpected= new int[][]{
{2,2,0,0},
{2,2,0,0},
{2,2,0,0},
{2,2,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
after = gameCore.getBoard();
assertEquals(partialExpected[0][0],after[0][0]);
assertEquals(partialExpected[0][1],after[0][1]);
assertEquals(partialExpected[1][0],after[1][0]);
assertEquals(partialExpected[1][1],after[1][1]);
assertEquals(partialExpected[2][0],after[2][0]);
assertEquals(partialExpected[2][1],after[2][1]);
assertEquals(partialExpected[3][0],after[3][0]);
assertEquals(partialExpected[3][1],after[3][1]);
SumOfRest = after[0][2]+after[0][3]
+ after[1][2]+after[1][3]
+ after[2][2]+after[2][3]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
} |
ea5e89cc-2761-4aae-bd66-e196ecdf9fb4 | public void test_tilt_board_up(){
gameCore.resetGame();
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
int[][]after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{2,2,2,2},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
after = gameCore.getBoard();
assertEquals(1,after[0][0]);
assertEquals(1,after[0][1]);
assertEquals(1,after[0][2]);
assertEquals(1,after[0][3]);
assertEquals(2,after[1][0]);
assertEquals(2,after[1][1]);
assertEquals(2,after[1][2]);
assertEquals(2,after[1][3]);
int SumOfRest = after[2][0]+after[2][1]
+ after[2][2]+after[2][3]
+ after[3][0]+after[3][1]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{0,0,0,0},
{2,2,2,2}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
after = gameCore.getBoard();
assertEquals(1,after[0][0]);
assertEquals(1,after[0][1]);
assertEquals(1,after[0][2]);
assertEquals(1,after[0][3]);
assertEquals(2,after[1][0]);
assertEquals(2,after[1][1]);
assertEquals(2,after[1][2]);
assertEquals(2,after[1][3]);
SumOfRest = after[2][0]+after[2][1]
+ after[2][2]+after[2][3]
+ after[3][0]+after[3][1]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,1,1,1},
{2,2,2,2},
{3,3,3,3},
{4,4,4,4}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1},
{1,1,1,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_up();
after = gameCore.getBoard();
assertEquals(2,after[0][0]);
assertEquals(2,after[0][1]);
assertEquals(2,after[0][2]);
assertEquals(2,after[0][3]);
assertEquals(2,after[1][0]);
assertEquals(2,after[1][1]);
assertEquals(2,after[1][2]);
assertEquals(2,after[1][3]);
SumOfRest = after[2][0]+after[2][1]
+ after[2][2]+after[2][3]
+ after[3][0]+after[3][1]
+ after[3][2]+after[3][3];
if(SumOfRest==0){
fail();
}
} |
bc80440e-9605-4c92-8f46-9c445711764c | public void test_tilt_board_right(){
gameCore.resetGame();
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
int[][]after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{0,0,0,1},
{0,0,0,1},
{0,0,0,1},
{0,0,0,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{0,2,0,1},
{0,2,0,1},
{0,2,0,1},
{0,2,0,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
after = gameCore.getBoard();
assertEquals(1,after[0][3]);
assertEquals(1,after[1][3]);
assertEquals(1,after[2][3]);
assertEquals(1,after[3][3]);
assertEquals(2,after[0][2]);
assertEquals(2,after[1][2]);
assertEquals(2,after[2][2]);
assertEquals(2,after[2][2]);
int SumOfRest = after[0][0]+after[0][1]
+ after[1][0]+after[1][1]
+ after[2][0]+after[2][1]
+ after[3][0]+after[3][1];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{2,0,0,1},
{2,0,0,1},
{2,0,0,1},
{2,0,0,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
after = gameCore.getBoard();
assertEquals(1,after[0][3]);
assertEquals(1,after[1][3]);
assertEquals(1,after[2][3]);
assertEquals(1,after[3][3]);
assertEquals(2,after[0][2]);
assertEquals(2,after[1][2]);
assertEquals(2,after[2][2]);
assertEquals(2,after[2][2]);
SumOfRest = after[0][0]+after[0][1]
+ after[1][0]+after[1][1]
+ after[2][0]+after[2][1]
+ after[3][0]+after[3][1];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{4,3,2,1},
{4,3,2,1},
{4,3,2,1},
{4,3,2,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1},
{1,1,1,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_right();
after = gameCore.getBoard();
assertEquals(2,after[0][3]);
assertEquals(2,after[1][3]);
assertEquals(2,after[2][3]);
assertEquals(2,after[3][3]);
assertEquals(2,after[0][2]);
assertEquals(2,after[1][2]);
assertEquals(2,after[2][2]);
assertEquals(2,after[2][2]);
SumOfRest = after[0][0]+after[0][1]
+ after[1][0]+after[1][1]
+ after[2][0]+after[2][1]
+ after[3][0]+after[3][1];
if(SumOfRest==0){
fail();
}
} |
98f5ab7d-5faf-4a37-99f0-0ca8e5ffb016 | public void test_tilt_board_down(){
gameCore.resetGame();
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
int[][]after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{1,1,1,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{2,2,2,2},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
after = gameCore.getBoard();
assertEquals(1,after[2][0]);
assertEquals(1,after[2][1]);
assertEquals(1,after[2][2]);
assertEquals(1,after[2][3]);
assertEquals(2,after[3][0]);
assertEquals(2,after[3][1]);
assertEquals(2,after[3][2]);
assertEquals(2,after[3][3]);
int SumOfRest = after[0][0]+after[0][1]
+ after[0][2]+after[0][3]
+ after[1][0]+after[1][1]
+ after[1][2]+after[1][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{0,0,0,0},
{2,2,2,2}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
after = gameCore.getBoard();
assertEquals(1,after[2][0]);
assertEquals(1,after[2][1]);
assertEquals(1,after[2][2]);
assertEquals(1,after[2][3]);
assertEquals(2,after[3][0]);
assertEquals(2,after[3][1]);
assertEquals(2,after[3][2]);
assertEquals(2,after[3][3]);
SumOfRest = after[0][0]+after[0][1]
+ after[0][2]+after[0][3]
+ after[1][0]+after[1][1]
+ after[1][2]+after[1][3];
if(SumOfRest==0){
fail();
}
mockBoards = new int[][]{
{1,1,1,1},
{2,2,2,2},
{3,3,3,3},
{4,4,4,4}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
after = gameCore.getBoard();
assertTrue(GameUtil.compareExpectToActualBoard(mockBoards, after));
mockBoards = new int[][]{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1},
{1,1,1,1}
};
gameCore.setBoard(mockBoards);
gameCore.tilt_board_down();
after = gameCore.getBoard();
assertEquals(2,after[2][0]);
assertEquals(2,after[2][1]);
assertEquals(2,after[2][2]);
assertEquals(2,after[2][3]);
assertEquals(2,after[3][0]);
assertEquals(2,after[3][1]);
assertEquals(2,after[3][2]);
assertEquals(2,after[3][3]);
SumOfRest = after[0][0]+after[0][1]
+ after[0][2]+after[0][3]
+ after[1][0]+after[1][1]
+ after[1][2]+after[1][3];
if(SumOfRest==0){
fail();
}
} |
5807d2b1-07bb-4765-b96a-58b6c24a990e | public void test_markGameLose(){
gameCore.markGameLose();
assertFalse(gameCore.win());
assertTrue(gameCore.lose());
} public void test_canMove(){ |
ccdf06ef-1853-4356-9752-316101830fc3 | } public void test_canMove(){
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.setBoard(mockBoards);
assertTrue(gameCore.canMove());
mockBoards = new int[][]{
{0,1,1,0},
{0,1,1,0},
{0,1,0,0},
{0,1,0,0}
};
gameCore.setBoard(mockBoards);
assertTrue(gameCore.canMove());
mockBoards = new int[][]{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1},
{1,1,1,1}
};
gameCore.setBoard(mockBoards);
assertTrue(gameCore.canMove());
mockBoards = new int[][]{
{2,2,1,1},
{2,2,1,1},
{2,2,1,1},
{2,2,1,1}
};
gameCore.setBoard(mockBoards);
assertTrue(gameCore.canMove());
mockBoards = new int[][]{
{2,3,1,0},
{7,6,5,4},
{2,3,1,6},
{6,5,4,1}
};
gameCore.setBoard(mockBoards);
assertFalse(gameCore.canMove());
} |
c589bcc3-104b-45bb-9c6a-2ee2fde626fb | public void test_lose(){
gameCore.resetGame();
assertFalse(gameCore.lose());
gameCore.markGameLose();
assertTrue(gameCore.lose());
} |
80c4d1c1-13f0-4122-a9ab-afcb7c1e846c | public void test_score(){
int[][] mockBoards = {
{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}
};
gameCore.resetGame();
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
assertEquals(0,gameCore.score());
mockBoards = new int[][]{
{1,1,1,1},
{0,0,0,0},
{2,2,2,2},
{0,0,0,0}
};
gameCore.resetGame();
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
assertEquals(12,gameCore.score());
mockBoards = new int[][]{
{1,0,0,0},
{2,0,0,0},
{2,0,0,0},
{2,0,0,0}
};
gameCore.resetGame();
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
assertEquals(0,gameCore.score());
mockBoards = new int[][]{
{1,2,3,4},
{2,3,3,3},
{2,2,2,2},
{2,3,3,3}
};
gameCore.resetGame();
gameCore.setBoard(mockBoards);
gameCore.tilt_board_left();
assertEquals(20,gameCore.score());
} |
89fe035d-9767-46b5-8a54-06df7e382229 | public static void main(String[] args) {
Result result = JUnitCore.runClasses(TestGame2048.class,WhiteBoxTestGame2048.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
} |
8fed5230-779d-4f3a-a118-027aa1570415 | public Tile() {
this(0);
} |
a4b8d384-fe4f-4fe6-aad1-fa3b085d76bf | public Tile(int num) {
value = num;
} |
1f3f9868-dca7-4671-ab86-09cae0bef8a9 | public Color getForeground() {
return value < 16 ? new Color(0x776e65) : new Color(0xf9f6f2);
} |
16dd0122-5e1e-456a-bfbc-bbf1c1a76e8d | public Color getBackground() {
switch (value) {
case 2:
return new Color(0xeee4da);
case 4:
return new Color(0xede0c8);
case 8:
return new Color(0xf2b179);
case 16:
return new Color(0xf59563);
case 32:
return new Color(0xf67c5f);
case 64:
return new Color(0xf65e3b);
case 128:
return new Color(0xedcf72);
case 256:
return new Color(0xedcc61);
case 512:
return new Color(0xedc850);
case 1024:
return new Color(0xedc53f);
case 2048:
return new Color(0xedc22e);
}
return new Color(0xcdc1b4);
} |
c51ebd20-1489-4acc-a4e5-613f4f9a3d6c | public void tilt_board_left(); |
aab3a6f0-5ede-491c-817f-2e664fb28595 | public int score(); |
7b7e221b-5b34-41d6-bedc-6f69cbd8522c | public void resetGame(); |
6f85c214-01c1-4cba-8b4d-a55795f6796b | public void tilt_board_right(); |
978a27dc-f696-4873-b433-dc31a320db45 | public void tilt_board_down(); |
e658190b-e6ac-4426-b264-baecc7a42038 | public void tilt_board_up(); |
4f069094-b2ba-4dd7-8539-1c18b634f02b | public int getNumber(int x, int y); |
8af1d605-0a85-4bbe-b60a-4cb2292be236 | public void markGameLose(); |
53c24b5f-ab00-4446-99cc-c4cc9121e33f | public boolean lose(); |
cee0c73e-c387-4da3-8294-bac95af5f009 | public boolean win(); |
e8484fe1-23f2-49ff-9663-e9b3762dea39 | public boolean canMove(); |
11b21de3-a2b1-4931-a223-1a35b2089794 | public int[][] getBoard(); |
64ca1509-3d93-4173-9b0c-622b5dd72ede | public void setBoard(int[][] board); |
ccf1a79b-7353-46b6-9847-77cfd656b24a | public Game2048Board() {
processer = new Game2048Core();
setFocusable(true);
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
processer.resetGame();
}
if (!processer.canMove()) {
processer.markGameLose();
}
if (!processer.win() && !processer.lose()) {
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
processer.tilt_board_left();
break;
case KeyEvent.VK_RIGHT:
processer.tilt_board_right();
break;
case KeyEvent.VK_DOWN:
processer.tilt_board_down();
break;
case KeyEvent.VK_UP:
processer.tilt_board_up();
break;
}
}
if (!processer.win() && !processer.canMove()) {
processer.markGameLose();
}
repaint();
}
});
processer.resetGame();
} |
40f01401-5727-4e2a-be33-0228c97a42e2 | @Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
processer.resetGame();
}
if (!processer.canMove()) {
processer.markGameLose();
}
if (!processer.win() && !processer.lose()) {
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
processer.tilt_board_left();
break;
case KeyEvent.VK_RIGHT:
processer.tilt_board_right();
break;
case KeyEvent.VK_DOWN:
processer.tilt_board_down();
break;
case KeyEvent.VK_UP:
processer.tilt_board_up();
break;
}
}
if (!processer.win() && !processer.canMove()) {
processer.markGameLose();
}
repaint();
} |
f128708c-a229-440b-b84a-97cca53ed99f | @Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(BG_COLOR);
g.fillRect(0, 0, this.getSize().width, this.getSize().height);
for (int y = 0; y < GameUtil.COLS; y++) {
for (int x = 0; x < GameUtil.COLS; x++) {
drawTile(g, new Tile(processer.getNumber(y, x)), x, y);
}
}
} |
88889379-9616-4c3d-8a7a-7d310ae54db3 | private void drawTile(Graphics g2, Tile tile, int x, int y) {
if (tile == null) {
return;
}
Graphics2D g = ((Graphics2D) g2);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
int value = tile.value;
int xOffset = offsetCoors(x);
int yOffset = offsetCoors(y);
g.setColor(tile.getBackground());
g.fillRoundRect(xOffset, yOffset, TILE_SIZE, TILE_SIZE, 14, 14);
g.setColor(tile.getForeground());
final int size = value < 100 ? 36 : value < 1000 ? 32 : 24;
final Font font = new Font(FONT_NAME, Font.BOLD, size);
g.setFont(font);
String s = String.valueOf(value);
final FontMetrics fm = getFontMetrics(font);
final int w = fm.stringWidth(s);
final int h = -(int) fm.getLineMetrics(s, g).getBaselineOffsets()[2];
if (value != 0)
g.drawString(s, xOffset + (TILE_SIZE - w) / 2, yOffset + TILE_SIZE
- (TILE_SIZE - h) / 2 - 2);
if (processer.win() || processer.lose()) {
g.setColor(new Color(255, 255, 255, 30));
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(new Color(78, 139, 202));
g.setFont(new Font(FONT_NAME, Font.BOLD, 48));
if (processer.win()) {
g.drawString("You won!", 68, 150);
}
if (processer.lose()) {
g.drawString("Game over!", 50, 130);
g.drawString("You lose!", 64, 200);
}
if (processer.win() || processer.lose()) {
g.setFont(new Font(FONT_NAME, Font.PLAIN, 16));
g.setColor(new Color(128, 128, 128, 128));
g.drawString("Press ESC to play again", 80, getHeight() - 40);
}
}
g.setFont(new Font(FONT_NAME, Font.PLAIN, 18));
g.drawString("Score: " + processer.score(), 200, 365);
} |
4dbacad7-b730-48c1-a087-a7eb9a363f01 | private static int offsetCoors(int arg) {
return arg * (TILES_MARGIN + TILE_SIZE) + TILES_MARGIN;
} |
66212c41-c4f0-4a53-9eeb-94dde09e9db9 | public int[] tilt_line_left(int[] oldLine) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < ROWS; i++) {
if (oldLine[i] != 0) {
list.add(new Integer(oldLine[i]));
}
}
if (list.size() == 0) {
return oldLine;
} else {
int[] after = new int[COLS];
for (int i = 0; i < list.size(); i++) {
after[i] = list.get(i).intValue();
}
return after;
}
} |
acfeea76-8816-49ea-b34c-d7459e27e6da | public int[] combine_tiles(int[] oldline) {
int j = 0;
int[] after = new int[COLS];
for (int i = 0; i < COLS && oldline[i] > 0; i++) {
int value = oldline[i];
if (i < COLS - 1 && oldline[i] == oldline[i + 1]) {
value *= 2;
// Calculate score here.
score += value;
after[j] = value;
i++;
} else {
after[j] = oldline[i];
}
j++;
}
return after;
} |
aa891795-8088-40fb-b6c2-e8c731f35c9b | public int[] tilt_line_left_combine(int[] oldline) {
return combine_tiles(tilt_line_left(oldline));
} |
f700ae79-7654-4343-95b7-97edefa18329 | public int[][] tilt_board_left(int[][] old) {
int[][] after = new int[ROWS][COLS];
for (int i = 0; i < COLS; i++) {
int[] line = tilt_line_left_combine(old[i]);
System.arraycopy(line, 0, after[i], 0, COLS);
}
return after;
} |
e5cda5f5-d1a1-43d3-ac93-c72111ccd536 | public int[][] tilt_board_up(int[][] old) {
int[][] temp = rotate_clockWise_270degree(old);
int[][] temp2 = tilt_board_left(temp);
return rotate_clockWise_90degree(temp2);
} |
f092c8c8-7e35-487a-9651-47c33674d030 | public int[][] tilt_board_down(int[][] old) {
int[][] temp = rotate_clockWise_90degree(old);
int[][] temp2 = tilt_board_left(temp);
return rotate_clockWise_270degree(temp2);
} |
96448b1b-c43a-4f78-acc0-54439b7f2b9c | public int[][] tilt_board_right(int[][] old) {
int[][] temp = rotate_clockWise_180degree(old);
int[][] temp2 = tilt_board_left(temp);
return rotate_clockWise_180degree(temp2);
} |
66f5eb07-b0be-4bf8-92fb-43aab1267a27 | public int[][] rotate_clockWise_90degree(int[][] old) {
if (old == null) {
return null;
}
int ROWS = old.length;
int COLS = old[0].length;
int[][] temp = new int[ROWS][COLS];
int dst = ROWS - 1;
// rotate the matrix clockwise 90 degree.
for (int i = 0; i < ROWS; i++, dst--) {
for (int j = 0; j < COLS; j++) {
temp[j][dst] = old[i][j];
}
}
return temp;
} |
2868b852-e505-4584-bdfe-81f6317ecde2 | public int[][] rotate_clockWise_180degree(int[][] old) {
return rotate_clockWise_90degree(rotate_clockWise_90degree(old));
} |
30c8a77a-1781-4f1f-95e4-aa5853725a20 | public int[][] rotate_clockWise_270degree(int[][] old) {
return rotate_clockWise_90degree(rotate_clockWise_90degree(rotate_clockWise_90degree(old)));
} |
321c2315-962f-4125-9c1a-26f98325e92a | private boolean isBoardFull() {
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
if (tiles[i][i] == 0) {
return false;
}
}
}
return true;
} |
9b96366f-10a2-4432-8c7e-28453f9e0a11 | public boolean canMove() {
if (!isBoardFull()) {
return true;
}
for (int x = 0; x < ROWS; x++) {
for (int y = 0; y < COLS; y++) {
if ((x < 3 && tiles[x][y] == tiles[x + 1][y])
|| ((y < 3) && tiles[x][y] == tiles[x][y + 1])) {
return true;
}
}
}
return false;
} |
d72ffa51-c1e7-4f13-90f5-9343acd8841b | public int getNumber(int x, int y) {
if (x < 0 || x >= ROWS || y < 0 || y >= COLS) {
return -1;
}
return tiles[x][y];
} |
3289f013-f11b-449b-a21a-4f895ad819b0 | public void resetGame() {
lose = false;
score=0;
tiles = new int[ROWS][COLS];
addANumber();
addANumber();
} |
312aff17-1999-444f-aedf-dbeb0d29a338 | private void addANumber() {
if (!isBoardFull()) {
ArrayList<String> emptySpots = GameUtil.snapshotEmptySpots(tiles);
int index = (int) (Math.random() * emptySpots.size())
% emptySpots.size();
String emptyLocation = emptySpots.get(index);
int x = Integer.parseInt(emptyLocation.substring(0, 1));
int y = Integer.parseInt(emptyLocation.substring(2, 3));
tiles[x][y] = Math.random() < 0.9 ? 2 : 4;
}
} |
ae6fc0ff-87d8-4e7b-9d8f-9a76fd6a2583 | public void tilt_board_down() {
int[][] tempTiles = tilt_board_down(tiles);
boolean needed = !GameUtil.compare(tempTiles, tiles);
tiles = tempTiles;
if (needed) {
addANumber();
}
} |
3f776118-0f48-40b5-a4a0-69b1c677313b | public void tilt_board_left() {
int[][] tempTiles = tilt_board_left(tiles);
boolean needed = !GameUtil.compare(tempTiles, tiles);
tiles = tempTiles;
if (needed) {
addANumber();
}
} |
199dd232-407b-4608-91b8-e098b140130a | public void tilt_board_right() {
int[][] tempTiles = tilt_board_right(tiles);
boolean needed = !GameUtil.compare(tempTiles, tiles);
tiles = tempTiles;
if (needed) {
addANumber();
}
} |
68698944-d37d-42c5-98dc-ec52924c5576 | public void tilt_board_up() {
int[][] tempTiles = tilt_board_up(tiles);
boolean needed = !GameUtil.compare(tempTiles, tiles);
tiles = tempTiles;
if (needed) {
addANumber();
}
} |
3ae152b9-4ae3-4dc7-b1df-bb13299f9230 | public void markGameLose() {
lose = true;
} |
760ad083-71b9-43d6-87f1-152f82eb62f0 | public boolean win() {
return score() == GameUtil.WINPOINTS_2048;
} |
d5211f90-2a3d-41e6-8ac2-d576b799b573 | public boolean lose() {
return lose;
} |
003497b1-c1b5-47d0-a7b7-4e35450a69dc | public int[][] getBoard() {
return tiles;
} |
cebd2c93-e3a5-414e-b9fb-d17deca7794a | public void setBoard(int[][] tiles) {
this.tiles = tiles;
} |
f78c8bdf-ab41-4fcc-9809-0dafacdec58a | public int score() {
return score;
} |
9a821b6c-4f31-4161-b5a3-7845d6e52c02 | public static void main(String[] args) {
JFrame game = new JFrame();
game.setTitle("2048 Game");
game.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
game.setSize(340, 400);
game.setResizable(false);
game.add(new Game2048Board());
game.setLocationRelativeTo(null);
game.setVisible(true);
} |
c6b8b48c-f073-4e73-bfab-4092157db363 | public static boolean compareExpectToActualLine(int[] expected, int[] actual) {
if (expected == null || actual == null
|| expected.length != actual.length) {
return false;
}
for (int i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
return false;
}
}
return true;
} |
1c5efb0f-3729-41d6-acde-171d8fde5dac | public static void printLine(int[] old, String message, int[] after,
int[] expected, String status) {
if (message == null || "".equalsIgnoreCase(message)) {
message = " after tilt_line_left became ";
}
String expectedStr = " and the expected is ";
System.out.println(convertLineToTxtWithSep(old) + message
+ GameUtil.convertLineToTxtWithSep(after) + expectedStr
+ GameUtil.convertLineToTxtWithSep(expected) + status);
} |
771d16cf-ab5b-407c-870d-5f08adebf681 | public static String convertLineToTxtWithSep(int[] value) {
if (value == null || value.length < 4) {
return "";
}
String txt = "{" + value[0] + SEP + value[1] + SEP + value[2] + SEP
+ value[3] + "}";
return txt;
} |
38f7cd32-d3f4-47c2-85f2-ccac9d1dd28b | public static String convertLineToTxtWithSep(int i1, int i2, int i3, int i4) {
String txt = "{" + i1 + SEP + i2 + SEP + i3 + SEP + i4 + "}";
return txt;
} |
d3ef0cc2-d072-42d9-8c05-a3898bf03fd8 | public static ArrayList<String> snapshotEmptySpots(int[][] tiles) {
ArrayList<String> emptySpots = new ArrayList<String>();
for (int x = 0; x < ROWS; x++) {
for (int y = 0; y < COLS; y++) {
if (tiles[x][y] == 0) {
emptySpots.add(x + "," + y);
}
}
}
return emptySpots;
} |
5b9b6242-84e6-4234-9e47-3283be7d44c6 | private static boolean compareLine(int[] line1, int[] line2){
if(line1 == line2){
return true;
}
if(line1.length!=line2.length){
return false;
}
for(int i=0;i<line1.length;i++){
if(line1[i]!=line2[i]){
return false;
}
}
return true;
} |
9ba1bc96-04a6-4d00-aea7-976ff7868862 | public static boolean compare(int[][] tempTiles, int[][] tiles2) {
if(tempTiles==null || tiles2==null){
return true;
}
for(int i=0;i<ROWS;i++){
if(!compareLine(tempTiles[i],tiles2[i])){
return false;
}
}
return true;
} |
aca18ae0-c9f3-4334-a66b-7519e221daa2 | public static boolean compareExpectToActualBoard(int[][] expected,
int[][] actual) {
for (int i = 0; i < expected.length; i++) {
if (!compareExpectToActualLine(expected[i], actual[i])) {
return false;
}
}
return true;
} |
1549dd70-15e6-4f48-8a6e-a5a689223fd3 | public static void printBoard(int[][] old, String message, int[][] after,
int[][] expected, String status) {
String expectedStr = " and the expected:";
if (message == null || "".equals(message)) {
message = "after tilt board let became";
}
StringBuffer bufer = new StringBuffer();
bufer.append("\n");
for (int i = 0; i < ROWS; i++) {
bufer.append(convertLineToTxtWithSepForBoardPrint(old[i])).append(
" ");
if (i < ROWS - 1) {
for (int j = 0; j < message.length(); j++) {
bufer.append(" ");
}
} else {
bufer.append(message);
}
bufer.append(" ").append(
convertLineToTxtWithSepForBoardPrint(after[i]));
if (i < ROWS - 1) {
for (int j = 0; j < expectedStr.length(); j++) {
bufer.append(" ");
}
} else {
bufer.append(expectedStr);
}
bufer.append(convertLineToTxtWithSepForBoardPrint(expected[i]))
.append("\n");
}
bufer.append(status);
System.out.println(bufer.toString());
} |
c8e08bdb-e799-4caa-a7e0-f81dcf6596ac | private static String convertLineToTxtWithSepForBoardPrint(int[] value) {
if (value == null || value.length < 4) {
return "";
}
String txt = "|" + value[0] + SEP + value[1] + SEP + value[2] + SEP
+ value[3] + "|";
return txt;
} |
317747d6-cade-45e0-b9da-8c89a1c1e40b | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Ingrese un día de la semana (número): ");
int v = scanner.nextInt();
String dia;
switch(v)
{
case 1:
dia = "Lunes";
break;
case 2:
dia = "Martes";
break;
case 3:
dia = "Miercoles";
break;
case 4:
dia = "Jueves";
break;
case 5:
dia = "Viernes";
break;
case 6:
dia = "Sábado";
break;
case 7:
dia = "Domingo";
break;
default:
dia = "Día incorrecto... El valor debe ser entre 1 y 7";
}
System.out.println(dia);
} |
401615ed-205a-426b-b489-082386a5dfab | public static void main(String[] args)
{
Scanner scanner = new Scanner (System.in);
System.out.print("Ingrese su edad: ");
int edad = scanner.nextInt();
if (edad>=21)
{
System.out.println("Usted es mayor de edad");
}
else
{
System.out.println("Usted es menor de edad");
}
} |
223c9afb-51f5-4ab3-b652-59de48a75d85 | public static void main (String[] args)
{
Scanner scanner = new Scanner (System.in);
//leo el valor de n
int n = scanner.nextInt();
int i = 1;
while (i <= n)
{
//muestro el valor de i
System.out.println(i);
//incremento el valor de i
i++;
}
} |
586fe2ad-f4b6-4ec9-8e18-c4636126588f | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int i = 1;
do {
System.out.println(i);
i++;
} while ( i <= n );
} |
66d6e638-3b34-4233-8ecd-b150f878bda1 | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Ingrese un valor: ");
int v = scanner.nextInt();
//obtener el resto de dividir v por 2
int resto = v % 2;
// Para preguntar por igual utilizaremos ==
if (resto == 0)
{
System.out.println(v+" es Par");
}
else
{
System.out.println(v+" es Impar");
}
//Utilizando un if in-line
String mssg = (resto == 0) ? "es Par": "es Impar";
//Muestro el resultado
System.out.println(mssg);
} |
21219630-a337-4ade-808a-9a981353aad1 | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
//Mensaje para el usuario
System.out.println("Ingrese nombre edad altura: ");
//Leemos el nombre
String nom = scanner.next();
//Leemos la edad
int edad = scanner.nextInt();
//Leemos la altura
double altura = scanner.nextDouble();
//Mostramos los datos por consola
System.out.println("Nombre: "+nom+" Edad: "+edad+" Altura: "+altura);
} |
03242cb8-2ade-4b91-aaa2-27c89b88bf30 | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for(int i=1;i<=n;i++)
{
System.out.println(i);
}
} |
08ec8336-007e-43fe-b1be-608c4467503c | public static void main(String[] args)
{
//define un array de 10 enteros
int arr[] = new int[10];
// usa el scanner para leer por teclado
Scanner scanner = new Scanner(System.in);
//leo el primer valor
System.out.println("Ingrese un valor (0=>fin): ");
int v = scanner.nextInt();
int i = 0;
// mientras v sea distinto de cero AND i sea menor que 10
while( v != 0 && i<10)
{
//asigna v en arr[i] y luego incrementa el valor de i
arr[i++] = v ;
//leo el siguiente valor
System.out.println("Ingrese un valor (0=>fin): ");
v = scanner.nextInt();
}
//recorro el array mostrando su contenido
for(int j=0;j<i;j++)
{
System.out.println(arr[j]);
}
} |
46777dcb-2547-48fb-8584-72f2c78ebe88 | public static void main(String[] args)
{
String dias[] = {"Lunes","Martes","Miercoles","Jueves","Viernes","Sabado","Domingo"};
Scanner scanner = new Scanner(System.in);
System.out.println("Ingrese un día de la semana (número): ");
int v = scanner.nextInt();
if (v <= dias.length)
{
System.out.println(dias[v-1]);
} else {
System.out.println("Día incorrecto...");
}
} |
afd299fb-7787-4b9a-a576-cdbcc2d455c1 | public static void main(String[] args)
{
Fecha f = new Fecha();
f.setDia(2);
f.setMes(10);
f.setAnio(1970);
System.out.println("Dia="+f.getDia());
System.out.println("Mes="+f.getMes());
System.out.println("Anio"+f.getAnio());
System.out.println(f);
} |
95c8b6bf-eebc-4b08-a4f8-23e064bfadb4 | public String toString()
{
return dia+"/"+mes+"/"+anio;
} |
ee006100-ccb3-4916-930a-bf2b355bac0f | public Fecha(String s)
{
int pos1=s.indexOf('/');
int pos2=s.lastIndexOf('/');
String sDia=s.substring(0,pos1);
dia = Integer.parseInt(sDia);
String sMes=s.substring(pos1+1,pos2);
mes = Integer.parseInt(sMes);
String sAnio = s.substring(pos2+1);
anio = Integer.parseInt(sAnio);
} |
37be7a54-4351-450b-8b8c-71025c84ed73 | public Fecha()
{
} |
ac6659b9-774a-4f54-b633-736eaeead2f6 | public Fecha(int d, int m, int a)
{
dia = d;
mes = m;
anio = a;
} |
8cb18878-86f1-46f2-818a-c8d7bba5bc87 | public int getDia()
{
return dia;
} |
9c7adfc0-ad13-4c9f-a6bc-6e762ef24bc2 | public void setDia (int dia)
{
this.dia = dia;
} |
77b4d243-076b-4db0-bbb8-7ac76e9e8d28 | public int getMes()
{
return mes;
} |
849d6cfe-ddfb-4678-8a8b-fbe8a2a8180f | public void setMes(int mes)
{
this.mes = mes;
} |
d18416fe-af8f-4497-b6d3-0413d1d882fa | public int getAnio()
{
return anio;
} |
7ed5c318-0353-406b-829d-df8086ba63b6 | public void setAnio(int anio)
{
this.anio = anio;
} |
7513d7b0-5295-4a10-864f-81eea6b68304 | private int fechaToDias()
{
return anio*360+mes*30+dia;
} |
3967e528-060f-4b0e-aa52-b39d29f29880 | private void diasToFecha(int i)
{
anio = (int)i/360;
int resto = i % 360;
mes = (int) resto/30;
dia = resto % 30;
if (dia == 0 )
{
dia = 30;
anio--;
}
if (mes == 0)
{
mes=12;
anio--;
}
} |
b0fc53d7-faa9-4fbc-a4c6-f0bcf994c86e | public void addDias(int d)
{
int sum = fechaToDias()+d;
diasToFecha(sum);
} |
c00ca15c-bb08-4076-9722-fc64521b50a5 | public boolean equals(Object o)
{
Fecha otra = (Fecha)o;
return (dia==otra.dia) && (mes==otra.mes) && (anio==otra.anio);
} |
f87a88a8-a3f3-4049-9e82-62da949de0c7 | public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Ingrese la fecha (dd/mm/aaaa): ");
String sFecha = scanner.next();
Fecha f = new Fecha(sFecha);
System.out.println("La Fecha ingresada es:"+f);
System.out.println("Ingrese días a sumar(pueden ser negativos)");
int diasSum = scanner.nextInt();
f.addDias(diasSum);
System.out.println("Sumando "+diasSum+" días, queda: "+f);
} |
9a7cb834-dda5-414a-b93d-d457645e0520 | @Override
public void onEvent(CalculateNumbersEvent event, long sequence, boolean endOfBatch) throws Exception {
CalculatedNumber fibonacciValue = event.getFibonacciValue();
CalculatedNumber factorialValue = event.getFactorialValue();
fibonacciValue.setBinaryRepresentation(Long.toBinaryString(fibonacciValue.getValue()));
factorialValue.setBinaryRepresentation(Long.toBinaryString(fibonacciValue.getValue()));
} |
b088d6a0-cfd3-46a0-b889-7ecb99c86047 | @Override
public void onEvent(CalculateNumbersEvent event, long sequence, boolean endOfBatch) throws Exception {
CalculatedNumber fibonacciValue = event.getFibonacciValue();
CalculatedNumber factorialValue = event.getFactorialValue();
fibonacciValue.setHexRepresentation(Long.toHexString(fibonacciValue.getValue()));
factorialValue.setHexRepresentation(Long.toHexString(factorialValue.getValue()));
} |