banana/tests/test_banana.py

65 lines
1.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-03 16:43:27 +02:00
import random
2020-10-01 20:21:38 +02:00
import pytest
2020-09-25 12:55:05 +02:00
2020-12-19 23:58:44 +01:00
from banana import BananaCodec
banana_conversions = {
"be": 1,
"da": 10,
"bema" : 100,
"duga": 1000,
"bibiva": 10000,
"galopa": 100000,
"bivucasa": 1000000,
"beba": 70,
"zu": 69,
"bezu": 139,
"nana": 2485,
}
2020-10-01 20:29:27 +02:00
@pytest.fixture(params=banana_conversions.items())
def banana_known(request):
yield request.param
2020-09-25 12:55:05 +02:00
2020-10-02 11:10:33 +02:00
banana_codec = BananaCodec()
2020-10-01 20:32:26 +02:00
2020-10-01 20:29:27 +02:00
def test_banana_to_dec_known(banana_known):
word, value = banana_known
2020-10-02 11:10:33 +02:00
assert banana_codec.decode(word) == value
2020-10-01 19:53:19 +02:00
2020-10-01 20:29:27 +02:00
def test_dec_to_banana_known(banana_known):
word, value = banana_known
2020-10-02 11:10:33 +02:00
assert banana_codec.encode(value) == word
2020-10-01 19:53:19 +02:00
2020-10-02 10:46:51 +02:00
def test_banana_is_banana(banana_known):
2020-10-02 11:10:33 +02:00
assert banana_codec.is_valid(banana_known[0])
2020-10-02 10:46:51 +02:00
2020-10-01 20:29:27 +02:00
def test_banana2dec_prefix_ba(banana_known):
"""un ba all'inizio non cambia nulla!"""
word, value = banana_known
for prefix in ("ba", "baba", "bababa"):
2020-10-02 11:10:33 +02:00
assert banana_codec.decode(prefix + word) == value
2020-09-25 12:55:05 +02:00
def test_answer_to_life_the_universe_and_everything():
2020-10-02 11:10:33 +02:00
banana = banana_codec.decode("banana")
2020-09-25 12:55:05 +02:00
assert banana != 42
assert banana == 2485
2020-10-03 16:43:27 +02:00
def test_random_len_0():
assert banana_codec.random(minlength=0) == ""
2020-12-19 23:58:44 +01:00