Exemple #1
0
def test_evolve_shape():
    ''' Validate that the shape of evolve method return value
    '''
    a = Attractor()
    assert a.evolve().shape == (
        a.points,
        4), "\n the array that was obtained does not have a proper shape \n"
class Runga_Kutta(unittest.TestCase):
    """This is set of basic test for Euler method"""

    def setUp(self):
        self.a = Attractor()
        self.a.points = 10000
        self.a.start = 0
        self.a.end = 100

    def test_dataframe(self):
        """Make sure the data frame is created with right number of rows"""
        df = self.a.evolve(order=4)
        print "This is length of dataframe", len(df)
        assert len(df) - 1 == 10000  # subrtact 1 for the title row

    def test_filesave(self):
        """Test ot make sure we are able to save the file"""
        file_save_status = self.a.save()
        print "The status of file save is ", file_save_status
        assert file_save_status == True

    def test_diff_start_points(self):
        """Make sure the data frame is created when using non default values"""
        df = self.a.evolve(r0=[1.0, 1.5, 2.0], order=4)
        print " The first row of dataframe is ", df.iloc[2,]
        print "This starting values of X variable is ", df.iloc[0, 1]
Exemple #3
0
def test_rhs_shape():
    ''' Validate that the shape of the rhs method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.rhs(xyz).shape == (
        3, ), "\n the shape of the array that was returned is not 3 \n"
def test_euler():
    """ This test case is to ensure proper size of the value returned by our euler method.
    If this test fails it will indicate that there aren't the correct number of items being passed
    to the method."""
    a = Attractor()
    xyz = np.array([0.0,0.0,0.0])
    assert a.euler(xyz).shape == (3, ), "\n The array given to the euler method did not contain 3 items!\n"
class TestCases:
    
    def setup(self):
        self.s=s
        self.p=p
        self.b=b
        start=0
        self.start=start
        self.end=end
        self.points=points
        self.a=Attractor(s,p,b,start,end,points)


    def test_euler(self):
        "To Test Euler Method"
        assert self.myObj.euler(np.array([0.1,0.,0.]))[0]==-1.
        assert int(self.myObj.euler(np.array([0.1,0.,0.]))[1])==int(2.8)
        assert self.myObj.euler(np.array([0.1,0.,0.]))[2]==0.


    def test_rk2(self):
        "To Order 2nd Order Runga-Kutta"
        obj = Attractor()
        obj.evolve([10,10,10],2)
        assert attr.solution['x'].count() > 0
        assert attr.solution['y'].count() > 0
        assert attr.solution['z'].count() > 0

    def test_solve(self):
        "To Test saving to .csv function"
            self.a.save()
            data=open('save_solution.csv','r')
            d=data.read()
 def test(self):
     "To test attractor result"
         obj = Attractor()
         expected_result =  [9.6 , 5.6 , 19.97333333]
         res = obj.euler([10,5,20])
         assert (expected_result == res).all
         print "Passed"
Exemple #7
0
class Gravity(Sketchy):
    def setup(self):
        width, height = [600, 400]

        self.a = Attractor(width, height)

        self.balls = []
        for i in range(0, 10):
            self.balls.append(Ball(width,height))

        self.size(width, height)

    def update(self):
        for i in range(len(self.balls)):
            for j in range(len(self.balls)):
                if i != j:
                    self.force = self.balls[j].attract(self.balls[i])
                    applyForce(self.balls[i], self.force)
            self.force = self.a.attract(self.balls[i])
            applyForce(self.balls[i], self.force)
            self.balls[i].update(600, 400)

    def draw(self, g):
        g.background(1, 1, 1)
        for i in range(len(self.balls)):
            self.balls[i].draw(g)
        self.a.draw(g)
 def test_rk2(self):
     "To Order 2nd Order Runga-Kutta"
     obj = Attractor()
     obj.evolve([10,10,10],2)
     assert attr.solution['x'].count() > 0
     assert attr.solution['y'].count() > 0
     assert attr.solution['z'].count() > 0
Exemple #9
0
def test_rk4_shape():
    ''' Validate that the shape of rk4 method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.rk4(xyz).shape == (
        3,
    ), "\n the shape of the array that was obtained from rk4 is not 3 \n"
