|
<!DOCTYPE html> |
|
<head> |
|
<meta charset="UTF-8" /> |
|
<title>test</title> |
|
<style> |
|
|
|
</style> |
|
</head> |
|
<body> |
|
|
|
<script src="coordinate-list-0.1.0.js"></script> |
|
<script> |
|
'use strict'; |
|
{ |
|
const c1 = new Coordinate([['x', 1], ['y', 2]]); |
|
|
|
console.assert(c1.dimensionName === 'x y'); |
|
console.assert(JSON.stringify(c1.keys()) === '["x","y"]'); |
|
console.assert(JSON.stringify(c1.values()) === '[1,2]'); |
|
console.assert(JSON.stringify(c1.entries()) === '[["x",1],["y",2]]'); |
|
console.assert(c1.size === 2); |
|
console.assert(c1.x === 1); |
|
console.assert(c1.y === 2); |
|
|
|
const c2 = new Coordinate; |
|
|
|
c2.set([' x ', 1], [' y ', 2]); |
|
console.assert(c2.dimensionName === 'x y'); |
|
console.assert(JSON.stringify(c2.keys()) === '["x","y"]'); |
|
console.assert(JSON.stringify(c2.values()) === '[1,2]'); |
|
console.assert(JSON.stringify(c2.entries()) === '[["x",1],["y",2]]'); |
|
console.assert(c2.size === 2); |
|
console.assert(c2.x === 1); |
|
console.assert(c2.y === 2); |
|
console.assert(JSON.stringify(c1) === JSON.stringify(c2)); |
|
|
|
c2.set(['z', 'foo']); // TypeError: foo is not a number |
|
} |
|
</script> |
|
<script> |
|
'use strict'; |
|
new Coordinate([['x y', 1]]); // Error: Do not include white-spaces in the "key": x y |
|
</script> |
|
<script> |
|
'use strict'; |
|
{ |
|
const c1 = new CoordinateList([[['x', 1], ['y', 2]], [['x', 2], ['y', 3]], [['x', 3], ['y', 4]]]); |
|
|
|
console.assert(c1.dimensionName === 'x y'); |
|
console.assert(JSON.stringify(c1.getCenter().entries()) === '[["x",2],["y",3]]'); |
|
console.assert(JSON.stringify(c1.entries()) === '[[["x",1],["y",2]],[["x",2],["y",3]],[["x",3],["y",4]]]'); |
|
|
|
const c2 = new CoordinateList; |
|
|
|
c2.push([['x', 1], ['y', 2]], [['x', 2], ['y', 3]], [['x', 3], ['y', 4]]); |
|
console.assert(JSON.stringify(c2.getCenter().entries()) === '[["x",2],["y",3]]'); |
|
console.assert(JSON.stringify(c1.entries()) === JSON.stringify(c2.entries())); |
|
|
|
new CoordinateList([[['x', 1], ['y', 2]], [['z', 1], ['t', 2]]]); // Error: All coordinate.dimensionName must be identical |
|
} |
|
</script> |
|
<script> |
|
'use strict'; |
|
</script> |
|
<script> |
|
'use strict'; |
|
</script> |
|
<script> |
|
'use strict'; |
|
</script> |
|
<script> |
|
'use strict'; |
|
</script> |
|
</body> |
|
</html> |