testfunc/test/jstests/utils.js
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Sat, 18 Jun 2011 23:27:23 +0200
branchstable
changeset 7537 1af162bd78b8
parent 7363 2293c49b290a
permissions -rw-r--r--
[migration] bugfix: c-c list was not displaying the name of a cube requiring another cube without constraining the version.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5738
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
function datetuple(d) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
    return [d.getFullYear(), d.getMonth()+1, d.getDate(),
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
	    d.getHours(), d.getMinutes()];
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
function pprint(obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
    print('{');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
    for(k in obj) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
	print('  ' + k + ' = ' + obj[k]);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    print('}');
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
function arrayrepr(array) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    return '[' + array.join(', ') + ']';
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
function assertArrayEquals(array1, array2) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
    if (array1.length != array2.length) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
	throw new crosscheck.AssertionFailure(array1.join(', ') + ' != ' + array2.join(', '));
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
    for (var i=0; i<array1.length; i++) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
	if (array1[i] != array2[i]) {
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
	    throw new crosscheck.AssertionFailure(arrayrepr(array1) + ' and ' + arrayrepr(array2)
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
						 + ' differs at index ' + i);
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
	}
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    }
74bd8123fb07 [jstest] get back more tests writen during the sprint by vgodard
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
}