def test_indices(): """ Test to verify that the class produces the right amount of indices """ polygon = ChaosGame(5, 0.5) polygon.iterate(500) check = any(polygon._indices >= 5) msg = "1 or more polygon indices was larger than 5-1" assert not check, msg
def test_savepng(): """ Tests if a wrong format of the picture gives error """ temp = ChaosGame(2) temp._generate_ngon() temp._generate_points(20) temp._starting_point() temp.iterate(10) a.savepng('filename.jpg')
def test_ChaosGame_iterate(): """Test if iterated points are within radius 1 from origin (unit circle)""" testgon = ChaosGame(3, 1 / 2) for i in [1000, 3000, 101, 5000]: testgon.iterate(i) nt.assert_almost_equal(len(testgon.points), i) np.testing.assert_array_less( np.sqrt(testgon.points[:, 0]**2 + testgon.points[:, 1]**2), 1)
def test_iterate(): """ Test to verify that the class iterates the right number of time """ polygon = ChaosGame() polygon.iterate(300) length = len(polygon._x) bool = length == 300 msg = "The number of points generated was not 3000, it was : {}".format( length) assert bool, msg
def test_scaled(): """ Test scaling vector - sum of the elements should be equal to 0 """ temp = ChaosGame(4) temp._generate_ngon() temp._generate_points(20) temp._starting_point() temp.iterate(10) computed = np.sum(temp.new_r[0]) assert (1 - computed) == 0
def test_savepng(): T = ChaosGame(5, 0.5) T.iterate(50) T.savepng("outfile.pic")
@classmethod def list_of_variations(cls): dict = { 'Linear': Variations.linear, 'Handkercheif': Variations.handkerchief, 'Swirl': Variations.swirl, 'Disc': Variations.disc, 'Diamond': Variations.diamond, 'Heart': Variations.heart } return dict if __name__ == '__main__': a = ChaosGame(4, 1 / 3) a.iterate(10000) x = a.x[:, 0] y = -a.x[:, 1] x /= np.max(np.abs(x), axis=0) y /= np.max(np.abs(y), axis=0) var = Variations(x, y, a.c) weights = np.linspace(0, 1, 4) for i in range(len(weights)): dic = {var.swirl: weights[i], var.linear: 1 - weights[i]} var(dic) var.plot(2, 2) plt.title("linear coef :{:.2} Swirl coef : {:.2}".format( 1 - weights[i], weights[i])) print(var.plotnumber) plt.show(dpi=500)
def test_savepng(): a = ChaosGame(3) a.iterate(30000) a.savepng('sierpinski.pdf')