Bug 933269: tests for getElem on TypedObjects (r=nmatsakis).

This commit is contained in:
Felix S. Klock II 2013-11-05 09:53:00 +01:00
parent 36609298e4
commit 58fce5e255
10 changed files with 290 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.ArrayType(TypedObject.uint16, 3);
var VecPointType = new TypedObject.ArrayType(PointType, 3);
function foo() {
for (var i = 0; i < 10000; i += 9) {
var vec = new VecPointType([
[i, i+1, i+2],
[i+3, i+4, i+5],
[i+6, i+7, i+8]]);
var sum = vec[0][0] + vec[0][1] + vec[0][2];
assertEq(sum, 3*i + 3);
sum = vec[1][0] + vec[1][1] + vec[1][2];
assertEq(sum, 3*i + 12);
sum = vec[2][0] + vec[2][1] + vec[2][2];
assertEq(sum, 3*i + 21);
}
}
foo();

View File

@ -0,0 +1,45 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.StructType({x: TypedObject.uint16,
y: TypedObject.uint16,
z: TypedObject.uint16});
var VecPointType = new TypedObject.ArrayType(PointType, 3);
var PairVecType = new TypedObject.StructType({fst: VecPointType,
snd: VecPointType});
function foo() {
for (var i = 0; i < 5000; i += 9) {
var p = new PairVecType({fst: [{x: i, y: i+1, z:i+2},
{x: i+3, y: i+4, z:i+5},
{x: i+6, y: i+7, z:i+8}],
snd: [{x: i+9, y:i+10, z:i+11},
{x: i+12, y:i+13, z:i+14},
{x: i+15, y:i+16, z:i+17}]
});
var sum;
sum = p.fst[0].x + p.fst[0].y + p.fst[0].z;
assertEq(sum, 3*i + 3);
sum = p.fst[1].x + p.fst[1].y + p.fst[1].z;
assertEq(sum, 3*i + 12);
sum = p.fst[2].x + p.fst[2].y + p.fst[2].z;
assertEq(sum, 3*i + 21);
sum = p.snd[0].x + p.snd[0].y + p.snd[0].z;
assertEq(sum, 3*i + 30);
sum = p.snd[1].x + p.snd[1].y + p.snd[1].z;
assertEq(sum, 3*i + 39);
sum = p.snd[2].x + p.snd[2].y + p.snd[2].z;
assertEq(sum, 3*i + 48);
}
}
foo();

View File

@ -0,0 +1,30 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.StructType({x: TypedObject.uint16,
y: TypedObject.uint16,
z: TypedObject.uint16});
var VecPointType = new TypedObject.ArrayType(PointType, 3);
function foo() {
for (var i = 0; i < 10000; i += 9) {
var vec = new VecPointType([
{x: i, y:i+1, z:i+2},
{x: i+3, y:i+4, z:i+5},
{x: i+6, y:i+7, z:i+8}]);
var sum = vec[0].x + vec[0].y + vec[0].z;
assertEq(sum, 3*i + 3);
sum = vec[1].x + vec[1].y + vec[1].z;
assertEq(sum, 3*i + 12);
sum = vec[2].x + vec[2].y + vec[2].z;
assertEq(sum, 3*i + 21);
}
}
foo();

View File

@ -0,0 +1,24 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var Vec3u16Type = new TypedObject.ArrayType(TypedObject.uint16, 3);
var PairVec3u16Type = new TypedObject.StructType({fst: Vec3u16Type,
snd: Vec3u16Type});
function foo_u16() {
for (var i = 0; i < 15000; i += 6) {
var p = new PairVec3u16Type({fst: [i, i+1, i+2],
snd: [i+3,i+4,i+5]});
var sum = p.fst[0] + p.fst[1] + p.fst[2];
assertEq(sum, 3*i + 3);
sum = p.snd[0] + p.snd[1] + p.snd[2];
assertEq(sum, 3*i + 12);
}
}
foo_u16();

View File

@ -0,0 +1,19 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var Vec3u16Type = new TypedObject.ArrayType(TypedObject.uint16, 3);
function foo_u16() {
for (var i = 0; i < 30000; i += 3) {
var vec = new Vec3u16Type([i, i+1, i+2]);
var sum = vec[0] + vec[1] + vec[2];
assertEq(sum, 3*i + 3);
}
}
foo_u16();

View File

@ -0,0 +1,27 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.ArrayType(TypedObject.uint32, 3);
var VecPointType = new TypedObject.ArrayType(PointType, 3);
function foo() {
for (var i = 0; i < 10000; i += 9) {
var vec = new VecPointType([
[i, i+1, i+2],
[i+3, i+4, i+5],
[i+6, i+7, i+8]]);
var sum = vec[0][0] + vec[0][1] + vec[0][2];
assertEq(sum, 3*i + 3);
sum = vec[1][0] + vec[1][1] + vec[1][2];
assertEq(sum, 3*i + 12);
sum = vec[2][0] + vec[2][1] + vec[2][2];
assertEq(sum, 3*i + 21);
}
}
foo();

View File

@ -0,0 +1,45 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.StructType({x: TypedObject.uint32,
y: TypedObject.uint32,
z: TypedObject.uint32});
var VecPointType = new TypedObject.ArrayType(PointType, 3);
var PairVecType = new TypedObject.StructType({fst: VecPointType,
snd: VecPointType});
function foo() {
for (var i = 0; i < 5000; i += 9) {
var p = new PairVecType({fst: [{x: i, y: i+1, z:i+2},
{x: i+3, y: i+4, z:i+5},
{x: i+6, y: i+7, z:i+8}],
snd: [{x: i+9, y:i+10, z:i+11},
{x: i+12, y:i+13, z:i+14},
{x: i+15, y:i+16, z:i+17}]
});
var sum;
sum = p.fst[0].x + p.fst[0].y + p.fst[0].z;
assertEq(sum, 3*i + 3);
sum = p.fst[1].x + p.fst[1].y + p.fst[1].z;
assertEq(sum, 3*i + 12);
sum = p.fst[2].x + p.fst[2].y + p.fst[2].z;
assertEq(sum, 3*i + 21);
sum = p.snd[0].x + p.snd[0].y + p.snd[0].z;
assertEq(sum, 3*i + 30);
sum = p.snd[1].x + p.snd[1].y + p.snd[1].z;
assertEq(sum, 3*i + 39);
sum = p.snd[2].x + p.snd[2].y + p.snd[2].z;
assertEq(sum, 3*i + 48);
}
}
foo();

View File

@ -0,0 +1,30 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var PointType = new TypedObject.StructType({x: TypedObject.uint32,
y: TypedObject.uint32,
z: TypedObject.uint32});
var VecPointType = new TypedObject.ArrayType(PointType, 3);
function foo() {
for (var i = 0; i < 10000; i += 9) {
var vec = new VecPointType([
{x: i, y:i+1, z:i+2},
{x: i+3, y:i+4, z:i+5},
{x: i+6, y:i+7, z:i+8}]);
var sum = vec[0].x + vec[0].y + vec[0].z;
assertEq(sum, 3*i + 3);
sum = vec[1].x + vec[1].y + vec[1].z;
assertEq(sum, 3*i + 12);
sum = vec[2].x + vec[2].y + vec[2].z;
assertEq(sum, 3*i + 21);
}
}
foo();

View File

@ -0,0 +1,24 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var Vec3u32Type = new TypedObject.ArrayType(TypedObject.uint32, 3);
var PairVec3u32Type = new TypedObject.StructType({fst: Vec3u32Type,
snd: Vec3u32Type});
function foo_u32() {
for (var i = 0; i < 15000; i += 6) {
var p = new PairVec3u32Type({fst: [i, i+1, i+2],
snd: [i+3,i+4,i+5]});
var sum = p.fst[0] + p.fst[1] + p.fst[2];
assertEq(sum, 3*i + 3);
sum = p.snd[0] + p.snd[1] + p.snd[2];
assertEq(sum, 3*i + 12);
}
}
foo_u32();

View File

@ -0,0 +1,19 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
if (!this.hasOwnProperty("TypedObject"))
quit();
var Vec3u32Type = new TypedObject.ArrayType(TypedObject.uint32, 3);
function foo_u32() {
for (var i = 0; i < 30000; i += 3) {
var vec = new Vec3u32Type([i, i+1, i+2]);
var sum = vec[0] + vec[1] + vec[2];
assertEq(sum, 3*i + 3);
}
}
foo_u32();