1 /*
2 * Copyright 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.examples;
17
18 import eu.simuline.octave.OctaveEngine;
19 import eu.simuline.octave.OctaveEngineFactory;
20 import eu.simuline.octave.type.OctaveDouble;
21
22 import static org.junit.Assert.assertEquals;
23
24 import org.junit.Ignore;
25 import org.junit.Test;
26
27 /**
28 * http://kenai.com/projects/javaoctave/pages/SimpleExampleOfJavaOctaveUsage
29 */
30 public class SimpleExampleTest {
31
32 /** Test */
33 @Test public void test() {
34 // Begin web text
35 final OctaveEngine octave = new OctaveEngineFactory().getScriptEngine();
36 final OctaveDouble a = new OctaveDouble(new double[] {1, 2, 3, 4 },
37 2, 2);
38 octave.put("a", a);
39 final String func = "" //
40 + "function res = my_func(a)\n" //
41 + " res = 2 * a;\n" //
42 + "endfunction\n" //
43 + "";
44 octave.eval(func);
45 octave.eval("b = my_func(a);");
46 final OctaveDouble b = octave.get(OctaveDouble.class, "b");
47 octave.close();
48 // End web text
49 assertEquals(8.0, b.get(2, 2), 0.0);
50 }
51
52 }