#!/usr/bin/ruby

var arr_test = [["x", "y", "z"]];

arr_test[0][1]->say;
arr_test[0][-1]->say;

arr_test[1] = "x";
arr_test->to_s->say;

arr_test[0][0,2]->to_s->say;

var ref_slice = [arr_test[0,1,2]];
ref_slice[0,1,2,3] = ("hu","hi","hei","no");

ref_slice.to_s.say;
arr_test->to_s.say;

arr_test->len->to_s->say;

["zzzz","ioana"][1]->say;
[[["zzz","trizen","zzz"]]][0][0][1]->say;

#
## Test `nil` return-values
#

var a = [4, 8, 10, 12]
var r = [a.first_by { .is_odd }, a.last_by { .is_odd }]

assert_eq(r.len, 2)
assert_eq(r, [nil, nil])

#
## Test `map_2d` and `grep_2d`
#

assert_eq(
    Matrix([1,2,3],[4,5,6]).map_2d{ |*a| a.map { _**2 } },
    Matrix([1, 4, 9], [16, 25, 36])
)

assert_eq([[1,2], [3,4], [5,6]].map_2d {|a,b| a+b }, [3, 7, 11])
assert_eq([[1,2], [3,4], [5,6]].map_2d {|a,b| [a**2, b**2] }, [[1,4], [9,16], [25, 36]])

assert_eq([[1,2], [3,4], [5,6]].grep_2d{|a,b| a+b == 7 }, [[3,4]])
assert_eq([[1,2], [3,4], [5,6]].grep_2d{|a,b| a+b <= 7 }, [[1,2], [3,4]])

do {
    var a = %w(a b c d e f)

    assert(a.contains('a'))
    assert(a.contains('a', 'b'))
    assert(a.contains('b'))
    assert(a.contains('b', 'c'))
    assert(a.contains('c'))
    assert(a.contains('b', 'c', 'd'))
    assert(a.contains('b', 'c', 'd', 'e'))
    assert(a.contains('b', 'c', 'd', 'e', 'f'))
    assert(a.contains('e', 'f'))
    assert(a.contains('f'))

    assert(!a.contains('b', 'd'))
    assert(!a.contains('b', 'd', 'e', 'f'))
    assert(!a.contains('a', 'c'))
    assert(!a.contains('d', 'f'))

    assert(['a',nil,'c'].contains(nil, 'c'))
    assert(['a','b',nil].contains('a','b', nil))
    assert(['a','b',nil].contains('b', nil))
    assert(['a','b',nil].contains(nil))

    assert(!['a',nil,'c'].contains(nil, 'd'))
    assert(!['a','b',nil].contains('a', 'b', nil, 'c'))
    assert(!['a','b',nil].contains('b', nil, 'c'))
    assert(!['a','b',nil].contains(nil, 'c'))
    assert(!['a','b',nil].contains('b', nil, nil, nil))

    assert(!a.contains('e', 'f', 'g'))
    assert(!a.contains('e', 'f', nil))
}

say "** Test passed!"
