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) 2005 University of Waikato, Hamilton, New Zealand |
---|
19 | */ |
---|
20 | |
---|
21 | package weka.datagenerators; |
---|
22 | |
---|
23 | import weka.core.CheckGOE; |
---|
24 | import weka.core.SerializationHelper; |
---|
25 | |
---|
26 | import junit.framework.TestCase; |
---|
27 | |
---|
28 | /** |
---|
29 | * Abstract Test class for ClusterDefinitions. |
---|
30 | * |
---|
31 | * @author FracPete (fracpete at waikato dot ac dot nz) |
---|
32 | * @version $Revision: 1.3 $ |
---|
33 | */ |
---|
34 | public abstract class AbstractClusterDefinitionTest |
---|
35 | extends TestCase { |
---|
36 | |
---|
37 | /** The cluster definition to be tested */ |
---|
38 | protected ClusterDefinition m_Definition; |
---|
39 | |
---|
40 | /** for testing GOE stuff */ |
---|
41 | protected CheckGOE m_GOETester; |
---|
42 | |
---|
43 | /** |
---|
44 | * Constructs the <code>AbstractClusterDefinitionTest</code>. |
---|
45 | * Called by subclasses. |
---|
46 | * |
---|
47 | * @param name the name of the test class |
---|
48 | */ |
---|
49 | public AbstractClusterDefinitionTest(String name) { |
---|
50 | super(name); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Called by JUnit before each test method. This implementation creates |
---|
55 | * the default cluster definition to test. |
---|
56 | * |
---|
57 | * @throws Exception if an error occurs |
---|
58 | */ |
---|
59 | protected void setUp() throws Exception { |
---|
60 | m_Definition = getDefinition(); |
---|
61 | m_GOETester = getGOETester(); |
---|
62 | } |
---|
63 | |
---|
64 | /** Called by JUnit after each test method */ |
---|
65 | protected void tearDown() { |
---|
66 | m_Definition = null; |
---|
67 | m_GOETester = null; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Used to create an instance of a specific ClusterDefinition. |
---|
72 | * |
---|
73 | * @return a suitably configured <code>ClusterDefinition</code> value |
---|
74 | */ |
---|
75 | public abstract ClusterDefinition getDefinition(); |
---|
76 | |
---|
77 | /** |
---|
78 | * Configures the CheckGOE used for testing GOE stuff. |
---|
79 | * Sets the ClusterDefinition returned from the getDefinition() method. |
---|
80 | * |
---|
81 | * @return the fully configured CheckGOE |
---|
82 | * @see #getDefinition() |
---|
83 | */ |
---|
84 | protected CheckGOE getGOETester() { |
---|
85 | CheckGOE result; |
---|
86 | |
---|
87 | result = new CheckGOE(); |
---|
88 | result.setObject(getDefinition()); |
---|
89 | result.setSilent(true); |
---|
90 | |
---|
91 | return result; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * tests whether setting the options returned by getOptions() works |
---|
96 | */ |
---|
97 | public void testOptions() { |
---|
98 | try { |
---|
99 | m_Definition.setOptions(m_Definition.getOptions()); |
---|
100 | } |
---|
101 | catch (Exception e) { |
---|
102 | fail("setOptions(getOptions()) does not work: " + e.getMessage()); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * tests whether the scheme declares a serialVersionUID. |
---|
108 | */ |
---|
109 | public void testSerialVersionUID() { |
---|
110 | if (SerializationHelper.needsUID(m_Definition.getClass())) |
---|
111 | fail("Doesn't declare serialVersionUID!"); |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * tests for a globalInfo method |
---|
116 | */ |
---|
117 | public void testGlobalInfo() { |
---|
118 | if (!m_GOETester.checkGlobalInfo()) |
---|
119 | fail("No globalInfo method"); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * tests the tool tips |
---|
124 | */ |
---|
125 | public void testToolTips() { |
---|
126 | if (!m_GOETester.checkToolTips()) |
---|
127 | fail("Tool tips inconsistent"); |
---|
128 | } |
---|
129 | } |
---|