[Javamatch-cvs] javamatch/src/net/sourceforge/javamatch/engine/test ObjectValueQuery.java,NONE,1.1 M
Status: Pre-Alpha
Brought to you by:
iterson
From: Walter v. I. <it...@us...> - 2004-09-13 09:14:22
|
Update of /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/engine/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5800/javamatch/engine/test Modified Files: MatchEngineTest.java MatchResultTest.java Added Files: ObjectValueQuery.java Log Message: Added threshold value, minimum match value for objects to be included Index: MatchEngineTest.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/engine/test/MatchEngineTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MatchEngineTest.java 10 Sep 2004 14:22:17 -0000 1.3 --- MatchEngineTest.java 13 Sep 2004 09:14:11 -0000 1.4 *************** *** 21,24 **** --- 21,25 ---- import junit.framework.*; import net.sourceforge.javamatch.engine.*; + import net.sourceforge.javamatch.query.*; import net.sourceforge.javamatch.query.test.*; *************** *** 184,186 **** --- 185,210 ---- } } + + public void testThreshold() { + try { + MatchEngine engine = new MatchEngine(); + engine.setThreshold(0.3f); + MatchQuery query = new ObjectValueQuery("floatValue"); + Vector objects = new Vector(); + objects.add(new DataObject(0.0f)); + objects.add(new DataObject(0.1f)); + objects.add(new DataObject(0.2f)); + objects.add(new DataObject(0.3f)); + objects.add(new DataObject(0.4f)); + objects.add(new DataObject(0.5f)); + MatchResult result = engine.executeQuery(query, objects); + Iterator resultIterator = result.getResultIterator(); + assertEquals(0.5f, ((ResultItem)resultIterator.next()).getMatchValue(), 0.001f); + assertEquals(0.4f, ((ResultItem)resultIterator.next()).getMatchValue(), 0.001f); + assertEquals(0.3f, ((ResultItem)resultIterator.next()).getMatchValue(), 0.001f); + assertFalse(resultIterator.hasNext()); + } catch (MatchException me) { + fail("unable to match"); + } + } } --- NEW FILE: ObjectValueQuery.java --- /* JavaMatch: Matching engine for Java runtime data structures * Copyright (C) 2004 Walter van Iterson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.javamatch.engine.test; import net.sourceforge.javamatch.engine.*; import net.sourceforge.javamatch.query.*; /** * Class ObjectValueQuery returns the value of a member in the matched objects * as result of the match */ public class ObjectValueQuery extends NumericQuery { /** The member that is called */ private String memberName; /** * Crates a new ObjectValueQuery, which returns the value of the given member */ public ObjectValueQuery(String memberName) { this.memberName = memberName; } /** * Returns the match value of this constant match */ public float getMatchValue(Object targetObject) throws MatchException { return (float)getValue(targetObject, memberName); } } Index: MatchResultTest.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/engine/test/MatchResultTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MatchResultTest.java 7 Sep 2004 09:41:07 -0000 1.2 --- MatchResultTest.java 13 Sep 2004 09:14:11 -0000 1.3 *************** *** 335,338 **** --- 335,354 ---- } + public void testThreshold() { + MatchResult result = new MatchResult(engine); + result.setThreshold(0.3f); + result.addResultItem(new Object(), 0.0f); + result.addResultItem(new Object(), 0.1f); + result.addResultItem(new Object(), 0.2f); + result.addResultItem(new Object(), 0.3f); + result.addResultItem(new Object(), 0.4f); + result.addResultItem(new Object(), 0.5f); + Iterator resultIterator = result.getResultIterator(); + assertEquals(0.5f, ((ResultItem)(resultIterator.next())).getMatchValue(), 0.001f); + assertEquals(0.4f, ((ResultItem)(resultIterator.next())).getMatchValue(), 0.001f); + assertEquals(0.3f, ((ResultItem)(resultIterator.next())).getMatchValue(), 0.001f); + assertFalse(resultIterator.hasNext()); + } + public void testSetMaxNumResultItemsAfterAdd() { MatchResult result = new MatchResult(engine); |