Exemple #10
0
def test_euler_shape():
    ''' Validate that the shape of the euler method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.euler(xyz).shape == (
        3,
    ), "\n the shape of the array that was obtained from euler is not 3 \n"
 def euler_test(self):
     """Tests Euler's method in Attractor and ensures the arrays are being filled to the correct and same sizes"""
     a = Attractor()
     a.evolve([1, 2, 3], 1)
     assert len(a.solution['x']) > 0, "\nError in Euler's solution for x"
     assert len(a.solution['y']) > 0, "\nError in Euler's solution for y"
     assert len(a.solution['z']) > 0, "\nError in Euler's solution for z"
     assert len(a.solution['x']) == len(a.solution['y']), "\nError in assigning values to arrays for solution x and/or y"
     assert len(a.solution['y']) == len(a.solution['z']), "\nError in assigning values to arrays for solution y and/or z"
 def rk4_test(self):
     """Tests the fourth order Runge Kutta method and ensures the arrays are being filled correctly and similarily"""
     a = Attractor()
     a.evolve([1, 2, 3], 4)
     assert len(a.solution['x']) > 0, "\nError in RK4 solution for x"
     assert len(a.solution['y']) > 0, "\nError in RK4 solution for y"
     assert len(a.solution['z']) > 0, "\nError in RK4 solution for z"
     assert len(a.solution['x']) == len(a.solution['y']), "\nError in assigning values to arrays for solution x and/or y"
     assert len(a.solution['y']) == len(a.solution['z']), "\nError in assigning values to arrays for solution y and/or z"
 def setup(self):
     self.s=s
     self.p=p
     self.b=b
     start=0
     self.start=start
     self.end=end
     self.points=points
     self.a=Attractor(s,p,b,start,end,points)
def test_save_csv():
    ''' Ensure that the csv file is created
    '''
    filename = 'filename.csv'
    a = Attractor()
    os.remove(filename)
    a.evolve()
    a.save(filename)
    assert os.path.exists(filename), "\n no output file found \n"
    print(" test_save_csv method is working as expected ")
def test_rk4():
    """Testing the Runge-Kutta method of order 4.

    This is being tested because it has the most amount steps to calculate the result.  This is the most likely place for errors.
    """
    rk4_true = [0.08425138,  0.19172248, -0.04604073]
    print("Expected rk4:", r4_true)
    a = Attractor()
    print("Actual rk4:", a.rk4([1,2,3]))
    assert a.rk4([1,2,3]) == rk4_true
def test_rk2():
    """Testing the Runge-Kutta method of order 2.

    This is being tested because it uses a new increment which increases the chance of error.
    """
    rk2_true = [0.08416, 0.19146368, -0.04608256]
    print("Expected rk2:", rk2_true)
    a = Attractor()
    print("Actual rk2:", a.rk2([1,2,3]))
    assert a.rk2([1,2,3]) == rk2_true
def test_euler():
    """Testing the euler method.

    This is being tested because this is a main method in this class.
    """
    euler_true = [0.08, 0.184, -0.048]
    print("Expected euler:", euler_true)
    a = Attractor()
    print("Actual euler:", a.euler([1,2,3]))
    assert a.euler([1,2,3]) == euler_true
def test_deriv():
    """Testing the derivative calculated.

    This is an important test because the euler, rk2, and rk4 estimates use this method.  If this method does not calculate the correct values, then             everything else will be incorrect.
    """
    deriv_true = [10.0,  23.0,  -6.0]
    print("Expected deriv:", deriv_true)
    a = Attractor()
    print("Actual deriv:", a.deriv([1,2,3]))
    assert a.deriv([1,2,3]) == deriv_true
class TestRandomValues:
    """Define an Attractor with random values for s, p and b, test interface"""

    def setup(self):
        """Setup fixture is run before every test method separately"""
        s = random.uniform(1, 20)
        p = random.uniform(1, 10)
        b = random.uniform(1, 15)
        self.s = s
        self.p = p
        self.b = b
        start = 0
        end = random.uniform(10, 50)
        points = random.randint(50, 200)
        self.start = start
        self.end = end
        self.points = points
        self.a = Attractor(s, p, b, start, end, points)

    def test_defintions(self):
        """Test the first definitions of the class"""
        assert (
            self.a.params[0] == self.s
        ), "\n we want to test that value of s save correctly,it gives us error if s!=params[0] \n"
        assert (
            self.a.params[1] == self.p
        ), "\n we want to test that value of p save correctly,it gives us error if p!=params[1] \n"
        assert (
            self.a.params[2] == self.b
        ), "\n we want to test that value of b save correctly,it gives us error if b!=params[2] \n"
        assert (
            self.a.dt == (self.end - self.start) / self.points
        ), "\n we want to test the value of s save correctly,it gives us error if dt!=(end-start)/points \n"

    def test_solve(self):
        """Test if solve is printing in the CSV file"""
        os.remove("save_solution.csv")
        self.a.save()
        data = open("save_solution.csv", "r")
        d = data.read()
        assert len(d) > 0

    def test_euler(self):
        """Test if the methods euler is generating the correct answer and we can do this for rk2 and rk4"""
        self.a = Attractor(5, 1, 3, 0, 80, 100)
        assert (
            self.a.euler(0, 1, 0)[0] == 5
        ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[0]!=5 \n"
        assert (
            self.a.euler(0, 1, 0)[1] == -1
        ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[1]!=-1 \n"
        assert (
            self.a.euler(0, 1, 0)[2] == 0
        ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[2]!=0 \n"
Exemple #20
0
 def test_rk4(self):
     """Test fourth-order RK method yields results.  I chose this test to verify that the 4th order RK method yields results and, if not, is the error associated with the calculation of the x-value, y-value, or z-value."""
     attr = Attractor()
     attr.evolve([10,10,10],4)
     print "Test for error in solution for x using rk4 method, Order=4"
     assert attr.solution['x'].count() > 0
     print "    PASSED!!!!"
     print "Test for error in solution for y using rk4 method, Order=4"
     assert attr.solution['y'].count() > 0
     print "    PASSED!!!!"
     print "Test for error in solution for z using rk4 method, Order=4"
     assert attr.solution['z'].count() > 0
     print "    PASSED!!!!"
Exemple #21
0
 def test_euler(self):
     """Test Euler method yields results.  I chose this test to verify that the Euler Method yields results.  If there is an error is it associated with the calculation of the x-value, y-value, or z-value."""
     attr = Attractor()
     attr.evolve([10,10,10],1)
     print "Assert output for Euler method, x parameter."
     assert attr.solution['x'].count() > 0
     print "    PASSED!!!!"
     print "Assert output for Euler method, y parameter."
     assert attr.solution['y'].count() > 0
     print "    PASSED!!!!"
     print "Assert output for Euler method z parameter."
     assert attr.solution['z'].count() > 0
     print "    PASSED!!!!"
Exemple #22
0
 def euler_test(self):
     """Tests Euler's method in Attractor and ensures the arrays are being filled to the correct and same sizes"""
     a = Attractor()
     a.evolve([1, 2, 3], 1)
     assert len(a.solution['x']) > 0, "\nError in Euler's solution for x"
     assert len(a.solution['y']) > 0, "\nError in Euler's solution for y"
     assert len(a.solution['z']) > 0, "\nError in Euler's solution for z"
     assert len(a.solution['x']) == len(
         a.solution['y']
     ), "\nError in assigning values to arrays for solution x and/or y"
     assert len(a.solution['y']) == len(
         a.solution['z']
     ), "\nError in assigning values to arrays for solution y and/or z"
Exemple #23
0
 def rk4_test(self):
     """Tests the fourth order Runge Kutta method and ensures the arrays are being filled correctly and similarily"""
     a = Attractor()
     a.evolve([1, 2, 3], 4)
     assert len(a.solution['x']) > 0, "\nError in RK4 solution for x"
     assert len(a.solution['y']) > 0, "\nError in RK4 solution for y"
     assert len(a.solution['z']) > 0, "\nError in RK4 solution for z"
     assert len(a.solution['x']) == len(
         a.solution['y']
     ), "\nError in assigning values to arrays for solution x and/or y"
     assert len(a.solution['y']) == len(
         a.solution['z']
     ), "\nError in assigning values to arrays for solution y and/or z"
def test_euler():
    """Tests if dx from euler method is implemented properly
    Uses set x, y, and z to be 0.1, 0.0, 0.0"""
    a = Attractor()
    #say x, y, z = [0.1, 0.0, 0.0]

    dx = (10 * (0.0 - 0.1)) * (80.0 - 0.0) / 10000
    dy = (0.1 * (28 - 0.0) - 0.0) * (80.0 - 0.0) / 10000
    dz = ((0.1 * 0.0) - (8 / 3 * 0.0)) * (80.0 - 0.0) / 10000
    ex_euler = np.array([dx, dy, dz])

    print("Actual increments: ", a.euler([0.1, 0.0, 0.0]))
    print("Expected increments: ", ex_euler)
    assert a.euler([0.1, 0.0, 0.0])[0] == ex_euler[0]
Exemple #25
0
    def test_modify_attr(self):
        #inputs
        old_states = ['11','00']
        new_states = ['11','10', '00', '01', '11']
        f_type = "lambda_bool"
        node_names = ['a','b']
        old_sol = [[0,0], [1,1]] 
        new_sol = [[0,0], [0,1], [1,1], [1,0]] 

        #declare attr
        attr = Attractor(old_states, f_type, node_names)
        self.assertEqual( old_sol, attr.states)
        #modify states
        attr.states = new_states
        self.assertEqual( new_sol, attr.states)
class TestRandomValues:
    """Define an Attractor with random values for s, p and b, test interface"""

    def setup(self):
        """Setup fixture is run before every test method separately"""
        s = random.uniform(15, 20)
        p = random.uniform(1, 5)
        b = random.uniform(10, 15)
        self.s = s
        self.p = p
        self.b = b
        start = 0
        end = random.uniform(5, 30)
        points = random.randint(5, 100)
        self.start = start
        self.end = end
        self.points = points
        self.a = Attractor(s, p, b, start, end, points)

    def test_defintions(self):
        """Test the first definitions of the class"""
        assert (
            self.a.params[0] == self.s
        ), "\n Error in the definition of self.params. The first argument should coincide with the value of s, the first input of the class.\n"
        assert (
            self.a.params[1] == self.p
        ), "\n Error in the definition of self.params. The second argument should coincide with the value of p, the second input of the class.\n"
        assert (
            self.a.params[2] == self.b
        ), "\n Error in the definition of self.params. The third argument should coincide with the value of b, the third input of the class.\n"
        assert self.a.dt == (self.end - self.start) / self.points, "\n Error in the definition of self.dt.\n"

    def test_ks(self):
        """Test if the methods euler, rk2 and rk4 are generating the correct answer"""
        # The outputs based on specific inputs were calculated by hand and here are compared with the values generated by the Attractor class.
        self.a = Attractor(1.0, 1.0, 1.0, 0.0, 80.0, 100)
        c = np.array([2, 3, 4])
        assert self.a.euler(c)[0] == 1.0, "\n Error in the first element of the np.array output of euler method.\n"
        assert self.a.euler(c)[1] == -9.0, "\n Error in the second element of the np.array output of euler method.\n"
        assert self.a.euler(c)[2] == 2.0, "\n Error in the third element of the np.array output of euler method.\n"
        assert self.a.rk2(c)[0] == -3.0, "\n Error in the first element of the np.array output of rk2 method.\n"
        assert self.a.rk2(c)[1] == -8.52, "\n Error in the second element of the np.array output of rk2 method.\n"
        assert self.a.rk2(c)[2] == -6.24, "\n Error in the third element of the np.array output of rk2 method.\n"
        assert self.a.rk4(c)[0] == 1.97024, "\n Error in the first element of the np.array output of rk4 method.\n"
        assert int(self.a.rk4(c)[1]) == -4, "\n Error in the second element of the np.array output of rk4 method.\n"
        assert int(self.a.rk4(c)[2]) == 0, "\n Error in the third element of the np.array output of rk4 method.\n"

    def test_solve(self):
        """Test if solve is printing in the CSV file"""
        # The method deletes the current csv file (if there is one) and creates another one by calling the method 'save'. After that, it analyses if there is somemething written inside the new file.
        os.remove("save_solution.csv")
        self.a.save()
        data = open("save_solution.csv", "r")
        d = data.read()
        assert (
            len(d) > 0
        ), "\nError in the save method. It is not creating the save_solution.csv file or saving the information of self.solution in it.\n"
def test_dt():
    """Tests step Value"""
    a = Attractor()
    dt_true = (80.0 - 0.0) / 10000

    print("Actual dt value: ", a.dt)
    print("Expected dt value: ", dt_true)
    assert a.dt == dt_true
Exemple #28
0
 def setup(self):
     """Test that initial conditions are setup correctly for default values (start, end, points) and default over-ride (s, p, q).  I chose this test so that the initial conditions can be verified and if there is an error identify which parameter the problem is associated with."""
     s = randint(1,10)
     p = randint(1,10)
     b = randint(1,10)
     attr = Attractor(s, p, b)
     attr.s_t = s
     attr.p_t = p
     attr.b_t = b
     attr = Attractor(attr.s_t, attr.p_t, attr.b_t)
     print "Assert value for s parameter over-ride"
     assert attr.params[0] == s
     print "    PASSED!!!!"
     print "Assert value for p parameter over-ride"
     assert attr.params[1] == p
     print "    PASSED!!!!"
     print "Assert value for b parameter over-ride"
     assert attr.params[2] == b
     print "    PASSED!!!!"
     print "Assert default value for start parameter"
     assert attr.start == 0
     print "    PASSED!!!!"
     print "Assert default value for end parameter"
     assert attr.end == 80
     print "    PASSED!!!!"
     print "Assert default value for points parameter"
     assert attr.points == 10000
     print "    PASSED!!!!"
Exemple #29
0
    def setup(self):
        width, height = [600, 400]

        self.a = Attractor(width, height)

        self.balls = []
        for i in range(0, 10):
            self.balls.append(Ball(width,height))

        self.size(width, height)
def test_y_generate():
    """Tests if evolve method is implemented properly
    Uses set x, y, and z to be 0.1, 0.0, 0.0"""
    a = Attractor()
    #say x, y, z = [0.1, 0.0, 0.0]

    dx = (10.0 * (0.0 - 0.1)) * (80.0 - 0.0) / 10000 + 0.1
    dy = (0.1 * (28 - 0.0) - 0.0) * (80.0 - 0.0) / 10000 + 0.0
    dz = ((0.1 * 0.0) - (8 / 3 * 0.0)) * (80.0 - 0.0) / 10000 + 0.0
    ex_1 = np.array([dx, dy, dz])

    dx2 = (10.0 * (dy - dx)) * (80.0 - 0.0) / 10000.0 + dx
    dy2 = (dx * (28.0 - dz) - dy) * (80.0 - 0.0) / 10000.0 + dy
    dz2 = ((dx * dy) - (8 / 3 * dz)) * (80.0 - 0.0) / 10000.0 + dz
    ex_2 = np.array([dx2, dy2, dz2])

    dx3 = (10.0 * (dy2 - dx2)) * (80.0 - 0.0) / 10000.0 + dx2
    dy3 = (dx2 * (28.0 - dz2) - dy2) * (80.0 - 0.0) / 10000.0 + dy2
    dz3 = ((dx2 * dy2) - (8 / 3 * dz2)) * (80.0 - 0.0) / 10000.0 + dz2
    ex_3 = np.array([dx3, dy3, dz3])

    dx4 = (10.0 * (dy3 - dx3)) * (80.0 - 0.0) / 10000.0 + dx3
    dy4 = (dx3 * (28 - dz3) - dy3) * (80.0 - 0.0) / 10000.0 + dy3
    dz4 = ((dx3 * dy3) - (8 / 3 * dz3)) * (80.0 - 0.0) / 10000.0 + dz3
    ex_4 = np.array([dx4, dy4, dz4])

    dx5 = (10.0 * (dy4 - dx4)) * (80.0 - 0.0) / 10000.0 + dx4
    dy5 = (dx4 * (28 - dz4) - dy4) * (80.0 - 0.0) / 10000.0 + dy4
    dz5 = ((dx4 * dy4) - (8 / 3 * dz4)) * (80.0 - 0.0) / 10000.0 + dz4
    ex_5 = np.array([dx5, dy5, dz5])

    a.evolve(order=4)
    y_list = a.solution['y'].tolist()

    for i in y_list[:6]:
        yy = round(i, 2)
    for j in [0.0, dy, dy2, dy3, dy4, dy5]:
        yyy = round(j, 2)

    print("Actual increments: ", yy)  #str(a.solution()['x']).strip('[]'))
    print("Expected increments: ", yyy)
    assert yy == yyy
Exemple #31
0
 def init_test(self):
     """Tests the initial setup for the problem to ensure the initial values are set correctly, the increment exists, and there are empty arrays for our variables to be filled later"""
     a = Attractor()
     assert a.params[0] == 10.0, "\nError in assigning initial parameter s"
     assert a.params[1] == 28.0, "\nError in assigning initial parameter p"
     assert a.params[
         2] == 8.0 / 3.0, "\nError in assigning initial parameter b"
     assert len(
         a.params
     ) > 0, "\nError in assigning initial parameters to params array"
     assert a.dt > 0, "\nError in setting up dt"
class TestEuler(unittest.TestCase):
    """This is set of basic test for Euler method"""

    def setUp(self):
        self.a = Attractor()
        self.a.points = 10000
        self.a.start = 0
        self.a.end = 100

    def test_dataframe(self):
        """Make sure the data frame is created with right number of rows"""
        df = self.a.evolve(order=1)
        print "This is length of dataframe", len(df)
        assert len(df) - 1 == 10000  # subrtact 1 for the title row

    def test_filesave(self):
        """Test ot make sure we are able to save the file"""
        file_save_status = self.a.save()
        print "The status of file save is ", file_save_status
        assert file_save_status == True
 def test_euler(self):
     """Test if the methods euler is generating the correct answer and we can do this for rk2 and rk4"""
     self.a = Attractor(5, 1, 3, 0, 80, 100)
     assert (
         self.a.euler(0, 1, 0)[0] == 5
     ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[0]!=5 \n"
     assert (
         self.a.euler(0, 1, 0)[1] == -1
     ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[1]!=-1 \n"
     assert (
         self.a.euler(0, 1, 0)[2] == 0
     ), "\n we want to test that value of euler[0] save correctly,it gives us error if euler[2]!=0 \n"
Exemple #34
0
def ball_control():
    att = Attractor(pygame.math.Vector2(mouse_X, mouse_Y))
    att.draw(win)
    print(mouse_X, mouse_Y)

    if len(balls) < NUMBER_OF_BALLS:
        posInit = pygame.math.Vector2(random.randint(0, W),
                                      random.randint(0, H))
        sz = random.randint(2, MAX_SIZE)
        ball = Ball(posInit, sz**2, sz, sz)
        balls.append(ball)

    flag = False
    for ball in balls:
        attForce = att.attract(ball)
        ball.add_force(attForce)
        ball.add_force(gForce)
        if flag:
            ball.add_force(wForce)
            flag = False
        else:
            ball.add_force(-wForce)
            flag = True

        # friction = - ball.vel
        # if friction.length() != 0:
        #     friction.normalize()
        #     friction *= 0.01
        # ball.add_force(friction)

        ball.update()
        ball.check_edges()
        ball.draw(win)

    for i in range(len(balls)):
        if i < len(balls) - 1:
            balls[i].draw_line(balls[i + 1], win)
        else:
            balls[0].draw_line(balls[i], win)
 def test_ks(self):
     """Test if the methods euler, rk2 and rk4 are generating the correct answer"""
     # The outputs based on specific inputs were calculated by hand and here are compared with the values generated by the Attractor class.
     self.a = Attractor(1.0, 1.0, 1.0, 0.0, 80.0, 100)
     c = np.array([2, 3, 4])
     assert self.a.euler(c)[0] == 1.0, "\n Error in the first element of the np.array output of euler method.\n"
     assert self.a.euler(c)[1] == -9.0, "\n Error in the second element of the np.array output of euler method.\n"
     assert self.a.euler(c)[2] == 2.0, "\n Error in the third element of the np.array output of euler method.\n"
     assert self.a.rk2(c)[0] == -3.0, "\n Error in the first element of the np.array output of rk2 method.\n"
     assert self.a.rk2(c)[1] == -8.52, "\n Error in the second element of the np.array output of rk2 method.\n"
     assert self.a.rk2(c)[2] == -6.24, "\n Error in the third element of the np.array output of rk2 method.\n"
     assert self.a.rk4(c)[0] == 1.97024, "\n Error in the first element of the np.array output of rk4 method.\n"
     assert int(self.a.rk4(c)[1]) == -4, "\n Error in the second element of the np.array output of rk4 method.\n"
     assert int(self.a.rk4(c)[2]) == 0, "\n Error in the third element of the np.array output of rk4 method.\n"
 def setup(self):
     """Setup fixture is run before every test method separately"""
     s = random.uniform(1, 20)
     p = random.uniform(1, 10)
     b = random.uniform(1, 15)
     self.s = s
     self.p = p
     self.b = b
     start = 0
     end = random.uniform(10, 50)
     points = random.randint(50, 200)
     self.start = start
     self.end = end
     self.points = points
     self.a = Attractor(s, p, b, start, end, points)
Exemple #37
0
def test_save_csv():
    ''' Ensure that the csv file is created
    '''
    filename = 'filename.csv'
    a = Attractor()
    os.remove(filename)
    a.evolve()
    a.save(filename)
    assert os.path.exists(filename), "\n no output file found \n"
    print(" test_save_csv method is working as expected ")
Exemple #38
0
    def __init__(self, game):
        self.game = game
        self.canvas = game.canvas
        self.background = pygame.image.load(
            os.path.join('images', self.name.lower(), 'background.png'))

        self.console_image = pygame.image.load(
            os.path.join('images', self.name.lower(), 'console.png'))
        self.attractors = []
        self.flock = None
        self.flock = Flock(self)
        self.has_visited = False
        self._level_complete = False

        if self.exit_gate_position:
            self.attractors.append(
                Attractor(self.exit_gate_position, 500,
                          Settings.gate_radius * 2))
        # 'Attractors': AttractorsRule(self, 1, [Attractor((300, 300), 50)]),
        self.flowers = []

        self.init_level()
 def setUp(self):
     self.a = Attractor()
     self.a.points = 10000
     self.a.start = 0
     self.a.end = 100
Exemple #40
0
from attractor import Attractor

if __name__ == "__main__":
    AL = Attractor()
    AL.animation("RK4", True)
Exemple #41
0
 def save_test(self):
     """Tests to see if a save file was created by creating another save file"""
     a = Attractor()
     a.evolve()
     a.save()
Exemple #42
0
def test_dt_value():
    ''' Ensure that dt is calculated as it is supposed to be
    '''
    a = Attractor()
    assert a.end == a.dt * a.points, "\n time step is not properly evaluated \n"
 def setup(self):
     """Setup fixture is run before every test method separately"""
     self.at = Attractor(self.c, self.n)
Exemple #44
0
    methods = Attractor.methods

    res = {}

    log_scale = True

    for method in methods:
        for inv in range(1, 6):
            # calcs.append((method,inv))
            # res_h.append([])
            #
            # continue
            print("=============================")
            print(f'{method}@{inv}')

            AL1 = Attractor(step=0.0001,
                            num_steps=10000)  # TODO Шаг выставляется тут!
            AL1.set_invariant_params(inv)
            AL1.call_method(method)
            calls = AL1.get_counter()
            print("calls_f: ", calls)
            # Get inv func
            I, err = AL1.get_invariant_err(inv)
            # Cut thirds
            l = int(I.shape[1] * (1.0 / 3.0))
            I = I[:, l:-l]
            err = err[:, l:-l]
            txt = f'{method}@{inv}#{calls}'

            # fig.savefig
            M = np.mean(I[0])
            D = np.std(I[0] - M)
from attractor import Attractor

if __name__ == "__main__":
    # Euler
    AL1 = Attractor()
    AL1.call_method("EUL1")
    AL1.show("img/Euler", "Euler's method", False, True)
    print("Вызовов EUL1 f: ", AL1.get_counter())

    # Midpoint
    AL2 = Attractor()
    AL2.call_method("MIDP2")
    AL2.show("img/Midpoint", "Midpoint method", False, True)
    print("Вызовов MIDP2 f: ", AL2.get_counter())

    # RK4
    AL3 = Attractor()
    AL3.call_method("RK4")
    AL3.show("img/RK4", "RK4 method", False, True)
    print("Вызовов RK4 f: ", AL3.get_counter())

    # Adams Bashforts
    AL4 = Attractor()
    AL4.call_method("AB4")
    AL4.show("img/Adams_Bashforts_", "Adams Bashfort method", False, True)
    print("Вызовов AB4 f: ", AL4.get_counter())

    # Adams Moulton 5
    AL5 = Attractor()
    AL5.call_method("ABM5")
    AL5.show("img/Adams_Bashforts_Moulton", "Adams-Bashfort-Moulton", False, True)
def test_rhs_shape():
    ''' Validate that the shape of the rhs method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.rhs(xyz).shape == (3, ), "\n the shape of the array that was returned is not 3 \n"
def test_evolve_shape():
    ''' Validate that the shape of evolve method return value
    '''
    a = Attractor()
    assert a.evolve().shape == (a.points, 4), "\n the array that was obtained does not have a proper shape \n"
def test_rk4_shape():
    ''' Validate that the shape of rk4 method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.rk4(xyz).shape == (3, ), "\n the shape of the array that was obtained from rk4 is not 3 \n"
def test_euler_shape():
    ''' Validate that the shape of the euler method return value
    '''
    a = Attractor()
    xyz = np.array([0.0, 0.0, 0.0])
    assert a.euler(xyz).shape == (3, ), "\n the shape of the array that was obtained from euler is not 3 \n"