icfp-model/src/test/java/ru/bosony/tests/TestMineParsing.java
author indvdum (gotoindvdum[at]gmail[dot]com)
Sun, 15 Jul 2012 00:48:47 +0400
changeset 18 735c03e46425
parent 7 251961e44b5f
permissions -rw-r--r--
Moving example maps to special separate class
     1 package ru.bosony.tests;
     2 
     3 import static org.junit.Assert.assertEquals;
     4 
     5 import org.junit.Test;
     6 
     7 import ru.bosony.model.maps.ExampleMaps;
     8 import ru.bosony.model.mine.Mine;
     9 
    10 /**
    11  * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
    12  *         14.07.2012 0:37:14
    13  * 
    14  */
    15 public class TestMineParsing {
    16 
    17 	protected static String alignMap(String map) {
    18 		String alignedMap = "";
    19 		String[] rows = map.split("\n");
    20 		int y = rows.length;
    21 		int x = 0;
    22 		for (String row : rows) {
    23 			if (x < row.length())
    24 				x = row.length();
    25 		}
    26 		for (int curY = 0; curY < rows.length; curY++) {
    27 			String row = rows[curY];
    28 			for (int curX = 0; curX < row.length() || curX < x; curX++) {
    29 				if (curX < row.length())
    30 					alignedMap += row.charAt(curX);
    31 				else
    32 					alignedMap += " ";
    33 			}
    34 			alignedMap += "\n";
    35 		}
    36 		return alignedMap.replaceAll("\n$", "");
    37 	}
    38 
    39 	@Test
    40 	public void testMap01() {
    41 		String map = ExampleMaps.MAP_01.getMap();
    42 		Mine mine = new Mine(map);
    43 		String parsed = mine.toText();
    44 		assertEquals(alignMap(map), parsed);
    45 	}
    46 
    47 	@Test
    48 	public void testMap02() {
    49 		String map = ExampleMaps.MAP_02.getMap();
    50 		Mine mine = new Mine(map);
    51 		String parsed = mine.toText();
    52 		assertEquals(alignMap(map), parsed);
    53 	}
    54 
    55 	@Test
    56 	public void testMap03() {
    57 		String map = ExampleMaps.MAP_03.getMap();
    58 		Mine mine = new Mine(map);
    59 		String parsed = mine.toText();
    60 		assertEquals(alignMap(map), parsed);
    61 	}
    62 
    63 	@Test
    64 	public void testMap04() {
    65 		String map = ExampleMaps.MAP_04.getMap();
    66 		Mine mine = new Mine(map);
    67 		String parsed = mine.toText();
    68 		assertEquals(alignMap(map), parsed);
    69 	}
    70 
    71 	@Test
    72 	public void testMap05() {
    73 		String map = ExampleMaps.MAP_05.getMap();
    74 		Mine mine = new Mine(map);
    75 		String parsed = mine.toText();
    76 		assertEquals(alignMap(map), parsed);
    77 	}
    78 
    79 	@Test
    80 	public void testMap06() {
    81 		String map = ExampleMaps.MAP_06.getMap();
    82 		Mine mine = new Mine(map);
    83 		String parsed = mine.toText();
    84 		assertEquals(alignMap(map), parsed);
    85 	}
    86 
    87 	@Test
    88 	public void testMap07() {
    89 		String map = ExampleMaps.MAP_07.getMap();
    90 		Mine mine = new Mine(map);
    91 		String parsed = mine.toText();
    92 		assertEquals(alignMap(map), parsed);
    93 	}
    94 
    95 	@Test
    96 	public void testMap08() {
    97 		String map = ExampleMaps.MAP_08.getMap();
    98 		Mine mine = new Mine(map);
    99 		String parsed = mine.toText();
   100 		assertEquals(alignMap(map), parsed);
   101 	}
   102 
   103 	@Test
   104 	public void testMap09() {
   105 		String map = ExampleMaps.MAP_09.getMap();
   106 		Mine mine = new Mine(map);
   107 		String parsed = mine.toText();
   108 		assertEquals(alignMap(map), parsed);
   109 	}
   110 
   111 	@Test
   112 	public void testMap10() {
   113 		String map = ExampleMaps.MAP_10.getMap();
   114 		Mine mine = new Mine(map);
   115 		String parsed = mine.toText();
   116 		assertEquals(alignMap(map), parsed);
   117 	}
   118 
   119 }