source: src/test/java/weka/core/SingleIndexTest.java @ 27

Last change on this file since 27 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 3.6 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * Copyright (C) 2006 University of Waikato
19 */
20
21package weka.core;
22
23import junit.framework.Test;
24import junit.framework.TestCase;
25import junit.framework.TestSuite;
26
27/**
28 * Tests SingleIndex. Run from the command line with:<p/>
29 * java weka.core.SingleIndexTest
30 *
31 * @author FracPete (fracpete at waikato dot ac dot nz)
32 * @version $Revision: 1.1 $
33 */
34public class SingleIndexTest 
35  extends TestCase {
36 
37  /**
38   * Constructs the <code>SingleIndexTest</code>.
39   *
40   * @param name the name of the test class
41   */
42  public SingleIndexTest(String name) { 
43    super(name); 
44  }
45 
46  /**
47   * Called by JUnit before each test method.
48   *
49   * @throws Exception if an error occurs
50   */
51  protected void setUp() throws Exception {
52    super.setUp();
53  }
54
55  /** Called by JUnit after each test method */
56  protected void tearDown() throws Exception {
57    super.tearDown();
58  }
59
60  /**
61   * returns a configured SingleIndex
62   *
63   * @param initial     the initial string, if null the default constructor
64   *                    is used (and "1" is set - otherwise setUpper doesn't
65   *                    work!)
66   * @param upper       the upper limit
67   */
68  protected SingleIndex getIndex(String initial, int upper) {
69    SingleIndex   result; 
70
71    if (initial == null) {
72      result = new SingleIndex();
73      result.setSingleIndex("1");
74      result.setUpper(upper);
75    }
76    else {
77      result = new SingleIndex(initial);
78      result.setUpper(upper);
79    }
80
81    return result;
82  }
83
84  /**
85   * test the default constructor
86   */
87  public void testDefaultConstructor() throws Exception {
88    int upper = 10;
89    int indexInt = 0;
90    String indexStr = "" + (indexInt + 1);
91    SingleIndex index = new SingleIndex();
92    index.setSingleIndex(indexStr);
93    index.setUpper(upper);
94
95    assertEquals(indexStr, index.getSingleIndex());
96    assertEquals(indexInt, index.getIndex());
97  }
98
99  /**
100   * tests the constructor with initial value
101   */
102  public void testInitialValueConstructor() throws Exception {
103    int upper = 10;
104    int indexInt = 0;
105    String indexStr = "" + (indexInt + 1);
106    SingleIndex index = getIndex("1", upper);
107
108    assertEquals(indexStr, index.getSingleIndex());
109    assertEquals(indexInt, index.getIndex());
110  }
111
112  /**
113   * tests whether "first" is interpreted correctly
114   */
115  public void testFirst() throws Exception {
116    int upper = 10;
117    SingleIndex index = getIndex("first", upper);
118
119    assertEquals(0, index.getIndex());
120    assertEquals("first", index.getSingleIndex());
121  }
122
123  /**
124   * tests whether "last" is interpreted correctly
125   */
126  public void testLast() throws Exception {
127    int upper = 10;
128    SingleIndex index = getIndex("last", upper);
129
130    assertEquals(upper, index.getIndex());
131    assertEquals("last", index.getSingleIndex());
132  }
133
134  public static Test suite() {
135    return new TestSuite(SingleIndexTest.class);
136  }
137
138  public static void main(String[] args){
139    junit.textui.TestRunner.run(suite());
140  }
141}
Note: See TracBrowser for help on using the repository browser.