/** * tests the listing of the options */ public void testListOptions() { if (!m_OptionTester.checkListOptions()) { fail("Options cannot be listed via listOptions."); } }
/** * Called by JUnit before each test method. This implementation creates the * default NearestNeighbourSearch to test and loads a test set of Instances. * * @exception Exception if an error occurs reading the example instances. */ @Override protected void setUp() throws Exception { m_NearestNeighbourSearch = getNearestNeighbourSearch(); m_OptionTester = getOptionTester(); m_GOETester = getGOETester(); m_Instances = getInstances(); m_NumNeighbors = 3; m_Random = new Random(1); }
/** * Runs a regression test -- this checks that the output of the tested object * matches that in a reference version. When this test is run without any * pre-existing reference output, the reference version is created. */ public void testRegression() { Regression reg; ArrayList<String> regressionResult; reg = new Regression(this.getClass()); try { regressionResult = useNearestNeighbourSearch(m_Instances); reg.println(resultsToString(regressionResult)); } catch (Exception e) { fail("Regression test failed: " + e); } try { String diff = reg.diff(); if (diff == null) { System.err.println("Warning: No reference available, creating."); } else if (!diff.equals("")) { fail("Regression test failed. Difference:\n" + diff); } } catch (java.io.IOException ex) { fail("Problem during regression testing.\n" + ex); } } }
/** * tests whether the number of instances returned by the algorithms is the * same as was requested */ public void testNumberOfNeighbors() { int i; int instIndex; Instances neighbors; try { m_NearestNeighbourSearch.setInstances(m_Instances); } catch (Exception e) { fail("Failed setting the instances: " + e); } for (i = 1; i <= m_NumNeighbors; i++) { instIndex = m_Random.nextInt(m_Instances.numInstances()); try { neighbors = m_NearestNeighbourSearch.kNearestNeighbours( m_Instances.instance(instIndex), i); assertEquals("Returned different number of neighbors than requested", i, neighbors.numInstances()); } catch (Exception e) { fail("Failed for " + i + " neighbors on instance " + (instIndex + 1) + ": " + e); } } }
/** * Configures the CheckOptionHandler uses for testing the option handling. * Sets the NearestNeighbourSearch returned from the * getNearestNeighbourSearch() method * * @return the fully configured CheckOptionHandler * @see #getNearestNeighbourSearch() */ protected CheckOptionHandler getOptionTester() { CheckOptionHandler result; result = new CheckOptionHandler(); result.setOptionHandler(getNearestNeighbourSearch()); result.setUserOptions(new String[0]); result.setSilent(true); return result; }
/** * tests whether the number of instances returned by the algorithms is the * same as was requested */ public void testNumberOfNeighbors() { int i; int instIndex; Instances neighbors; try { m_NearestNeighbourSearch.setInstances(m_Instances); } catch (Exception e) { fail("Failed setting the instances: " + e); } for (i = 1; i <= m_NumNeighbors; i++) { instIndex = m_Random.nextInt(m_Instances.numInstances()); try { neighbors = m_NearestNeighbourSearch.kNearestNeighbours( m_Instances.instance(instIndex), i); assertEquals("Returned different number of neighbors than requested", i, neighbors.numInstances()); } catch (Exception e) { fail("Failed for " + i + " neighbors on instance " + (instIndex + 1) + ": " + e); } } }
/** * Configures the CheckOptionHandler uses for testing the option handling. * Sets the NearestNeighbourSearch returned from the * getNearestNeighbourSearch() method * * @return the fully configured CheckOptionHandler * @see #getNearestNeighbourSearch() */ protected CheckOptionHandler getOptionTester() { CheckOptionHandler result; result = new CheckOptionHandler(); result.setOptionHandler(getNearestNeighbourSearch()); result.setUserOptions(new String[0]); result.setSilent(true); return result; }
/** * Called by JUnit before each test method. This implementation creates the * default NearestNeighbourSearch to test and loads a test set of Instances. * * @exception Exception if an error occurs reading the example instances. */ @Override protected void setUp() throws Exception { m_NearestNeighbourSearch = getNearestNeighbourSearch(); m_OptionTester = getOptionTester(); m_GOETester = getGOETester(); m_Instances = getInstances(); m_NumNeighbors = 3; m_Random = new Random(1); }
/** * tests whether there are any remaining options */ public void testRemainingOptions() { if (!m_OptionTester.checkRemainingOptions()) { fail("There were 'left-over' options."); } }
/** * Runs a regression test -- this checks that the output of the tested object * matches that in a reference version. When this test is run without any * pre-existing reference output, the reference version is created. */ public void testRegression() { Regression reg; ArrayList<String> regressionResult; reg = new Regression(this.getClass()); try { regressionResult = useNearestNeighbourSearch(m_Instances); reg.println(resultsToString(regressionResult)); } catch (Exception e) { fail("Regression test failed: " + e); } try { String diff = reg.diff(); if (diff == null) { System.err.println("Warning: No reference available, creating."); } else if (!diff.equals("")) { fail("Regression test failed. Difference:\n" + diff); } } catch (java.io.IOException ex) { fail("Problem during regression testing.\n" + ex); } } }
/** * Configures the CheckGOE used for testing GOE stuff. Sets the * NearestNeighbourSearch returned from the getNearestNeighbourSearch() * method. * * @return the fully configured CheckGOE * @see #getNearestNeighbourSearch() */ protected CheckGOE getGOETester() { CheckGOE result; result = new CheckGOE(); result.setObject(getNearestNeighbourSearch()); result.setIgnoredProperties(result.getIgnoredProperties() + ",instances"); result.setSilent(true); return result; }
/** * tests the setting of the options */ public void testSetOptions() { if (!m_OptionTester.checkSetOptions()) { fail("setOptions method failed."); } }
/** * Configures the CheckGOE used for testing GOE stuff. Sets the * NearestNeighbourSearch returned from the getNearestNeighbourSearch() * method. * * @return the fully configured CheckGOE * @see #getNearestNeighbourSearch() */ protected CheckGOE getGOETester() { CheckGOE result; result = new CheckGOE(); result.setObject(getNearestNeighbourSearch()); result.setIgnoredProperties(result.getIgnoredProperties() + ",instances"); result.setSilent(true); return result; }
/** * tests whether there are any remaining options */ public void testRemainingOptions() { if (!m_OptionTester.checkRemainingOptions()) { fail("There were 'left-over' options."); } }
/** * tests whether the default settings are processed correctly */ public void testDefaultOptions() { if (!m_OptionTester.checkDefaultOptions()) { fail("Default options were not processed correctly."); } }
/** * tests the resetting of the options to the default ones */ public void testResettingOptions() { if (!m_OptionTester.checkSetOptions()) { fail("Resetting of options failed"); } }
/** * tests for a globalInfo method */ public void testGlobalInfo() { if (!m_GOETester.checkGlobalInfo()) { fail("No globalInfo method"); } }
/** * tests the tool tips */ public void testToolTips() { if (!m_GOETester.checkToolTips()) { fail("Tool tips inconsistent"); } }
/** * tests the whether the user-supplied options stay the same after setting. * getting, and re-setting again. * * @see #getOptionTester() */ public void testCanonicalUserOptions() { if (!m_OptionTester.checkCanonicalUserOptions()) { fail("setOptions method failed"); } }
/** * tests whether the scheme declares a serialVersionUID. */ public void testSerialVersionUID() { boolean result; result = !SerializationHelper.needsUID(m_NearestNeighbourSearch.getClass()); if (!result) { fail("Doesn't declare serialVersionUID!"); } }