dimanche 15 novembre 2020

How do I make a test function for a class method?

I got this class, and I want to test the call method to see if the class is working properly. I'm implementing a test for testing that class Cooling works. The test function should verify that the call method returns the correct results for given values of the arguments T and t (the input into the call method is T and t) How would you solve it? With test function i mean with def test_cooling(): My code is under:

class Cooling:
    def __init__(self,h,Ts):
        self.h=h
        self.Ts=Ts
        
    def __call__(self, T, t):
        self.T = T
        self.t = t
        h = -self.h*(self.T - self.Ts)
        self.T = (self.T) + self.t*h
        return self.T, self.t

I have tried with

def test_Cooling(self):
        c=Cooling()
        expected=c.__call__(T,t)
        self.assertTrue(expected, msg=None)

Aucun commentaire:

Enregistrer un commentaire