|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Matrix = require('../..'); |
| 4 | + |
| 5 | +describe('Sub view', function () { |
| 6 | + it('should correctly remap coordinates', function () { |
| 7 | + var m = Matrix.ones(5, 8); |
| 8 | + var msv = m.subMatrixView([1,2], [2,1]); |
| 9 | + |
| 10 | + m.get(1, 2).should.equal(1); |
| 11 | + msv.set(0, 0, 5); |
| 12 | + m.get(1, 2).should.equal(5); |
| 13 | + |
| 14 | + m.get(2,1).should.equal(1); |
| 15 | + m.set(2,1, 10); |
| 16 | + msv.get(1,1).should.equal(10); |
| 17 | + |
| 18 | + msv = m.subMatrixView(3,4,6,7); |
| 19 | + m.get(4,7).should.equal(1); |
| 20 | + msv.set(1, 1, 20); |
| 21 | + m.get(4,7).should.equal(20); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should throw when wrong arguments or range', function () { |
| 25 | + var m = Matrix.ones(2,2); |
| 26 | + (function () { |
| 27 | + m.subMatrixView(0,1); |
| 28 | + }).should.throw(TypeError); |
| 29 | + |
| 30 | + (function () { |
| 31 | + m.subMatrixView(0,1,0,2); |
| 32 | + }).should.throw(RangeError); |
| 33 | + |
| 34 | + (function () { |
| 35 | + m.subMatrixView([1,1,2], [0,2]); |
| 36 | + }).should.throw(RangeError); |
| 37 | + |
| 38 | + (function () { |
| 39 | + m.subMatrixView([1,1,2]) |
| 40 | + }).should.throw(TypeError); |
| 41 | + }); |
| 42 | +}); |
0 commit comments