def test_nunit_no_duplicates(): c = fabric_7t.Canvas() for (x,y) in ( (x,y) for x in range(4) for y in range(2)): c.pushTr( Transformation(x*c.unitCellWidth, y*c.unitCellHeight)) if x % 2 != 0: c.hitTopTr( Transformation(1*c.unitCellWidth, 0*c.unitCellHeight, -1, 1)) if y % 2 != 0: c.hitTopTr( Transformation(0*c.unitCellWidth, 1*c.unitCellHeight, 1, -1)) c.nunit() c.popTr() fn = "__json_7t_nunit" with open( mydir / (fn + "_cand"), "wt") as fp: data = c.writeJSON( fp) # assert len(c.rd.opens) == 0 assert len(c.rd.shorts) == 0 with open( mydir / (fn + "_gold"), "rt") as fp: data2 = json.load( fp) assert data == data2
def test_transformation_hit1(): t = Transformation( 0, 10, 1, -1) assert (0,0) == t.hit( (0,10))
def test_genTr(): oX, oY = 23, 47 w,h = 100,200 for orient in [ 'N', 'S', 'FN', 'FS']: tr = Transformation.genTr( orient, w=w, h=h) tr.oX, tr.oY = 0, 0 # tr is now just the flipping matrix, no translation tr_offset = Transformation( oX=oX, oY=oY) tr_center = Transformation( oX=-w//2, oY=-h//2) tr_uncenter = Transformation( oX=w//2, oY=h//2) tr_first = tr_uncenter.postMult( tr).postMult( tr_center) tr_whole = tr_offset.postMult( tr_first) tr_first2 = Transformation.genTr( orient, w=w, h=h) tr_whole2 = tr_offset.postMult( tr_first2) assert Transformation() == tr_first2.postMult( tr_first2.inv()) assert Transformation() == tr_first2.inv().postMult( tr_first2) assert tr_first == tr_first2 assert tr_whole == tr_whole2 assert tr_first.inv() == tr_center.inv().postMult( tr.inv()).postMult( tr_uncenter.inv()) assert tr_first.inv() == tr_uncenter.postMult( tr).postMult( tr_center) assert tr_first.inv() == tr_first assert tr_whole.inv() == tr_first.inv().postMult( tr_offset.inv())
def test_hitRect(): a = Transformation( 0, 10, -1, 1) r = Rect( 0, 0, 1, 1) assert a.hitRect(r).canonical().toList() == [-1, 10, 0, 11]
def test_repr(): a = Transformation( 0, 0, 1, 1) assert repr(a) == "Transformation(oX=%d, oY=%d, sX=%d, sY=%d)" % (a.oX, a.oY, a.sX, a.sY)
def test_transformation_postMult0(): a = Transformation( 0, 10, 0, 0) b = Transformation( 0, 0, 1,-1) assert (0,-10) == (b.postMult(a)).hit( (0,0))
def test_transformation_preMult0(): a = Transformation( 0, 10, 0, 0) b = Transformation( 0, 0, 1,-1) assert (0,-10) == (a.preMult(b)).hit( (0,0))
def test_transformation_Mult0(): a = Transformation( 0, 10, 0, 0) b = Transformation( 0, 0, 1,-1) assert (0,-10) == (Transformation.mult( b, a)).hit( (0,0))