Created
November 10, 2010 14:02
-
-
Save nati57/670882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@author Rafael Salomao <rafaelgavazzi at gmail.com> | |
#@author Natalia Marcondes < natalia.marcondes at gmail.com> | |
#@author Marco Moura <email at marcomoura.com> | |
#@author Carlos Eduardo <kaddxxi at gmail.com> | |
__date__ ="$10/11/2010 10:20:24$" | |
class Despertador: | |
@staticmethod | |
def subtracao_minutos(minInicial,minFinal): | |
minTotal = minFinal - minInicial ; | |
return minTotal | |
@staticmethod | |
def conversao_horaminuto(hora): | |
minutos = hora * 60; | |
return minutos | |
@staticmethod | |
def conversao_minutos(hora,minuto): | |
hora= Despertador.conversao_horaminuto(hora) | |
minutosTotal=hora+minuto | |
return minutosTotal | |
@staticmethod | |
def despertar(hora_dormir, minuto_dormir, hora_acordar, minuto_acordar): | |
''' | |
check period of time between hours | |
return minutes total | |
''' | |
validar_hora_dormir = Despertador.validar_hora(hora_dormir) | |
validar_hora_acordar = Despertador.validar_hora(hora_acordar) | |
if validar_hora_dormir == False or validar_hora_acordar == False: | |
pass | |
return Despertador.conversao_minutos(hora_acordar, minuto_acordar) - Despertador.conversao_minutos(hora_dormir, minuto_dormir) | |
@staticmethod | |
def validar_hora(hora): | |
if hora <= 23 and hora >= 0: | |
return True | |
else: | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@author Rafael Salomao <rafaelgavazzi at gmail.com> | |
#@author Natalia Marcondes < natalia.marcondes at gmail.com> | |
#@author Marco Moura <email at marcomoura.com> | |
#@author Carlos Eduardo <kaddxxi at gmail.com> | |
import unittest | |
from despertador import Despertador | |
class Test_alarmeTestCase(unittest.TestCase): | |
def test_subtracao_minuto_1_do_11(self): | |
self.assertEqual(10,Despertador.subtracao_minutos(1,11)) | |
def test_subtracao_minuto_0_do_50(self): | |
self.assertEqual(50,Despertador.subtracao_minutos(0,50)) | |
def test_subtracao_minuto_10_do_40(self): | |
self.assertEqual(30,Despertador.subtracao_minutos(10,40)) | |
def test_conversao_de_1_hora_para_60_minuto(self): | |
self.assertEqual(60,Despertador.conversao_horaminuto(1)) | |
def test_conversao_de_2_hora_para_120_minuto(self): | |
self.assertEqual(120,Despertador.conversao_horaminuto(2)) | |
def test_conversao_de_8_hora_para_480_minuto(self): | |
self.assertEqual(480,Despertador.conversao_horaminuto(8)) | |
def test_transforma_1_hora_e_5_minutos_em_minutos(self): | |
self.assertEqual(65,Despertador.conversao_minutos(1,5)) | |
def test_transforma_3_horas_e_15_minutos_em_minutos(self): | |
self.assertEqual(195,Despertador.conversao_minutos(3,15)) | |
def test_should_be_130_when_sleep_1_5_and_wakeup_3_15(self): | |
self.assertEqual(130,Despertador.despertar(1,5,3,15)) | |
def test_should_be_75_when_sleep_0_0_and_wakeup_1_15(self): | |
self.assertEqual(75,Despertador.despertar(0,0,1,15)) | |
def test_validar_hora_22(self): | |
self.assertTrue(Despertador.validar_hora(22)) | |
def test_validar_hora_1(self): | |
self.assertTrue(Despertador.validar_hora(1)) | |
def test_validar_hora_24(self): | |
self.assertFalse(Despertador.validar_hora(24)) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment