View Javadoc

1   /***
2    * Jetrix TetriNET Server
3    * Copyright (C) 2005  Emmanuel Bourg
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package net.jetrix.filter;
21  
22  import java.io.File;
23  
24  import junit.framework.*;
25  import net.jetrix.config.*;
26  
27  /***
28   * @author Emmanuel Bourg
29   * @version $Revision: 836 $, $Date: 2010-04-11 23:25:35 +0200 (dim., 11 avr. 2010) $
30   */
31  public class DownstackPuzzleGeneratorTest extends TestCase
32  {
33      public void testGetNextPuzzle()
34      {
35          PuzzleGenerator generator = new DownstackPuzzleGenerator();
36          
37          for (int i = 0; i < 100; i++)
38          {
39              Puzzle puzzle = generator.getNextPuzzle();
40              assertNotNull("puzzle null", puzzle);
41              assertNotNull("null settings", puzzle.getSettings());
42          }
43      }
44  
45      public void testLoadPuzzle() throws Exception
46      {
47          DownstackPuzzleGenerator generator = new DownstackPuzzleGenerator();
48          Puzzle puzzle = generator.loadPuzzle(new File("data/puzzle"), "game3");
49          
50          assertNotNull("puzzle null", puzzle);
51          assertEquals("author", "NiLS", puzzle.getAuthor());
52          assertEquals("name", "Left or Right", puzzle.getName());
53          assertEquals("comment", "no comment", puzzle.getComment());
54  
55          assertNotNull("null field", puzzle.getField());
56          assertFalse("empty field", puzzle.getField().isEmpty());
57  
58          Settings settings = puzzle.getSettings();
59          assertNotNull("null settings", settings);
60          
61          int[] blocks = { 14, 14, 15, 14, 14, 14, 15 };
62          for (int i = 0; i < DownstackPuzzleGenerator.BLOCKS.length; i++)
63          {
64              Block block = DownstackPuzzleGenerator.BLOCKS[i];
65              assertEquals(block.getCode() + " occurancy", blocks[i], settings.getOccurancy(block));
66          }
67  
68          int[] specials = { 32, 18, 1, 11, 3, 14, 1, 6, 14 };
69          for (Special special : Special.values())
70          {
71              assertEquals(special.getCode() + " occurancy", specials[special.ordinal()], settings.getOccurancy(special));
72          }
73          
74          assertEquals("sudden death message", "Time's up! It's SUDDEN DEATH MODE!", settings.getSuddenDeathMessage());
75          assertEquals("sudden death delay", 30, settings.getSuddenDeathDelay());
76          assertEquals("sudden death time", 180, settings.getSuddenDeathTime());
77          assertEquals("sudden death lines", 1, settings.getSuddenDeathLinesAdded());
78  
79          // RULES 1 2 1 1 0 18 1 1
80          assertEquals("starting level", 1, settings.getStartingLevel());
81          assertEquals("lines per level", 2, settings.getLinesPerLevel());
82          assertEquals("level increase", 1, settings.getLevelIncrease());
83          assertEquals("lines per special", 1, settings.getLinesPerSpecial());
84          assertEquals("special added", 0, settings.getSpecialAdded());
85          assertEquals("special capacity", 18, settings.getSpecialCapacity());
86          assertEquals("classic rules", true, settings.getClassicRules());
87          assertEquals("average levels", true, settings.getAverageLevels());
88      }
89  }