python Resultado do dojo de python - 04/05/2017

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Resultado do dojo de python - 04/05/2017相关的知识,希望对你有一定的参考价值。

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()


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
#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 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
* https://docs.google.com/presentation/d/1VQOoaa2BoQwJS-2OCoSP7p19RvFezKfKFolYR_5tma8/edit[Slides]
* https://ide.c9.io/adamatti/learn-python[Workspace no cloud9] 
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()
		
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()

以上是关于python Resultado do dojo de python - 04/05/2017的主要内容,如果未能解决你的问题,请参考以下文章

DOJO按钮示例[关闭]

Dojo 小部件未正确呈现

data-dojo-type 和 dojotype 有啥区别?

在dojo中使用onclick事件刷新页面,我不想刷新页面

在Django Dojo中使用bootswatch

如何添加 optgroup do dijit.form.Select 或其他小部件类型