Changeset View
Changeset View
Standalone View
Standalone View
src/backends/julia/tests/testjulia.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This program is free software; you can redistribute it and/or | ||||
3 | * modify it under the terms of the GNU General Public License | ||||
4 | * as published by the Free Software Foundation; either version 2 | ||||
5 | * of the License, or (at your option) any later version. | ||||
6 | * | ||||
7 | * This program is distributed in the hope that it will be useful, | ||||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
10 | * GNU General Public License for more details. | ||||
11 | * | ||||
12 | * You should have received a copy of the GNU General Public License | ||||
13 | * along with this program; if not, write to the Free Software | ||||
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
15 | * Boston, MA 02110-1301, USA. | ||||
16 | * | ||||
17 | * --- | ||||
18 | * Copyright (C) 2016 Ivan Lakhtanov <ivan.lakhtanov@gmail.com> | ||||
19 | */ | ||||
20 | #include "testjulia.h" | ||||
21 | | ||||
22 | #include "session.h" | ||||
23 | #include "backend.h" | ||||
24 | #include "expression.h" | ||||
25 | #include "result.h" | ||||
26 | | ||||
27 | QString TestJulia::backendName() | ||||
28 | { | ||||
29 | return QLatin1String("julia"); | ||||
30 | } | ||||
31 | | ||||
32 | void TestJulia::testOneLine() | ||||
33 | { | ||||
34 | Cantor::Expression *e = evalExp(QLatin1String("2 + 3")); | ||||
35 | QVERIFY(e != nullptr); | ||||
36 | QVERIFY(e->result()->data().toString() == QLatin1String("5")); | ||||
37 | } | ||||
38 | | ||||
39 | void TestJulia::testOneLineWithPrint() | ||||
40 | { | ||||
41 | Cantor::Expression *e = evalExp(QLatin1String("print(2 + 3)")); | ||||
42 | QVERIFY(e != nullptr); | ||||
43 | QVERIFY(e->result()->data().toString() == QLatin1String("5")); | ||||
44 | } | ||||
45 | | ||||
46 | void TestJulia::testException() | ||||
47 | { | ||||
48 | Cantor::Expression *e = evalExp(QLatin1String("sqrt(-1)")); | ||||
49 | QVERIFY(e != nullptr); | ||||
50 | QVERIFY( | ||||
51 | not e->errorMessage().isEmpty() | ||||
52 | and e->errorMessage().contains(QLatin1String( | ||||
53 | "sqrt will only return a complex result if called with a " | ||||
54 | "complex argument. Try sqrt(complex(x))." | ||||
55 | )) | ||||
56 | ); | ||||
57 | } | ||||
58 | | ||||
59 | void TestJulia::testSyntaxError() | ||||
60 | { | ||||
61 | Cantor::Expression *e = evalExp(QLatin1String("for i = 1:10\nprint(i)")); | ||||
62 | QVERIFY(e != nullptr); | ||||
63 | QVERIFY( | ||||
64 | not e->errorMessage().isEmpty() | ||||
65 | and e->errorMessage().contains(QLatin1String( | ||||
66 | "syntax: incomplete: \"for\" at none:1 requires end" | ||||
67 | )) | ||||
68 | ); | ||||
69 | } | ||||
70 | | ||||
71 | void TestJulia::testMultilineCode() | ||||
72 | { | ||||
73 | Cantor::Expression *e = evalExp(QLatin1String( | ||||
74 | "q = 0; # comment\n" | ||||
75 | "# sdfsdf\n" | ||||
76 | "for i = 1:10\n" | ||||
77 | " q += i\n" | ||||
78 | "end\n" | ||||
79 | "print(q)" | ||||
80 | )); | ||||
81 | QVERIFY(e != nullptr); | ||||
82 | QVERIFY(e->result()->data().toString() == QLatin1String("55")); | ||||
83 | } | ||||
84 | | ||||
85 | QTEST_MAIN(TestJulia) | ||||
86 | | ||||
87 | #include "testjulia.moc" |