From: <Jen...@us...> - 2008-08-19 15:23:57
|
Revision: 1101 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1101&view=rev Author: JensLehmann Date: 2008-08-19 15:23:53 +0000 (Tue, 19 Aug 2008) Log Message: ----------- - unit test, which verifies that all learning problems are working (learn a concept) - feature request #1892798 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java Modified: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-08-19 14:28:27 UTC (rev 1100) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-08-19 15:23:53 UTC (rev 1101) @@ -39,7 +39,7 @@ */ public class QuickStart { - static HashMap<String, ArrayList<String>> hm = null; +// static HashMap<String, ArrayList<String>> hm = null; static String pm = ".";// pathmodifier public static void main(String[] args) { @@ -50,10 +50,10 @@ ArrayList<String> finalSelection = new ArrayList<String>(); finalSelection.add("na"); - hm = new HashMap<String, ArrayList<String>>(); + HashMap<String, ArrayList<String>> hm = new HashMap<String, ArrayList<String>>(); String path = pm + File.separator + "examples"; File f = new File(path); - getAllConfs(f, path); + getAllConfs(f, path, hm); // System.out.println(hm.size()); Iterator<String> i = hm.keySet().iterator(); @@ -148,7 +148,7 @@ // System.out.println(f.isDirectory()+f.getAbsolutePath()); } - public static void getAllConfs(File f, String path) { + public static void getAllConfs(File f, String path, HashMap<String, ArrayList<String>> confs) { path = path + File.separator; // System.out.println(path); String[] act = f.list(); @@ -157,13 +157,13 @@ if (new File(path + act[i]).isDirectory()) { - getAllConfs(new File(path + act[i]), path + act[i]); + getAllConfs(new File(path + act[i]), path + act[i], confs); // al.add(new File(act[i])); } else if (act[i].endsWith(".conf")) { - if (hm.get(path) == null) { - hm.put(path, new ArrayList<String>()); + if (confs.get(path) == null) { + confs.put(path, new ArrayList<String>()); } - hm.get(path).add(act[i].substring(0, act[i].length() - 5)); + confs.get(path).add(act[i].substring(0, act[i].length() - 5)); // System.out.println(act[i].substring(0,act[i].length()-5)); // System.out.println(hm.get(path).size()); // hm.put(new Added: trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java 2008-08-19 15:23:53 UTC (rev 1101) @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test.junit; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; + +import org.dllearner.cli.QuickStart; +import org.dllearner.cli.Start; +import org.dllearner.core.ComponentInitException; +import org.junit.Test; + +/** + * Tests related to learning problems in the examples directory. + * + * @author Jens Lehmann + * + */ +public class ExampleTests { + + /** + * This test runs all conf files in the examples directory. Each conf file corresponds to one + * unit test, which is succesful if a concept was learned. + * @throws ComponentInitException If any component initialisation exception occurs in the process. + */ + @Test + public void testAllConfFiles() throws ComponentInitException { + // map containing a list of conf files for each path + HashMap<String, ArrayList<String>> confFiles = new HashMap<String, ArrayList<String>>(); + String exampleDir = "." + File.separator + "examples"; + File f = new File(exampleDir); + QuickStart.getAllConfs(f, exampleDir, confFiles); + + for(String path : confFiles.keySet()) { + for(String file : confFiles.get(path)) { + String conf = path + file + ".conf"; + // start example + Start start = new Start(new File(conf)); + start.start(false); + // test is successful if a concept was learned + assert(start.getLearningAlgorithm().getCurrentlyBestDescription() != null); + } + } + + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |