View Javadoc
1   /*
2    * Copyright 2007, 2008, 2009 Ange Optimization ApS
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package eu.simuline.octave.io.impl;
17  
18  import eu.simuline.octave.OctaveEngine;
19  import eu.simuline.octave.OctaveEngineFactory;
20  import eu.simuline.octave.io.OctaveIO;
21  import eu.simuline.octave.type.OctaveFunctionHandle;
22  import eu.simuline.octave.type.OctaveObject;
23  
24  import static org.junit.Assert.assertEquals;
25  
26  import org.junit.Ignore;
27  import org.junit.Test;
28  
29  
30  /**
31   * Test read/write of {@link OctaveFunctionHandle}
32   */
33  public class TestIoFunctionHandle {
34  
35      /** Test */
36      @Test public void testToString() {
37          final OctaveObject fh = 
38  	    new OctaveFunctionHandle("@(x) sqrt (1 - x ^ 2)");
39          assertEquals("# name: ans\n" + //
40  		     "# type: function handle\n" + //
41  		     "@<anonymous>\n" + //
42  		     "@(x) sqrt (1 - x ^ 2)\n" + //
43  		     "# length: 0\n", 
44  		     OctaveIO.toText(fh));
45      }
46  
47      /** Test */
48      @Test public void testToOctave() {
49          final OctaveObject fh = 
50  	    new OctaveFunctionHandle("@(x) sqrt (1 - x ^ 2)");
51          assertEquals("# name: fh\n" + //
52  		     "# type: function handle\n" + //
53  		     "@<anonymous>\n" + //
54  		     "@(x) sqrt (1 - x ^ 2)\n" + //
55  		     "# length: 0\n", 
56  		     OctaveIO.toText("fh", fh));
57      }
58  
59      /** Test */
60      @Test public void testOctaveConnection() {
61          final OctaveEngine octave = new OctaveEngineFactory().getScriptEngine();
62          if (octave.getVersion().equals("3.0.5")) {
63              octave.close();
64              return; // Skip test on octave 3.0.5
65          }
66          final OctaveObject fh1 = 
67  	    new OctaveFunctionHandle("@(x) sqrt (1 - x ^ 2)");
68          octave.put("fh", fh1);
69          // TODO enable when reading of OctaveFunctionHandle is done
70          // final OctaveObject fh2 = octave.get(OctaveString.class, "fh");
71          // assertEquals(s1, s2);
72          octave.close();
73      }
74  
75  }