Skip to content
Snippets Groups Projects
Commit 39428d86 authored by kovax's avatar kovax
Browse files

JUnit tesztelések.

parent 745f66ef
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,8 @@ javac.source=1.7 ...@@ -41,7 +41,8 @@ javac.source=1.7
javac.target=1.7 javac.target=1.7
javac.test.classpath=\ javac.test.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir} ${build.classes.dir}:\
${libs.junit_4.classpath}
javac.test.processorpath=\ javac.test.processorpath=\
${javac.test.classpath} ${javac.test.classpath}
javadoc.additionalparam= javadoc.additionalparam=
......
No preview for this file type
...@@ -263,7 +263,7 @@ public class Model ...@@ -263,7 +263,7 @@ public class Model
return po; return po;
} }
private boolean isMined(int x, int y) public boolean isMined(int x, int y)
{ {
if( x < 0 || y < 0 || x > controller.game.game.settings.size || y > controller.game.game.settings.size ) if( x < 0 || y < 0 || x > controller.game.game.settings.size || y > controller.game.game.settings.size )
{ {
...@@ -367,6 +367,11 @@ public class Model ...@@ -367,6 +367,11 @@ public class Model
this.squares[x][y].setBackground(color); this.squares[x][y].setBackground(color);
this.squares[x][y].setForeground(colorF); this.squares[x][y].setForeground(colorF);
} }
/**
* Amikor a user megjelol egy poziciot, akkor ez fut le.
*
* @param pos
*/
void flagButton(int[] pos) void flagButton(int[] pos)
{ {
if( isGameOver ) if( isGameOver )
......
...@@ -27,7 +27,13 @@ public class RecursiveNullFinder extends Thread ...@@ -27,7 +27,13 @@ public class RecursiveNullFinder extends Thread
this.wasThere = wasThere; this.wasThere = wasThere;
this.controller = controller; this.controller = controller;
} }
private ArrayList<int[]> getNullFieldAround() /**
* getNullFieldAround()
* Megkeresi az adott elem koruli osszes nulla ertekkel rendelkezo elemet.
*
* @return
*/
public ArrayList<int[]> getNullFieldAround()
{ {
if( wasThere == null ) if( wasThere == null )
wasThere = new ArrayList<>(); wasThere = new ArrayList<>();
...@@ -75,6 +81,14 @@ public class RecursiveNullFinder extends Thread ...@@ -75,6 +81,14 @@ public class RecursiveNullFinder extends Thread
} }
return nullsAround; return nullsAround;
} }
/**
* X-Y koordináták alapján keres az ArrayListben, ha a koordináta benne van, true-t ad vissza, ha nem false-ot.
*
*
* @param container
* @param position
* @return
*/
public Boolean isContains(ArrayList<int[]> container, int[] position) public Boolean isContains(ArrayList<int[]> container, int[] position)
{ {
for( int[] act : container) for( int[] act : container)
...@@ -84,16 +98,26 @@ public class RecursiveNullFinder extends Thread ...@@ -84,16 +98,26 @@ public class RecursiveNullFinder extends Thread
} }
return false; return false;
} }
/**
* ArrayList-be helyez be elemeket, úgy, hogy ha az elem már szerepelt, nem rakja be mégegyszer.
*
* @param to
* @param add
* @return
*/
public ArrayList<int[]> addUnique(ArrayList<int[]> to, int[] add) public ArrayList<int[]> addUnique(ArrayList<int[]> to, int[] add)
{ {
for (int[] actTo : to ) for (int[] actTo : to )
{ {
if( actTo == add ) if( actTo[0] == add[0] && actTo[1] == add[1] )
return to; return to;
} }
to.add(add); to.add(add);
return to; return to;
} }
/**
* A szál indítása
*/
@Override @Override
public void run() public void run()
{ {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GUI.game;
import Program.Settings;
import java.awt.Color;
import javax.swing.JButton;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author kovax
*/
public class ModelTest {
public ModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
/*
0123
0*X** 2,2 3,2 2,3 3,3
1**** x: 3 y= 2
2****
3****
*/
/**
* Test of calculateMinesAround method, of class Model.
*/
@Test
public void testCalculateMinesAround() {
System.out.println("colorField");
int[] pos = {1,1};
Program.Settings settings = new Settings(4, "Test", 1, 600, 600);
GUI.game.Game game = new Game(settings, new Program.Game(settings));
game.controller.model.build();
//2,2
int mines = 0;
if( game.controller.model.isMined(0, 0) )
mines++;
if( game.controller.model.isMined(2, 0) )
mines++;
if( game.controller.model.isMined(0, 1) )
mines++;
if( game.controller.model.isMined(1, 1) )
mines++;
if( game.controller.model.isMined(2, 1) )
mines++;
if( game.controller.model.isMined(1, 0))
mines++;
int realValue = game.controller.model.calculateMinesAround(1, 0);
System.out.println("Mines:" + mines + "real:" + realValue);
assertEquals(mines, realValue);
}
/**
* Test of colorField method, of class Model.
*/
@Test
public void testColorField() {
//this.squares[x][y].setBackground(color);
//this.squares[x][y].setForeground(colorF);
System.out.println("colorField");
int[] pos = {1,1};
Program.Settings settings = new Settings(4, "Test", 1, 600, 600);
GUI.game.Game game = new Game(settings, new Program.Game(settings));
game.controller.model.build();
game.controller.model.colorField(1, 1, Color.blue, Color.yellow);
assertEquals(Color.blue,game.controller.model.squares[1][1].getBackground());
assertEquals(Color.yellow, game.controller.model.squares[1][1].getForeground());
}
/*
1234
1**** 2,2 3,2 2,3 3,3
2**** x: 3 y= 2
3****
4****
*/
/**
* Test of flagButton method, of class Model.
*
*/
@Test
public void testFlagButton() {
System.out.println("flagButton");
int[] pos = {1,1};
Program.Settings settings = new Settings(4, "Test", 1, 600, 600);
GUI.game.Game game = new Game(settings, new Program.Game(settings));
game.controller.model.build();
game.controller.model.flagButton(pos);
assertEquals("?", game.controller.model.squares[1][1].getText());
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GUI.game;
import Program.Settings;
import java.util.ArrayList;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author kovax
*/
public class RecursiveNullFinderTest {
//private
public RecursiveNullFinderTest()
{
}
/*
1234
1**** 2,2 3,2 2,3 3,3
2**** x: 3 y= 2
3****
4****
*/
/**
* Test of isContains method, of class RecursiveNullFinder.
*/
@Test
public void testIsContains() {
System.out.println("isContains");
ArrayList<int[]> container = new ArrayList<>();
int[] a = {1,1};
int[] b = {1,2};
int[] c = {2,5};
int[] d = {5,6};
container.add(a);
container.add(b);
container.add(c);
container.add(d);
int[] position = {1,1};
RecursiveNullFinder instance = new RecursiveNullFinder(1, 1, null, null, null);
Boolean expResult = null;
Boolean result = instance.isContains(container, position);
assertEquals(true, result);
// TODO review the generated test code and remove the default call to fail.
}
@Test
public void getNullFieldsAroundTest()
{
RecursiveNullFinder recur;
ArrayList<int[]> nulls = new ArrayList<>();
ArrayList<int[]> wasthere;
Program.Settings settings = new Settings(4, "Test", 1, 600, 600);
GUI.game.Game game = new Game(settings, new Program.Game(settings));
int[] testNullA = {2,2};
int[] testNullB = {3,2};
int[] testNullC = {2,3};
int[] testNullD = {3,3};
nulls.add(testNullA);
nulls.add(testNullB);
nulls.add(testNullC);
nulls.add(testNullD);
wasthere = new ArrayList<>();
recur = new RecursiveNullFinder(3, 2, nulls, wasthere, game.controller);
System.out.println("RecursiveNullFinderTest");
ArrayList<int[]> result = recur.getNullFieldAround();
ArrayList<int[]> expected = new ArrayList<>();
expected.add(testNullA);
expected.add(testNullB);
expected.add(testNullC);
expected.add(testNullD);
assertArrayEquals(expected.get(1), result.get(1));
}
/**
* Test of addUnique method, of class RecursiveNullFinder.
*/
@Test
public void testAddUnique() {
System.out.println("addUnique");
ArrayList<int[]> to = new ArrayList<>();
int[] a = {1,1};
int[] b = {1,2};
int[] c = {2,5};
int[] d = {5,6};
int[] add1 = {1,2};
int[] add2 = {1,3};
to.add(a);
to.add(b);
to.add(c);
to.add(d);
RecursiveNullFinder instance = new RecursiveNullFinder(1, 1, null, null, null);
ArrayList<int[]> expResult = new ArrayList<>();
expResult.add(a);
expResult.add(b);
expResult.add(c);
expResult.add(d);
expResult.add(add2);
ArrayList<int[]> result = instance.addUnique(to, add1);
result = instance.addUnique(result, add2);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment