-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...java/WFC_dungeon_gen/domain/MyRandom.java → ...n/java/WFC_dungeon_gen/util/MyRandom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package WFC_dungeon_gen.domain; | ||
package WFC_dungeon_gen.util; | ||
|
||
import java.util.Random; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,79 @@ | ||
/* | ||
* 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 WFC_dungeon_gen.domain; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import WFC_dungeon_gen.dao.TileSetTestData; | ||
import java.io.FileNotFoundException; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* | ||
* @author scyti | ||
* @author Juha Kauppinen | ||
*/ | ||
public class SolverTest { | ||
|
||
|
||
private Solver map; | ||
private int width; | ||
private int depth; | ||
private TileSet tileSet; | ||
|
||
public SolverTest() { | ||
this.depth = 5; | ||
this.width = 5; | ||
try { | ||
tileSet = new TileSetTestData().loadTileSet("hello"); | ||
} catch (FileNotFoundException ex) { | ||
System.out.println("error loading data"); | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownClass() { | ||
} | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
int numTiles = tileSet.getNumberOfTiles(); | ||
boolean[][][] rules = tileSet.getAdjacencyRules(); | ||
int[] weights = tileSet.getTileWeights(); | ||
this.map = new Solver(this.width, this.depth, numTiles, weights, rules); | ||
} | ||
|
||
@Test | ||
public void mapInitializesToRightDimension() { | ||
int[][] intMap = this.map.getMap(); | ||
assertEquals(this.width, intMap[0].length); | ||
assertEquals(this.depth, intMap.length); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
|
||
@Test | ||
public void mapIsInitializedToMinusOne() { | ||
this.map.initMap(); | ||
int[][] intMap = this.map.getMap(); | ||
for (int i = 0; i < this.depth; i++) { | ||
for (int j = 0; j < this.width; j++) { | ||
assertEquals(-1, intMap[i][j]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Test of printMaze method, of class Solver. | ||
*/ | ||
@Test | ||
public void testPrintMaze() { | ||
assertEquals(true, true); | ||
public void tilesAreSelectedRandomly() { | ||
int sum = 0; | ||
int cycles = 1000; | ||
|
||
for (int x = 0; x < cycles; x++) { | ||
map.initMap(); | ||
map.step(); | ||
int[][] intMap = map.getMap(); | ||
|
||
for (int i = 0; i < depth; i++) { | ||
for (int j = 0; j < width; j++) { | ||
if (intMap[i][j] != -1) { | ||
int value = i * depth + j; | ||
sum += value; | ||
} | ||
} | ||
} | ||
} | ||
int average = sum / cycles; | ||
assertEquals(average, (width * depth) / 2, 2); | ||
} | ||
|
||
} |