Solució del lliurament 1 G40 d’Ampliació d’Informàtica

Organització:

Secció ETSEIB, Departament de Ciències de la Computació, UPC

Data:

13 de març de 2024

Durada:

45 minuts

Copyright:

Reconeixement-CompartirIgual 4.0 No adaptada de Creative Commons

Jocs de proves

maxmin_locals

>>> from maxmin_locals import maxmin_locals
>>> l = [10, 20, 30, 20, 10]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == [('max', 30, 2)]    # doctesttag: +TAG=1_maxmin_locals
True
>>> l = [20, 10, 20]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == [('min', 10, 1)]    # doctesttag: +TAG=1_maxmin_locals
True
>>> l = [20, 30, 20, 10, 20]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == [('max', 30, 1), ('min', 10, 3)]    # doctesttag: +TAG=1_maxmin_locals
True
>>> l = [10, 20, 30, 20, 10, 20, 30, 15, 20, 10]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == [('max', 30, 2), ('min', 10, 4), ('max', 30, 6), ('min', 15, 7), ('max', 20, 8)]    # doctesttag: +TAG=1_maxmin_locals
True
>>> l = [10, 20, 30, 30, 20, 10]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == []    # doctesttag: +TAG=1_maxmin_locals
True
>>> l = [50, 40, 30, 30, 45, 55]
>>> it = iter(l)
>>> itsol = maxmin_locals(it)
>>> list(itsol) == []    # doctesttag: +TAG=1_maxmin_locals
True

horari_descans

>>> import horaris
>>> from datetime import time, date, datetime, timedelta
>>> ti, tf, dia = time(10, 5, 0), time(12, 0, 0), date(2024, 3, 11)
>>> horaris.horari_descans(ti, tf, dia, timedelta(minutes=10))    # doctesttag: +TAG=2_horari_descans
(True, datetime.datetime(2024, 3, 11, 10, 57, 30), datetime.datetime(2024, 3, 11, 11, 7, 30))
>>> horaris.horari_descans(ti, tf, dia, timedelta(minutes=120))    # doctesttag: +TAG=2_horari_descans
(False, datetime.datetime(2024, 3, 11, 10, 5), datetime.datetime(2024, 3, 11, 12, 0))
>>> horaris.horari_descans(ti, tf, dia, timedelta(0))    # doctesttag: +TAG=2_horari_descans
(False, datetime.datetime(2024, 3, 11, 10, 5), datetime.datetime(2024, 3, 11, 12, 0))
>>> ti, tf, dia = time(9, 5, 0), time(10, 55, 0), date(2024, 5, 31)
>>> horaris.horari_descans(ti, tf, dia, timedelta(minutes=15, seconds=30))    # doctesttag: +TAG=2_horari_descans
(True, datetime.datetime(2024, 5, 31, 9, 52, 15), datetime.datetime(2024, 5, 31, 10, 7, 45))
>>> horaris.horari_descans(ti, tf, dia, timedelta(minutes=5))    # doctesttag: +TAG=2_horari_descans
(True, datetime.datetime(2024, 5, 31, 9, 57, 30), datetime.datetime(2024, 5, 31, 10, 2, 30))
>>> horaris.horari_descans(ti, tf, dia, timedelta(minutes=170))    # doctesttag: +TAG=2_horari_descans
(False, datetime.datetime(2024, 5, 31, 9, 5), datetime.datetime(2024, 5, 31, 10, 55))

congruent_nums

>>> from congruents import congruent_nums
>>> from fractions import Fraction
>>> l = [Fraction(1, 3), Fraction(2, 3), Fraction(4, 3)]
>>> it1, it2 = congruent_nums(iter(l), Fraction(1, 3))
>>> it1 == iter(it1) and list(it1) == [1, 4] and it2 == iter(it2) and list(it2) == []    # doctesttag: +TAG=3_congruent_nums
True
>>> l = [Fraction(-1, 3), Fraction(-2, 3), Fraction(-3, 3), Fraction(-4, 3), Fraction(-5, 3)]
>>> it1, it2 = congruent_nums(iter(l), Fraction(1, 3))
>>> it1 == iter(it1) and list(it1) == [] and it2 == iter(it2) and list(it2) == [-2, -5]    # doctesttag: +TAG=3_congruent_nums
True
>>> l = [Fraction(1, 3), Fraction(3, 3), Fraction(4, 3), Fraction(-2, 3)]
>>> l.extend([Fraction(-22, 6), Fraction(2, 6), Fraction(5, 3), Fraction(14, 6), Fraction(-4, 6)])
>>> it1, it2 = congruent_nums(iter(l), Fraction(1, 3))
>>> it1 == iter(it1) and list(it1) == [1, 4, 1, 7] and it2 == iter(it2) and list(it2) == [-2, -11, -2]    # doctesttag: +TAG=3_congruent_nums
True
>>> l = [Fraction(2, 3), Fraction(3, 3), Fraction(5, 3), Fraction(1, 6)]
>>> it1, it2 = congruent_nums(iter(l), Fraction(1, 3))
>>> it1 == iter(it1) and list(it1) == [] and it2 == iter(it2) and list(it2) == []    # doctesttag: +TAG=3_congruent_nums
True
>>> l = [Fraction(15, 6), Fraction(5, 3), Fraction(-1, 3), Fraction(-21, 6)]
>>> it1, it2 = congruent_nums(iter(l), Fraction(1, 3))
>>> it1 == iter(it1) and list(it1) == [] and it2 == iter(it2) and list(it2) == []    # doctesttag: +TAG=3_congruent_nums
True