[Remoterengine-commits] r129 - in pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote: client common
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 15 12:18:20 CEST 2009
Author: ian_long
Date: 2009-09-15 12:18:19 +0200 (Tue, 15 Sep 2009)
New Revision: 129
Added:
pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/client/TestFactors.java
pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/common/RemoteREngineTestBase.java
Log:
-- Added first TestNG test case - within a new source tree, starting "test"
Added: pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/client/TestFactors.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/client/TestFactors.java (rev 0)
+++ pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/client/TestFactors.java 2009-09-15 10:18:19 UTC (rev 129)
@@ -0,0 +1,60 @@
+package org.rosuda.REngine.remote.client;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.rosuda.REngine.REXP;
+import org.rosuda.REngine.REXPFactor;
+import org.rosuda.REngine.RFactor;
+import org.rosuda.REngine.remote.common.RemoteREngineTestBase;
+
+/*
+ * Copyright Stoat Software & Services 2009 <ilong at stoatsoftware.com>
+ *
+ * This file is part of the RemoteREngine project
+ *
+ * The RemoteREngine project 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The RemoteREngine project 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 the RemoteREngine project. If not, see <http://www.gnu.org/licenses/>.
+ * @author $Author$
+ * @version $Rev$ as of $Date$
+ * <p>URL : $HeadURL$
+ */
+public class TestFactors extends RemoteREngineTestBase {
+
+ @Test
+ public void testFactors() throws Exception {
+ System.out.println("* Test support of factors");
+ REXP f = r.parseAndEval("factor(paste('F',as.integer(runif(20)*5),sep=''))");
+ System.out.println(" f="+f);
+ System.out.println(" isFactor: "+f.isFactor()+", asFactor: "+f.asFactor());
+ Assert.assertNotNull( f.isFactor(), "Returned a null factor");
+ assert( f.isFactor()) : "Failed to return a factor";
+
+/* System.out.println(" singe-level factor used to degenerate:");
+ f = r.parseAndEval("factor('foo')");
+ System.out.println(" isFactor: "+f.isFactor()+", asFactor: "+f.asFactor());
+ if (!f.isFactor() || f.asFactor() == null) throw new TestException("single factor test failed (not a factor)");
+ if (!f.asFactor().at(0).equals("foo")) throw new TestException("single factor test failed (wrong value)");
+ System.out.println(" test factors with null elements contents:");
+ r.assign("f", new REXPFactor(new RFactor(new String[] { "foo", "bar", "foo", "foo", null, "bar" })));
+ f = r.parseAndEval("f");
+ if (!f.isFactor() || f.asFactor() == null) throw new TestException("factor assign-eval test failed (not a factor)");
+ System.out.println(" f = "+f.asFactor());
+ f = r.parseAndEval("as.factor(c(1,'a','b',1,'b'))");
+ System.out.println(" f = "+f);
+ if (!f.isFactor() || f.asFactor() == null) throw new TestException("factor test failed (not a factor)");
+ System.out.println("PASSED");
+*/
+ }
+}
Property changes on: pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/client/TestFactors.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author HeadURL Id
Added: pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/common/RemoteREngineTestBase.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/common/RemoteREngineTestBase.java (rev 0)
+++ pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/common/RemoteREngineTestBase.java 2009-09-15 10:18:19 UTC (rev 129)
@@ -0,0 +1,74 @@
+package org.rosuda.REngine.remote.common;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.rosuda.REngine.remote.client.RemoteREngine;
+import org.testng.annotations.BeforeSuite;
+
+/*
+ * Copyright Stoat Software & Services 2009 <ilong at stoatsoftware.com>
+ *
+ * This file is part of the RemoteREngine project
+ *
+ * The RemoteREngine project 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The RemoteREngine project 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 the RemoteREngine project. If not, see <http://www.gnu.org/licenses/>.
+ * @author $Author$
+ * @version $Rev$ as of $Date$
+ * <p>URL : $HeadURL$
+ */
+public class RemoteREngineTestBase {
+ /** Instance of the Remote R Engine available for tests */
+ protected static RemoteREngine r = init();
+
+ /**
+ * Create a connection to a running remote server
+ * @return Reference to a remote engine
+ */
+ @BeforeSuite
+ protected static RemoteREngine init(){
+/* Properties props = System.getProperties();
+ for (Enumeration<?> enumerator = props.keys(); enumerator.hasMoreElements(); ) {
+ String key = (String)enumerator.nextElement();
+ String value = props.getProperty(key);
+ System.out.println(key + " : " + value);
+ }
+*/
+ RemoteREngine r = null ;
+ String name = "RemoteREngineTest";
+ int registryPort = RemoteREngineConstants.RMIPORT;
+ try{
+ if (System.getSecurityManager() == null) {
+ System.setSecurityManager(new SecurityManager());
+ }
+ r = new RemoteREngine( name , RemoteREngineConstants.RMIHOSTNAME , registryPort );
+ System.out.println("Connected to " + name + " via " + RemoteREngineConstants.RMIHOSTNAME +
+ " registry on port " + registryPort);
+ } catch( Exception e ){
+ System.err.println( "cannot connect to R engine" ) ;
+ System.exit(1);
+ }
+ return r;
+ }
+
+ protected static RemoteREngine cleanR(){
+ try{
+ r.parseAndEval( "rm( list = ls() )" ) ;
+ } catch(Exception e){
+ // should not happen
+ }
+ return r;
+ }
+
+}
Property changes on: pkg/RemoteREngine/inst/java_src/test/org/rosuda/REngine/remote/common/RemoteREngineTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author HeadURL Id
More information about the Remoterengine-commits
mailing list