I defined this class using spyder and to test it my teacher would create 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?
class Caminhos():
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._caminhoI[i] == v:
b = True
i = i + 1
return b
def verticePos(self, v):
#aqui preferia aplicar a pertenceQ ao V mas n sei bem a sintaxe
i = 0
b = False
while i < len(self._caminhoI) and not b:
if self._caminhoI[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._caminhoI[i] == v:
d = True
i = i + 1
return i
def mostra(self):
return self._caminhoI