From 39428d86e51ac51d981a2702e0a5ecf1eb463be3 Mon Sep 17 00:00:00 2001
From: kovax <kovax@eduard>
Date: Sun, 1 Dec 2013 16:57:29 +0100
Subject: [PATCH] =?UTF-8?q?JUnit=20tesztel=C3=A9sek.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 nbproject/project.properties               | 151 +++++++++++----------
 settings2.dat                              | Bin 9283 -> 9270 bytes
 src/GUI/game/Model.java                    |   7 +-
 src/GUI/game/RecursiveNullFinder.java      |  28 +++-
 test/GUI/game/ModelTest.java               | 123 +++++++++++++++++
 test/GUI/game/RecursiveNullFinderTest.java | 151 +++++++++++++++++++++
 6 files changed, 382 insertions(+), 78 deletions(-)
 create mode 100644 test/GUI/game/ModelTest.java
 create mode 100644 test/GUI/game/RecursiveNullFinderTest.java

diff --git a/nbproject/project.properties b/nbproject/project.properties
index 09c70e6..7da044b 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -1,75 +1,76 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=false
-annotation.processing.processors.list=
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=Minesweeper2
-application.vendor=D\u00e1niel
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-# Uncomment to specify the preferred debugger connection transport:
-#debug.transport=dt_socket
-debug.classpath=\
-    ${run.classpath}
-debug.test.classpath=\
-    ${run.test.classpath}
-# Files in build.classes.dir which should be excluded from distribution jar
-dist.archive.excludes=
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/Minesweeper2.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-endorsed.classpath=
-excludes=
-includes=**
-jar.compress=false
-javac.classpath=
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.processorpath=\
-    ${javac.classpath}
-javac.source=1.7
-javac.target=1.7
-javac.test.classpath=\
-    ${javac.classpath}:\
-    ${build.classes.dir}
-javac.test.processorpath=\
-    ${javac.test.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-main.class=Program.Program
-manifest.file=manifest.mf
-meta.inf.dir=${src.dir}/META-INF
-mkdist.disabled=false
-platform.active=default_platform
-run.classpath=\
-    ${javac.classpath}:\
-    ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project.
-# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
-# To set system properties for unit tests define test-sys-prop.name=value:
-run.jvmargs=
-run.test.classpath=\
-    ${javac.test.classpath}:\
-    ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-test.src.dir=test
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=Minesweeper2
+application.vendor=D\u00e1niel
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+    ${run.classpath}
+debug.test.classpath=\
+    ${run.test.classpath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/Minesweeper2.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+    ${javac.classpath}
+javac.source=1.7
+javac.target=1.7
+javac.test.classpath=\
+    ${javac.classpath}:\
+    ${build.classes.dir}:\
+    ${libs.junit_4.classpath}
+javac.test.processorpath=\
+    ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+main.class=Program.Program
+manifest.file=manifest.mf
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+run.classpath=\
+    ${javac.classpath}:\
+    ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=
+run.test.classpath=\
+    ${javac.test.classpath}:\
+    ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/settings2.dat b/settings2.dat
index 843909e98fcbd1f726ce8eb901724fbcb52991de..5b05a879b88d367f8a80a7845fb958acecbd093c 100644
GIT binary patch
delta 197
zcmX@?vCU(H5i5t^rkhKx4<>)xY{e?dCM3WB1B?uej0_A6XErBtA7_<Hgb6di#2FYE
zK=LA+odh*mgoH8VH`j`OWo4c9|NsBDo6Ds+*cj6$Hz>9+rfp_bn#{;PJLn4o1B2G&
z`N}cYOyw*L3=CYwg$#8JCxRd{3MCA@p?P_Uxv41uIf<32MIgzO6(tP3#i=DFnR)5O
JMtUiUB>*H2F}(l)

delta 192
zcmdnyaoA&n5i7^e$>%-ynZ7FBY{e?dCZxas1B?uej0_A6dp0L>A7_<HfC)3e#2FYE
zK=PuSodh*mghVjpH`j`OWo2FT|Ns9to6Ds+*cjs`Hz>9+#%*R*n#{;PO)8Lqfx%?*
ueB~G;=5iJW1_tKhLWVkq6G0FepArVP;=~jXLKe;`VPG~iGM=oUA_f4TGAla(

diff --git a/src/GUI/game/Model.java b/src/GUI/game/Model.java
index b8cf67c..c91a58e 100644
--- a/src/GUI/game/Model.java
+++ b/src/GUI/game/Model.java
@@ -263,7 +263,7 @@ public class Model
         
         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 )
         {
@@ -367,6 +367,11 @@ public class Model
             this.squares[x][y].setBackground(color);
             this.squares[x][y].setForeground(colorF);
     }
+    /**
+     * Amikor a user megjelol egy poziciot, akkor ez fut le.
+     * 
+     * @param pos 
+     */
     void flagButton(int[] pos) 
     {
         if( isGameOver )
diff --git a/src/GUI/game/RecursiveNullFinder.java b/src/GUI/game/RecursiveNullFinder.java
index 4ee1190..5e61dc9 100644
--- a/src/GUI/game/RecursiveNullFinder.java
+++ b/src/GUI/game/RecursiveNullFinder.java
@@ -27,7 +27,13 @@ public class RecursiveNullFinder extends Thread
         this.wasThere   = wasThere;
         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 )
             wasThere = new ArrayList<>();
@@ -75,6 +81,14 @@ public class RecursiveNullFinder extends Thread
         }
         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)
     {
         for( int[] act : container)
@@ -84,16 +98,26 @@ public class RecursiveNullFinder extends Thread
         }
         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)
     {
         for (int[] actTo : to  ) 
         {
-            if( actTo == add )
+            if( actTo[0] == add[0] && actTo[1] == add[1] )
                 return to;
         }
         to.add(add);
         return to;
     }
+    /**
+     * A szál indítása
+     */
     @Override
     public void run()
     {
diff --git a/test/GUI/game/ModelTest.java b/test/GUI/game/ModelTest.java
new file mode 100644
index 0000000..f566358
--- /dev/null
+++ b/test/GUI/game/ModelTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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());
+    }
+    
+}
diff --git a/test/GUI/game/RecursiveNullFinderTest.java b/test/GUI/game/RecursiveNullFinderTest.java
new file mode 100644
index 0000000..182f24b
--- /dev/null
+++ b/test/GUI/game/RecursiveNullFinderTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.
+    }
+    
+}
-- 
GitLab