1
0
Fork 0
forked from itec/banana
banana/tests/test_banana.py

94 lines
2 KiB
Python
Raw Normal View History

2020-09-25 12:55:05 +02:00
#!/usr/bin/env python
"""Tests for `banana` package."""
2020-10-01 20:21:38 +02:00
import pytest
2020-09-25 12:55:05 +02:00
2020-10-01 20:21:38 +02:00
from banana import (avocado2dec, banana2dec, dec2avocado, dec2banana,
dec2ribes, ribes2dec)
2020-09-25 12:55:05 +02:00
2020-10-01 20:06:03 +02:00
banana_conversions = {
2020-10-01 19:53:19 +02:00
"ba": 0,
"baba": 0,
"be": 1,
"beba": 70,
"zu": 69,
"bezu": 139,
"nana": 2485,
"banana": 2485,
}
2020-09-25 12:55:05 +02:00
2020-10-01 20:21:38 +02:00
avocado_conversions = {
2020-10-01 20:06:03 +02:00
"a": 0,
"aca": 5,
"ada": 10,
"afa": 15,
"aga": 20,
"ala": 25,
"ama": 30,
"ana": 35,
"apa": 40,
"ara": 45,
"asa": 50,
"ata": 55,
"ava": 60,
"aza": 65,
"eba": 70,
"eca": 75,
"eda": 80,
"efa": 85,
"ega": 90,
}
2020-10-01 20:21:38 +02:00
ribes_conversions = {"b": 0, "c": 1, "z": 13, "beb": 14, "bec": 15}
@pytest.fixture(params=ribes_conversions.items())
def ribes_known(request):
yield request.param
2020-10-01 19:53:19 +02:00
def test_banana_to_dec_known():
2020-10-01 20:06:03 +02:00
for word, value in banana_conversions.items():
2020-10-01 19:53:19 +02:00
assert banana2dec(word) == value
def test_banana2dec_prefix_ba():
"""un ba all'inizio non cambia nulla!"""
2020-10-01 20:06:03 +02:00
for word in banana_conversions:
2020-10-01 19:53:19 +02:00
value = banana2dec(word)
for prefix in ("ba", "baba", "bababa"):
assert banana2dec(prefix + word) == value
def test_dec_to_banana_known():
2020-10-01 20:06:03 +02:00
for word, value in banana_conversions.items():
2020-10-01 19:53:19 +02:00
if word.startswith("ba"):
continue
assert dec2banana(value) == word
2020-09-25 12:55:05 +02:00
2020-10-01 20:21:38 +02:00
def test_ribes_to_dec_known(ribes_known):
word, value = ribes_known
assert ribes2dec(word) == value
2020-10-01 20:06:03 +02:00
def test_dec_to_ribes_known():
for word, value in ribes_conversions.items():
assert dec2ribes(value) == word
2020-10-01 20:21:38 +02:00
def test_avocado_to_dec_known():
for word, value in avocado_conversions.items():
assert avocado2dec(word) == value
def test_dec_to_avocado_known():
for word, value in avocado_conversions.items():
assert dec2avocado(value) == word
2020-09-25 12:55:05 +02:00
def test_answer_to_life_the_universe_and_everything():
2020-10-01 19:53:19 +02:00
banana = banana2dec("banana")
2020-09-25 12:55:05 +02:00
assert banana != 42
assert banana == 2485