| 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, Hamilton, New Zealand |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | package weka.core.converters; |
|---|
| 22 | |
|---|
| 23 | import java.io.File; |
|---|
| 24 | |
|---|
| 25 | import junit.framework.Test; |
|---|
| 26 | import junit.framework.TestSuite; |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Tests C45Loader/C45Saver. Run from the command line with:<p/> |
|---|
| 30 | * java weka.core.converters.C45Test |
|---|
| 31 | * |
|---|
| 32 | * @author FracPete (fracpete at waikato dot ac dot nz) |
|---|
| 33 | * @version $Revision: 1.1 $ |
|---|
| 34 | */ |
|---|
| 35 | public class C45Test |
|---|
| 36 | extends AbstractFileConverterTest { |
|---|
| 37 | |
|---|
| 38 | /** the name of the data file */ |
|---|
| 39 | protected String m_ExportFilenameData; |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Constructs the <code>C45Test</code>. |
|---|
| 43 | * |
|---|
| 44 | * @param name the name of the test class |
|---|
| 45 | */ |
|---|
| 46 | public C45Test(String name) { |
|---|
| 47 | super(name); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * returns the loader used in the tests |
|---|
| 52 | * |
|---|
| 53 | * @return the configured loader |
|---|
| 54 | */ |
|---|
| 55 | public AbstractLoader getLoader() { |
|---|
| 56 | return new C45Loader(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * returns the saver used in the tests |
|---|
| 61 | * |
|---|
| 62 | * @return the configured saver |
|---|
| 63 | */ |
|---|
| 64 | public AbstractSaver getSaver() { |
|---|
| 65 | return new C45Saver(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * returns the filename for the data file. |
|---|
| 70 | * |
|---|
| 71 | * @return the filename |
|---|
| 72 | */ |
|---|
| 73 | protected String getExportFilenameData() { |
|---|
| 74 | return m_ExportFilename.replaceAll("\\.names", ".data"); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * returns the command line options, either for the loader or the saver |
|---|
| 79 | * |
|---|
| 80 | * @param loader if true the options for the loader will be returned, |
|---|
| 81 | * otherwise the ones for the saver |
|---|
| 82 | * @return the command line options |
|---|
| 83 | */ |
|---|
| 84 | protected String[] getCommandlineOptions(boolean loader) { |
|---|
| 85 | if (loader) |
|---|
| 86 | return super.getCommandlineOptions(loader); |
|---|
| 87 | else |
|---|
| 88 | return new String[]{"-i", m_SourceFilename, "-o", m_ExportFilename, "-c", "last"}; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | /** |
|---|
| 92 | * Called by JUnit before each test method. |
|---|
| 93 | * |
|---|
| 94 | * @throws Exception if an error occurs reading the example instances. |
|---|
| 95 | */ |
|---|
| 96 | protected void setUp() throws Exception { |
|---|
| 97 | File file; |
|---|
| 98 | |
|---|
| 99 | super.setUp(); |
|---|
| 100 | |
|---|
| 101 | m_ExportFilenameData = getExportFilenameData(); |
|---|
| 102 | |
|---|
| 103 | // delete temp. files |
|---|
| 104 | file = new File(m_ExportFilenameData); |
|---|
| 105 | if (file.exists()) |
|---|
| 106 | file.delete(); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Called by JUnit after each test method |
|---|
| 111 | */ |
|---|
| 112 | protected void tearDown() throws Exception { |
|---|
| 113 | File file; |
|---|
| 114 | |
|---|
| 115 | // delete temp. files |
|---|
| 116 | file = new File(m_ExportFilenameData); |
|---|
| 117 | if (file.exists()) |
|---|
| 118 | file.delete(); |
|---|
| 119 | |
|---|
| 120 | m_ExportFilenameData = null; |
|---|
| 121 | |
|---|
| 122 | super.tearDown(); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | * ignored, since not supported! |
|---|
| 127 | */ |
|---|
| 128 | public void testLoaderWithStream() { |
|---|
| 129 | System.out.println("testLoaderWithStream is ignored!"); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | /** |
|---|
| 133 | * returns a test suite |
|---|
| 134 | * |
|---|
| 135 | * @return the test suite |
|---|
| 136 | */ |
|---|
| 137 | public static Test suite() { |
|---|
| 138 | return new TestSuite(C45Test.class); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | /** |
|---|
| 142 | * for running the test from commandline |
|---|
| 143 | * |
|---|
| 144 | * @param args the commandline arguments - ignored |
|---|
| 145 | */ |
|---|
| 146 | public static void main(String[] args){ |
|---|
| 147 | junit.textui.TestRunner.run(suite()); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|