summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core/tests/unit_tests/oldEmptyBehaviour.tst
blob: 56ac154240ba2b627df500dc94d55eb256345373 (plain)
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
56
57
58
59
60
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2016 - Scilab Enterprises - Pierre-Aime Agnel
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================

// <-- CLI SHELL MODE -->
//
// <-- ENGLISH ONLY -->

// Testing oldEmptyBehaviour default mode
behaviour = oldEmptyBehaviour("query");
assert_checkequal(behaviour, "off");

// Changing the behaviour
oldEmptyBehaviour("on");
behaviour = oldEmptyBehaviour("query");
assert_checkequal(behaviour, "on");
E = [];
s = 1;
sc = 1 + %i;
M = [1 2; 3 4];
MC = M + M.*%i;
I = int8(M);
P = [3*%s^2 + %s + 1; %s^2];
PC = P + %i*%s;
st = ["this is a test"; "with a string"];

num = {s, sc, M, MC, I, P, PC};

// Test all numeric
for i = 1:size(num, "*")
    assert_checkequal(E + num{i}, num{i});
    assert_checkequal(E - num{i}, -num{i});
    assert_checkequal(num{i} + E, num{i});
    assert_checkequal(num{i} - E, num{i});
end

// test strings
assert_checkequal(E + st, st);
assert_checkequal(st + E, st);

// New behaviour
oldEmptyBehaviour("off");
behaviour = oldEmptyBehaviour("query");
assert_checkequal(behaviour, "off");

// Test all numeric
for i = 1:size(num, "*")
    assert_checkequal(E + num{i}, E);
    assert_checkequal(E - num{i}, E);
    assert_checkequal(num{i} + E, E);
    assert_checkequal(num{i} - E, E);
end

// test strings
assert_checkequal(E + st, E);
assert_checkequal(st + E, E);