#!/usr/bin/ruby

# Test the zip (~Z) and cross (~X) meta-operators

var a = [1, 2];
var b = [3, 4];
var c = [1, 1];
var d = [42];

assert_eq(a ~X+ b, [4, 5, 5, 6]);
assert_eq(a ~X== c, [true, true, false, false]);
assert_eq(a ~Z b, [[1,3], [2,4]]);
assert_eq(a ~Z+ b, [4,6]);

var X = 21;       # there should be no conflict
var Z = 22;       # between operators and variables

assert_eq(a ~X d, [[1, 42], [2, 42]]);
assert_eq(a ~X+ d, [43, 44]);
assert_eq(d ~X+ a, [43, 44]);
assert_eq(d ~X a, [[42, 1], [42, 2]]);

assert_eq(d ~Z a, [[42, 1]]);
assert_eq(d ~Z+ a, [43]);
assert_eq(d ~Z/ c, [42]);
assert_eq(b ~Z/ a, [3, 2]);

assert_eq(~X, -22);
assert_eq(~Z, -23)

say "** Test passed!";
