コード例 #1
0
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]
コード例 #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
コード例 #3
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"
コード例 #4
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"
コード例 #5
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 ")
コード例 #6
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 ")
コード例 #7
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"
コード例 #8
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!!!!"
コード例 #9
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!!!!"
コード例 #10
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"
コード例 #11
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"
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
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()
コード例 #15
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"
コード例 #16
0
def test_evolve():
    """ This test case is to ensure proper number of parameters are being passed to the evolve method. As
    above, this test also check for proper passing of paramters."""
    a = Attractor()
    assert a.evolve().shape == (a.points, 4), "\n The array given to the evolve method was improper!\n"
コード例 #17
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()