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()
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_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 ")
Esempio n. 4
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 ")
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"
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]
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 save_test(self):
     """Tests to see if a save file was created by creating another save file"""
     a = Attractor()
     a.evolve()
     a.save()
Esempio n. 9
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()