>>> from unitats import calcula_canvi_unitats >>> prefixos = { ... 'd': 1e-1, ... 'c': 1e-2, ... 'm': 1e-3, ... 'da': 1e1, ... 'h': 1e2, ... 'k': 1e3, ... } >>> eps = 1e-6 La unitat de referència és cm³ >>> cu = calcula_canvi_unitats('m³', 3, 1e6, prefixos) >>> ru = { ... 'm³': 1e6, ... 'dam³': 1e9, ... 'hm³': 1e12, ... 'km³': 1e15, ... 'dm³': 1e3, ... 'cm³': 1, ... 'mm³': 1e-3, ... } ru == cu amb tolerància eps en cada unitat >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats >>> cu = calcula_canvi_unitats('l', 1, 1e3, prefixos) >>> ru = { ... 'l': 1e3, ... 'dal': 1e4, ... 'hl': 1e5, ... 'kl': 1e6, ... 'dl': 1e2, ... 'cl': 1e1, ... 'ml': 1, ... } >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats La unitat de referència és mm² >>> cu = calcula_canvi_unitats('m²', 2, 1e6, prefixos) >>> ru = { ... 'm²': 1e6, ... 'dam²': 1e8, ... 'hm²': 1e10, ... 'km²': 1e12, ... 'dm²': 1e4, ... 'cm²': 1e2, ... 'mm²': 1, ... } >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats La unitat de referència és m >>> cu = calcula_canvi_unitats('m', 1, 1, prefixos) >>> ru = { ... 'm': 1, ... 'dam': 1e1, ... 'hm': 1e2, ... 'km': 1e3, ... 'dm': 1e-1, ... 'cm': 1e-2, ... 'mm': 1e-3, ... } >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats La unitat de referència és mi (milles) >>> cu = calcula_canvi_unitats('m', 1, 1/1609.344, prefixos) >>> ru = { ... 'm': 0.0006213711922373339, ... 'dm': 6.213711922373339e-05, ... 'cm': 6.213711922373339e-06, ... 'mm': 6.21371192237334e-07, ... 'dam': 0.006213711922373339, ... 'hm': 0.06213711922373339, ... 'km': 0.621371192237334 ... } >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats La unitat de referència és ha >>> cu = calcula_canvi_unitats('m²', 2, 1e-4, prefixos) >>> ru = { ... 'm²': 0.0001, ... 'dm²': 1e-06, ... 'cm²': 1e-08, ... 'mm²': 1e-10, ... 'dam²': 0.01, ... 'hm²': 1.0, ... 'km²': 100.0 ... } >>> if any(map(lambda x: abs(cu[x] - ru[x]) >= eps, ru)): print(cu) # doctesttag: +TAG=1_unitats >>> import os >>> from correus_e import filtra_capcalera >>> text = """\ ... Received: from x.y.test ... by example.net ... via TCP ... with ESMTP ... id ABC12345 ... for ; 21 Nov 1997 10:05:43 -0600 ... Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 ... From: John Doe ... To: Mary Smith ... Subject: Saying Hello ... Date: Fri, 21 Nov 1997 09:55:06 -0600 ... Message-ID: <1234@local.node.example> ... ... This is a message just to say hello. ... So, "Hello". ... """ >>> nf = 'correu-1.txt' >>> with open(nf, 'w') as f: r = f.write(text) >>> nfc = 'correu-1.txt' >>> camps = ['Received', 'To'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e Received: from x.y.test by example.net via TCP with ESMTP id ABC12345 for ; 21 Nov 1997 10:05:43 -0600 Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 To: Mary Smith >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = ['Message-ID', 'From', 'Subject'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e From: John Doe Subject: Saying Hello Message-ID: <1234@local.node.example> >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = ['Date'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e Date: Fri, 21 Nov 1997 09:55:06 -0600 >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = [] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> text = """\ ... From: Pete(A nice \) chap) ... To: A Group(Some people) ... :Chris Jones , ... joe@example.org, ... John (my dear friend); (the end of the group) ... Cc: (Empty list)(start)Hidden recipients :(nobody(that I know)) ; ... Date: Thu, ... 13 ... Feb ... 1969 ... 23:32 ... -0330 (Newfoundland Time) ... Message-ID: ... ... Testing. ... """ >>> nfc = 'correu-2.txt' >>> with open(nfc, 'w') as f: r = f.write(text) >>> nff = 'filtrat-2.txt' >>> camps = ['Date', 'From', 'Subject'] >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e From: Pete(A nice \) chap) Date: Thu, 13 Feb 1969 23:32 -0330 (Newfoundland Time) >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> camps = ['Cc', 'Message-ID', 'To'] >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e To: A Group(Some people) :Chris Jones , joe@example.org, John (my dear friend); (the end of the group) Cc: (Empty list)(start)Hidden recipients :(nobody(that I know)) ; Message-ID: >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> text = """\ ... Received: from x.y.test ... Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 ... From: John Doe ... To: Mary Smith ... Subject: Saying Hello ... Date: Fri, 21 Nov 1997 09:55:06 -0600 ... Message-ID: <1234@local.node.example> ... """ >>> nf = 'correu-1.txt' >>> with open(nf, 'w') as f: r = f.write(text) >>> nfc = 'correu-1.txt' >>> camps = ['Received', 'To'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e Received: from x.y.test Received: from node.example by x.y.test; 21 Nov 1997 10:01:22 -0600 To: Mary Smith >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = ['Message-ID', 'From', 'Subject'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e From: John Doe Subject: Saying Hello Message-ID: <1234@local.node.example> >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = ['Date'] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e Date: Fri, 21 Nov 1997 09:55:06 -0600 >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> nfc = 'correu-1.txt' >>> camps = [] >>> nff = 'filtrat-1.txt' >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> text = """\ ... From: Pete(A nice \) chap) ... To: A Group(Some people) ... Cc: (Empty list)(start)Hidden recipients :(nobody(that I know)) ; ... Date: Thu, ... Message-ID: ... """ >>> nfc = 'correu-2.txt' >>> with open(nfc, 'w') as f: r = f.write(text) >>> nff = 'filtrat-2.txt' >>> camps = ['Date', 'From', 'Subject'] >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e From: Pete(A nice \) chap) Date: Thu, >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> camps = ['Cc', 'Message-ID', 'To'] >>> filtra_capcalera(nfc, camps, nff) >>> with open(nff, 'r') as f: print(f.read()) # doctesttag: +NORMALIZE_WHITESPACE +TAG=2_correus_e To: A Group(Some people) Cc: (Empty list)(start)Hidden recipients :(nobody(that I know)) ; Message-ID: >>> try: ... os.remove(nff) ... except FileNotFoundError: ... pass >>> import math >>> from series_trigo import quants_termes >> from series_trigo import n_termes ---- inici >>> eps = 1e-5 >>> a = 0.1 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 353 ---- fi >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-4 >>> a = math.pi - 0.1 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 196 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-6 >>> a = 0.2 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 1425 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-3 >>> a = 0.3 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 18 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-5 >>> a = 1 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 349 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-6 >>> a = 2 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 1328 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-4 >>> a = math.pi/2 + 1e-2 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 154 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps # and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-5 >>> a = 2.5 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 177 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-3 >>> a = math.pi - 1e-3 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 961 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True >>> eps = 1e-2 >>> a = math.pi/4 >>> n = quants_termes(a, eps) >>> n # doctesttag: +TAG=3_series_trigo 25 >> lt = n_termes(a, n) >> limit = (math.pi - 2*a)/4 >> abs(sum(lt) - limit) < eps and abs(sum(lt[:-1]) - limit) >= eps True