Skip to content

Instantly share code, notes, and snippets.

@adamatti
Last active November 1, 2019 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamatti/9bca7583082ac02961625bbd56932461 to your computer and use it in GitHub Desktop.
Save adamatti/9bca7583082ac02961625bbd56932461 to your computer and use it in GitHub Desktop.
Resultado do dojo de python - 04/05/2017 #dojo
import unittest
from sort import BubbleSort
class BubbleSortTest(unittest.TestCase):
def setUp(self):
self.bubble_sort = BubbleSort()
def testSortEmptyList(self):
lista = []
self.assertEqual(lista, self.bubble_sort.sort(lista))
def testSortListOneElement(self):
lista = [1]
self.assertEqual(lista, self.bubble_sort.sort(lista))
def testSortListTwoElementSorted(self):
lista = [1, 2]
self.assertEqual(lista, self.bubble_sort.sort(lista))
def testSortListTwoElementUnsorted(self):
lista = [2, 1]
self.assertEqual([1, 2], self.bubble_sort.sort(lista))
def testSortListThreeElementUnsorted(self):
lista = [2, 1, 5]
self.assertEqual([1, 2, 5], self.bubble_sort.sort(lista))
if __name__=='__main__':
unittest.main()
class Morse:
def __init__(self):
self.dicionario = { "S" : "...", "O" : "---"}
def StringToMorse(self, texto):
traduzao = ""
texto = texto.strip()
texto = texto.upper()
for chave in texto:
traduzao += " " + self.dicionario[chave]
return traduzao.strip()
class Sort:
def run(self, items):
for i in range(len(items)):
for j in range(len(items)-1-i):
if items[j] > items[j+1]:
items[j], items[j+1] = items[j+1], items[j]
return items
#http://interactivepython.org/courselib/static/pythonds/SortSearch/TheBubbleSort.html
def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
alist = [54,26,93,17,77,31,44,55,20]
bubbleSort(alist)
print(alist)
class BubbleSort:
def sort(self, lista):
for x in (range(1,len(lista))):
if lista[x - 1] > lista[x]:
aux = lista[x-1]
lista[x-1] = lista[x]
lista[x] = aux
return lista
import unittest
from morse import Morse
class Test_Morse(unittest.TestCase):
def testStringToMorse(self):
m = Morse();
self.assertEqual("... --- ...", m.StringToMorse("SOS"))
self.assertEqual("... --- ...", m.StringToMorse("sos"))
self.assertEqual("... --- ...", m.StringToMorse(" sos "))
if __name__=='__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment