-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple_field_assign.cpp
More file actions
55 lines (45 loc) · 1.64 KB
/
test_simple_field_assign.cpp
File metadata and controls
55 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <jaiscript/core/engine.hpp>
#include <jaiscript/stdlib/stdlib.hpp>
#include <iostream>
int main() {
auto engine = jai::engine::make();
jai::stdlib::register_all(*engine);
try {
auto result = engine->execute(R"(
class Calculator {
auto result = 0.0;
auto memory = 0.0;
void add(x) {
result = result + x;
print("After add, result = " + to_string(result));
}
void multiply(x) {
result = result * x;
print("After multiply, result = " + to_string(result));
}
void store() {
print("Before store: result = " + to_string(result) + ", memory = " + to_string(memory));
memory = result;
print("After store: memory = " + to_string(memory));
}
}
auto calc = Calculator();
calc.add(5.0);
calc.multiply(3.0);
calc.store();
print("Final: result = " + to_string(calc.result) + ", memory = " + to_string(calc.memory));
calc.result == 15.0 && calc.memory == 15.0
)");
std::cout << "Result: " << result.to_string() << std::endl;
if (result.is_bool() && result.as_bool()) {
std::cout << "TEST PASSED" << std::endl;
return 0;
} else {
std::cout << "TEST FAILED" << std::endl;
return 1;
}
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
return 1;
}
}