testa meglio
This commit is contained in:
parent
ce80fe857d
commit
dd73232769
2 changed files with 75 additions and 51 deletions
|
@ -1,8 +1,9 @@
|
|||
"""Console script for banana."""
|
||||
import argparse
|
||||
from . import bananalib as banana
|
||||
import sys
|
||||
|
||||
from . import bananalib as banana
|
||||
|
||||
|
||||
def ananas2dec():
|
||||
parser = argparse.ArgumentParser(description="Convert ananas string to dec")
|
||||
|
@ -23,12 +24,16 @@ def avocado2dec():
|
|||
def banana2dec():
|
||||
parser = argparse.ArgumentParser(description="Convert banana string to dec")
|
||||
parser.add_argument("banana", help="String to be converted")
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||
parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0)
|
||||
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0)
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs="+")
|
||||
parser.add_argument(
|
||||
"--dictstart", help="Set starting dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shiftend", help="Set shift for ending dictionary", type=int, default=0
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(banana.banana2dec(args.banana, args.dictstart, args.shiftend, args.dictionary))
|
||||
print(banana.banana2dec(args.banana))
|
||||
|
||||
|
||||
def ribes2dec():
|
||||
|
@ -41,13 +46,21 @@ def ribes2dec():
|
|||
|
||||
def bananarandom():
|
||||
parser = argparse.ArgumentParser(description="Generate random banana")
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||
parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0)
|
||||
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0)
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs="+")
|
||||
parser.add_argument(
|
||||
"--dictstart", help="Set starting dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shiftend", help="Set shift for ending dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument("--minlength", help="Set minimum length", type=int, default=6)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(banana.bananarandom(args.dictstart, args.shiftend, args.minlength, args.dictionary))
|
||||
print(
|
||||
banana.bananarandom(
|
||||
args.dictstart, args.shiftend, args.minlength, args.dictionary
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def dec2ananas():
|
||||
|
@ -71,13 +84,21 @@ def dec2avocado():
|
|||
def dec2banana():
|
||||
parser = argparse.ArgumentParser(description="Convert dec number to banana")
|
||||
parser.add_argument("num", help="Number to be converted", type=int)
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||
parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0)
|
||||
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0)
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs="+")
|
||||
parser.add_argument(
|
||||
"--dictstart", help="Set starting dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shiftend", help="Set shift for ending dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument("--minlength", help="Set minimum length", type=int, default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(banana.dec2banana(args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary))
|
||||
print(
|
||||
banana.dec2banana(
|
||||
args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def dec2ribes():
|
||||
|
@ -92,9 +113,13 @@ def dec2ribes():
|
|||
def isbanana():
|
||||
parser = argparse.ArgumentParser(description="Checks if string is banana")
|
||||
parser.add_argument("banana", help="String to be checked")
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||
parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0)
|
||||
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0)
|
||||
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs="+")
|
||||
parser.add_argument(
|
||||
"--dictstart", help="Set starting dictionary", type=int, default=0
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shiftend", help="Set shift for ending dictionary", type=int, default=0
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(banana.isbanana(args.banana, args.dictstart, args.shiftend, args.dictionary))
|
||||
|
@ -107,4 +132,3 @@ def main():
|
|||
if __name__ == "__main__":
|
||||
# pragma: no cover
|
||||
main()
|
||||
|
||||
|
|
|
@ -6,16 +6,13 @@ import pytest
|
|||
from banana import (avocado2dec, banana2dec, dec2avocado, dec2banana,
|
||||
dec2ribes, ribes2dec)
|
||||
|
||||
banana_conversions = {
|
||||
"ba": 0,
|
||||
"baba": 0,
|
||||
"be": 1,
|
||||
"beba": 70,
|
||||
"zu": 69,
|
||||
"bezu": 139,
|
||||
"nana": 2485,
|
||||
"banana": 2485,
|
||||
}
|
||||
banana_conversions = {"be": 1, "beba": 70, "zu": 69, "bezu": 139, "nana": 2485}
|
||||
|
||||
|
||||
@pytest.fixture(params=banana_conversions.items())
|
||||
def banana_known(request):
|
||||
yield request.param
|
||||
|
||||
|
||||
avocado_conversions = {
|
||||
"a": 0,
|
||||
|
@ -39,6 +36,12 @@ avocado_conversions = {
|
|||
"ega": 90,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(params=avocado_conversions.items())
|
||||
def avocado_known(request):
|
||||
yield request.param
|
||||
|
||||
|
||||
ribes_conversions = {"b": 0, "c": 1, "z": 13, "beb": 14, "bec": 15}
|
||||
|
||||
|
||||
|
@ -47,24 +50,21 @@ def ribes_known(request):
|
|||
yield request.param
|
||||
|
||||
|
||||
def test_banana_to_dec_known():
|
||||
for word, value in banana_conversions.items():
|
||||
assert banana2dec(word) == value
|
||||
def test_banana_to_dec_known(banana_known):
|
||||
word, value = banana_known
|
||||
assert banana2dec(word) == value
|
||||
|
||||
|
||||
def test_banana2dec_prefix_ba():
|
||||
def test_dec_to_banana_known(banana_known):
|
||||
word, value = banana_known
|
||||
assert dec2banana(value) == word
|
||||
|
||||
|
||||
def test_banana2dec_prefix_ba(banana_known):
|
||||
"""un ba all'inizio non cambia nulla!"""
|
||||
for word in banana_conversions:
|
||||
value = banana2dec(word)
|
||||
for prefix in ("ba", "baba", "bababa"):
|
||||
assert banana2dec(prefix + word) == value
|
||||
|
||||
|
||||
def test_dec_to_banana_known():
|
||||
for word, value in banana_conversions.items():
|
||||
if word.startswith("ba"):
|
||||
continue
|
||||
assert dec2banana(value) == word
|
||||
word, value = banana_known
|
||||
for prefix in ("ba", "baba", "bababa"):
|
||||
assert banana2dec(prefix + word) == value
|
||||
|
||||
|
||||
def test_ribes_to_dec_known(ribes_known):
|
||||
|
@ -72,19 +72,19 @@ def test_ribes_to_dec_known(ribes_known):
|
|||
assert ribes2dec(word) == value
|
||||
|
||||
|
||||
def test_dec_to_ribes_known():
|
||||
for word, value in ribes_conversions.items():
|
||||
assert dec2ribes(value) == word
|
||||
def test_dec_to_ribes_known(ribes_known):
|
||||
word, value = ribes_known
|
||||
assert dec2ribes(value) == word
|
||||
|
||||
|
||||
def test_avocado_to_dec_known():
|
||||
for word, value in avocado_conversions.items():
|
||||
assert avocado2dec(word) == value
|
||||
def test_avocado_to_dec_known(avocado_known):
|
||||
word, value = avocado_known
|
||||
assert avocado2dec(word) == value
|
||||
|
||||
|
||||
def test_dec_to_avocado_known():
|
||||
for word, value in avocado_conversions.items():
|
||||
assert dec2avocado(value) == word
|
||||
def test_dec_to_avocado_known(avocado_known):
|
||||
word, value = avocado_known
|
||||
assert dec2avocado(value) == word
|
||||
|
||||
|
||||
def test_answer_to_life_the_universe_and_everything():
|
||||
|
|
Loading…
Reference in a new issue