Beispiel #1
0
def test_init():
    """
    Check if it raises an error if not proper figure is chosen
    """

    temp = ChaosGame(2)
    temp = ChaosGame(1)
Beispiel #2
0
def test_ChaosGame_starting_point():
    """Test if starting points are within radius 1 from origin (unit circle)"""

    for i in range(3, 10):
        testgon = ChaosGame(i, 1 / 2)
        testgon._starting_point()
        nt.assert_less_equal(
            np.sqrt(testgon.start[0]**2 + testgon.start[1]**2), 1)
Beispiel #3
0
def test_generate_ngon():
    """
    Checks if value that is passed to cos is in radians, i.e. cos(0) = 1
    """

    temp = ChaosGame(4)
    temp._generate_ngon()
    nt.assert_equal(np.cos(temp.theta[0]), 1)
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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)
Beispiel #7
0
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')
Beispiel #8
0
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_equilateral_triangle():
    a = ChaosGame(3)
    edge1 = np.linalg.norm(a.corners[0] - a.corners[1])
    edge2 = np.linalg.norm(a.corners[0] - a.corners[2])
    edge3 = np.linalg.norm(a.corners[1] - a.corners[2])
    nt.assert_almost_equal(edge1, edge2)
    nt.assert_almost_equal(edge1, edge3)
def test_equilateral_square():
    b = ChaosGame(4)
    edge1 = np.linalg.norm(b.corners[0] - b.corners[1])
    edge2 = np.linalg.norm(b.corners[1] - b.corners[2])
    edge3 = np.linalg.norm(b.corners[2] - b.corners[3])
    edge4 = np.linalg.norm(b.corners[3] - b.corners[0])
    nt.assert_almost_equal(edge1, edge2)
    nt.assert_almost_equal(edge1, edge3)
    nt.assert_almost_equal(edge1, edge4)
Beispiel #11
0
def test_number_of_vertices():
    """
    Test to verify that the class produces the right number of vertices
    """
    polygon = ChaosGame(4, 0.5)
    number_of_corners = len(polygon.corner)
    bool = number_of_corners == 4
    msg = "The polygon does not have 3 vertices it has : {}".format(
        number_of_corners)
    assert bool, msg
Beispiel #12
0
def test_ChaosGame_init_errors2():
    """Test if ValueErrors are raised in initialization"""

    testgon = ChaosGame(0, 1 / 2)
    testgon = ChaosGame(1, 1 / 2)
    testgon = ChaosGame(2, 1 / 2)
    testgon = ChaosGame(-5, 1 / 2)

    testgon = ChaosGame(3, float(1))
    testgon = ChaosGame(3, float(2))
    testgon = ChaosGame(3, float(3.5))
    testgon = ChaosGame(3, float(-0.1))
Beispiel #13
0
def test_ChaosGame_initialization():
    """Test different initialization attributes"""

    testtri = ChaosGame(3, 1 / 2)
    testquad = ChaosGame(4, 1 / 3)
    testpent = ChaosGame(5, 1 / 4)

    nt.assert_almost_equal(testtri.r, 1 / 2)
    nt.assert_almost_equal(testtri.n, 3)
    nt.assert_almost_equal(testquad.r, 1 / 3)
    nt.assert_almost_equal(testquad.n, 4)
    nt.assert_almost_equal(testpent.r, 1 / 4)
    nt.assert_almost_equal(testpent.n, 5)

    nt.assert_almost_equal(testtri.corners[0][0], np.sin(0))
    nt.assert_almost_equal(testtri.corners[0][1], np.cos(0))
    nt.assert_almost_equal(testtri.corners[1][0], np.sin((1 / 3) * 2 * np.pi))
    nt.assert_almost_equal(testtri.corners[1][1], np.cos((1 / 3) * 2 * np.pi))
    nt.assert_almost_equal(testtri.corners[2][0], np.sin((2 / 3) * 2 * np.pi))
    nt.assert_almost_equal(testtri.corners[2][1], np.cos((2 / 3) * 2 * np.pi))
Beispiel #14
0
def test_generate_ngon():
    """
    Test to verify that each side of the polygon has the same length
    """
    polygon = ChaosGame(3, 0.5)
    vec1 = polygon.corner[0] - polygon.corner[1]
    vec2 = polygon.corner[1] - polygon.corner[2]
    sidelength1 = np.sqrt(vec1[0]**2 + vec1[1]**2)
    sidelength2 = np.sqrt(vec2[0]**2 + vec2[1]**2)
    diff = abs(sidelength1 - sidelength2)
    bool = diff < 1e-4
    msg = "The generated polygon does not have equal length sides. " \
          "The sides differ by : {}".format(diff)
    assert bool, msg
Beispiel #15
0
def test_ChaosGame_init_errors1():
    """Test if TypeErrors are raised in initialization"""

    testgon = ChaosGame(0.1, 1 / 2)
    testgon = ChaosGame("nose", 1 / 2)
    testgon = ChaosGame([1, 2, 3], 1 / 2)

    testgon = ChaosGame(3, "nose")
    testgon = ChaosGame(3, [1, 2, 3])
    testgon = ChaosGame(3, int(1))
def test__init__n():
    ChaosGame(2, 0.5)
    ChaosGame(3.5, 0.5)
def test_generate_ngon():
    """ Test that _generate_ngon returns list. """
    T = ChaosGame(5, 0.5)
    s = T._generate_ngon(5)
    nt.assert_equal(type(s), list)
def test_starting_point():
    """ Test that _starting_point returns array. """
    T = ChaosGame(5, 0.5)
    s = T._starting_point()
    nt.assert_equal(type(s), np.ndarray)
def test_savepng():
    T = ChaosGame(5, 0.5)
    T.iterate(50)
    T.savepng("outfile.pic")
def test__init__():
    ChaosGame(5, 1.1)
    ChaosGame(4, 1)
Beispiel #21
0
    @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_error_n():
    a = ChaosGame(0.1)
    b = ChaosGame(2)
def test_error_r():
    a = ChaosGame(3, 1)
    b = ChaosGame(3, 1.1)
def test_savepng():
    a = ChaosGame(3)
    a.iterate(30000)
    a.savepng('sierpinski.pdf')