org-mode/testing/examples/ob-maxima-test.org

146 lines
3.2 KiB
Org Mode
Raw Normal View History

#+Title: a collection of examples for ob-maxima tests
#+OPTIONS: ^:nil
* Simple tests
:PROPERTIES:
:ID: b5842ed4-8e8b-4b18-a1c9-cef006b6a6c8
:END:
#+begin_src maxima :var s=4 :results silent
print(s);
#+end_src
Pass a string
#+begin_src maxima :var fun="sin(x)" :var q=2 :results silent
print(diff(fun, x, q))$
#+end_src
* Graphic output
Graphic output
#+begin_src maxima :var a=0.5 :results graphics :file maxima-test-sin.png
plot2d(sin(a*x), [x, 0, 2*%pi])$
#+end_src
#+begin_src maxima :results graphics :file maxima-test-3d.png
plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2])$
#+end_src
* lisp/ob-maxima.el: enable use of `batch' loader and `draw' * (org-babel-header-args:maxima): Document the two new header arguments (batch and graphics-pkg) that are specific to ob-maxima. * (org-babel-maxima--command-arguments-default): A new variable storing the default command-line argument(s). This value was hard-coded in `org-babel-maxima:execute'. * (org-babel-maxima--graphic-package-options): A new variable that stores an alist of Maxima graphics packages and the Maxima code to set up that package. * (org-babel-maxima--default-epilogue): A new variable that stores an alist of the clean-up code that is run at end of a `graphical-output' or `non-graphical-output' source block. * (org-babel-maxima--output-filter-regexps): A new variable that stores a list of regexps to identify "bad" output lines to be removed from Maxima's output. Source-code comments document each regexp's purpose. Two additional regexps have been added: one filters un-wanted output from `batch' and the other removes empty input lines that `batch'-ed output may spuriously produce (actual empty input lines are syntax errors, see the new tests below). * (org-babel-maxima--output-filter): A new function that takes a single line of Maxima output. It returns nil if the line has zero length or matches a regexp in `org-babel-maxima--output-filter-regexps'; otherwise, it returns the line. This function and regexp replace the hard-coded filter in `org-babel-execute:maxima'. * (org-babel-maxima-expand): Prepare the source block for execution, depending on whether it is producing graphical output or not. In case of graphical output, use the `graphics-pkg' header to set the graphics package and use `org-babel-maxima--graphic-package-options' to set-up the package. Grovel the graphics terminal from the output filename. * (org-babel-execute:maxima): Use the :batch header argument and `org-babel-maxima--command-arguments-default' to execute the source block. Replace the existing, in-line output filter and its regexps with `org-babel-maxima--output-filter' and `org-babel-maxima--output-filter-regexps'. * testing/examples/ob-maxima-test.org: Add test examples. Include examples of the batch-related tests from testing/lisp/test-ob-maxima.el. Provide an example of the `:graphics-pkg' header argument with the `draw' package. * testing/lisp/test-ob-maxima.el: Introduce six new, batch-related test functions. Each test exercises the :batch header argument. The response to unusual inputs is tested (empty strings, strings with just whitespace, input with the `:lisp' reader, and two syntax-related errors). link: https://list.orgmode.org/87cyz1ivzw.fsf@t14.reltub.ca/
2023-09-19 14:36:06 -04:00
** Use the ~draw~ package
This test exercises the ~:graphics-pkg~ header argument.
#+name: ob-maxima/draw
#+begin_src maxima :var a=0.5 :results graphics file :file ./maxima-test-cos.png :graphics-pkg draw
draw2d(explicit(cos(a*x), x, -%pi, %pi))$
#+end_src
* Output to a file
Output to a file
#+begin_src maxima :file maxima-test-ouput.out
for i:1 thru 10 do print(i)$
#+end_src
* List input
:PROPERTIES:
:ID: b5561c6a-73cd-453a-ba5e-62ad84844de6
:END:
Simple list as an input
#+begin_src maxima :var a=(list 1 2 3) :results silent :results verbatim
print(a)$
#+end_src
#+begin_src maxima :var a=(list 1 (list 1 2) 3) :results silent :results verbatim
print(a+1);
#+end_src
* Table input
:PROPERTIES:
:ID: 400ee228-6b12-44fd-8097-7986f0f0db43
:END:
#+name: test_tbl_col
| 1.0 |
| 2.0 |
#+name: test_tbl_row
| 1.0 | 2.0 |
#+begin_src maxima :var s=test_tbl_col :results silent :results verbatim
print(s+1.0);
#+end_src
#+begin_src maxima :var s=test_tbl_row :results silent :results verbatim
print(s+1.0);
#+end_src
Matrix
#+name: test_tbl_mtr
| 1.0 | 1.0 |
#+begin_src maxima :var s=test_tbl_mtr :results silent :results verbatim
ms: apply(matrix, s);
print(ms);
#+end_src
* Construct a table from the output
:PROPERTIES:
:ID: cc158527-b867-4b1d-8ae0-b8c713a90fd7
:END:
#+begin_src maxima :results silent
with_stdout("/dev/null", load(numericalio))$
m: genmatrix (lambda([i,j], i+j-1), 3, 3)$
write_data(m, "/dev/stdout")$
#+end_src
* LaTeX output
#+begin_src maxima :exports both :results latex :results verbatim
assume(x>0);
tex(ratsimp(diff(%e^(a*x), x)));
#+end_src
#+results:
#+BEGIN_LaTeX
$$a\,e^{a\,x}$$
#+END_LaTeX
* lisp/ob-maxima.el: enable use of `batch' loader and `draw' * (org-babel-header-args:maxima): Document the two new header arguments (batch and graphics-pkg) that are specific to ob-maxima. * (org-babel-maxima--command-arguments-default): A new variable storing the default command-line argument(s). This value was hard-coded in `org-babel-maxima:execute'. * (org-babel-maxima--graphic-package-options): A new variable that stores an alist of Maxima graphics packages and the Maxima code to set up that package. * (org-babel-maxima--default-epilogue): A new variable that stores an alist of the clean-up code that is run at end of a `graphical-output' or `non-graphical-output' source block. * (org-babel-maxima--output-filter-regexps): A new variable that stores a list of regexps to identify "bad" output lines to be removed from Maxima's output. Source-code comments document each regexp's purpose. Two additional regexps have been added: one filters un-wanted output from `batch' and the other removes empty input lines that `batch'-ed output may spuriously produce (actual empty input lines are syntax errors, see the new tests below). * (org-babel-maxima--output-filter): A new function that takes a single line of Maxima output. It returns nil if the line has zero length or matches a regexp in `org-babel-maxima--output-filter-regexps'; otherwise, it returns the line. This function and regexp replace the hard-coded filter in `org-babel-execute:maxima'. * (org-babel-maxima-expand): Prepare the source block for execution, depending on whether it is producing graphical output or not. In case of graphical output, use the `graphics-pkg' header to set the graphics package and use `org-babel-maxima--graphic-package-options' to set-up the package. Grovel the graphics terminal from the output filename. * (org-babel-execute:maxima): Use the :batch header argument and `org-babel-maxima--command-arguments-default' to execute the source block. Replace the existing, in-line output filter and its regexps with `org-babel-maxima--output-filter' and `org-babel-maxima--output-filter-regexps'. * testing/examples/ob-maxima-test.org: Add test examples. Include examples of the batch-related tests from testing/lisp/test-ob-maxima.el. Provide an example of the `:graphics-pkg' header argument with the `draw' package. * testing/lisp/test-ob-maxima.el: Introduce six new, batch-related test functions. Each test exercises the :batch header argument. The response to unusual inputs is tested (empty strings, strings with just whitespace, input with the `:lisp' reader, and two syntax-related errors). link: https://list.orgmode.org/87cyz1ivzw.fsf@t14.reltub.ca/
2023-09-19 14:36:06 -04:00
* Batch
:PROPERTIES:
:header-args:maxima: :exports both :results verbatim :batch batch
:END:
Exercise the ~:batch~ header argument. These tests are also defined in
~testing/lisp/test-ob-maxima.el~. The test name is name of the ~ert~
test.
#+name: ob-maxima/batch+verbatim
#+begin_src maxima
(assume(z>0),
integrate(exp(-t)*t^z, t, 0, inf));
#+end_src
#+name: ob-maxima/batch+verbatim+quiet
#+begin_src maxima :cmdline --quiet
(assume(z>0),
integrate(exp(-t)*t^z, t, 0, inf));
#+end_src
#+name: ob-maxima/batch+verbatim+:lisp
#+begin_src maxima :cmdline --quiet
:lisp #$(assume(z>0),integrate(exp(-t)*t^z, t, 0, inf));#$
#+end_src
#+name: ob-maxima/batch+verbatim+empty-string
#+begin_src maxima :cmdline --quiet
"";
#+end_src
#+name: ob-maxima/batch+verbatim+whitespace-string
#+begin_src maxima :cmdline --quiet
" ";
#+end_src
#+name: ob-maxima/batch+verbatim+syntax-error
#+begin_src maxima :cmdline --quiet
;
#+end_src
#+name: ob-maxima/batch+verbatim+eof-error
#+begin_src maxima :cmdline --quiet
x:
#+end_src