2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
import mathx.MatrixUtil;
10
import mathx.MatPoint;
12
typedef IntTestMatrix = Matrix<Int>;
14
class TestMatrix extends haxe.unit.TestCase
16
public function testBasic()
18
var q = { x : 1, y : 1 };
22
var origA : Array<Array<Int>> = [ [ 1, 2, 3], [4,5,6] ];
23
var orig = IntTestMatrix.fromArrayMat( origA );
25
assertEquals( orig.get( 1, 1 ), 5 ); //checking very basics
26
assertTrue( MatrixUtil.equals( orig, n ) );
28
assertEquals( orig.get(1,1), 5 ); //should not have been modified
29
assertFalse( MatrixUtil.equals( orig, n ) );
31
var q = orig.createFlip( );
32
assertTrue( ArrayUtil.equals( q.extractRow(1), orig.extractRow(0) ) );
33
assertTrue( ArrayUtil.equals( q.extractRow(0), orig.extractRow(1) ) );
35
var rotA : Array<Array<Int>> = [ [ 4, 1 ], [ 5, 2], [6, 3 ] ];
36
var rot = IntTestMatrix.fromArrayMat( rotA );
37
var oRot = orig.clone();
39
assertTrue( MatrixUtil.equals( rot, oRot ) );
42
//testing iterators (the first one doesn't actually assume an order, any order would work)
43
var count = IntTestMatrix.create( 10, 5, 0 );
44
for( mp in count.boxOrderIter( MatPoint.at( 2, 3 ) ) )
46
assertTrue( count.validIndex( mp.x, mp.y ) );
47
count.set( mp.x, mp.y, count.get( mp.x, mp.y ) + 1 );
51
for( mp in count.xOrderIter() )
53
assertEquals( 1, count.get(mp.x,mp.y) );
57
assertEquals( total, 10 * 5 );
60
var mp = count.subIter( MatPoint.at( 2, 3 ), MatPoint.at( 3, 2 ) );
61
assertEquals( 2, mp.next().x ); //2,3
62
assertEquals( 3, mp.next().y ); //3,3
63
assertEquals( 4, mp.next().x ); //4,3
64
assertEquals( 4, mp.next().y ); //2,4
65
assertEquals( 3, mp.next().x ); //3,4
66
assertEquals( 4, mp.next().y ); //4,4
68
assertTrue( !mp.hasNext() );