mardi 8 décembre 2020

How do I test classes in phyton?

I defined this class using spyder and to test it my teacher would creat a new file just for testing and he would check if each method returned the desired result, can anyone tell me how to do that?

    
    def __init__(self,vi,vf):
        self._vi=vi
        self._vf=vf
        self._caminhoI=[vi,vf]
        
    def primeiroV(self):
        return self._caminhoI[0]
    
    def ultimoV(self):
        return self._caminhoI[-1]
    
    def comprimento(self):
        return len(self._caminhoI)

    def acrescentaV(self,v):
        self._caminhoI=self._caminhoI+[v]
    
    def pertenceQ(self,v):
        i=0
        b=False
        while i<len(self._caminhoI) and not b:
            if self._caminho[i]==v:
                b=True
            i=i+1
        return b
        
    def verticePos(self,v):
        i=0                      #aqui preferia aplicar a pertenceQ ao V mas n sei bem a sintaxe
        b=False
        while i<len(self._caminhoI) and not b:
            if self._caminho[i]==v:
                b=True
            i=i+1
        if not b:
            print("Erro, o vertice nao pertence ao caminho")
        else:
            i=0
            d=False
            while i<len(self._caminhoI) and not d:
                if self._caminho[i]==v:
                    d=True
                i=i+1
            return i
        
    def mostra(self):
        return self._caminhoI```

Aucun commentaire:

Enregistrer un commentaire