From 0d0a05e7f51cafd4e026eba9c64623fa87ee0781 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 1 Oct 2020 20:32:26 +0200 Subject: [PATCH] add ananas --- banana/bananalib.py | 8 ++++++++ tests/test_banana.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/banana/bananalib.py b/banana/bananalib.py index 13297e4..d3967f5 100644 --- a/banana/bananalib.py +++ b/banana/bananalib.py @@ -66,6 +66,14 @@ def dec2avocado(word): return encoder(word, 1, 1) +def ananas2dec(word): + return decoder(word, 1, 0) + + +def dec2ananas(word): + return encoder(word, 1, 0) + + def bananarandom(dictstart=0, shiftend=0, minlength=6, dictionary=None): import random diff --git a/tests/test_banana.py b/tests/test_banana.py index 30c70f2..c78f30c 100644 --- a/tests/test_banana.py +++ b/tests/test_banana.py @@ -3,8 +3,8 @@ """Tests for `banana` package.""" import pytest -from banana import (avocado2dec, banana2dec, dec2avocado, dec2banana, - dec2ribes, ribes2dec) +from banana import (ananas2dec, avocado2dec, banana2dec, dec2ananas, + dec2avocado, dec2banana, dec2ribes, ribes2dec) banana_conversions = {"be": 1, "beba": 70, "zu": 69, "bezu": 139, "nana": 2485} @@ -50,6 +50,34 @@ def ribes_known(request): yield request.param +ananas_conversions = { + "ac": 1, + "al": 5, + "as": 10, + "ec": 15, + "em": 20, + "et": 25, + "id": 30, + "in": 35, + "iv": 40, + "of": 45, + "op": 50, + "oz": 55, + "ug": 60, + "ur": 65, + "acab": 70, + "acal": 75, + "acas": 80, + "acec": 85, + "acem": 90, +} + + +@pytest.fixture(params=ananas_conversions.items()) +def ananas_known(request): + yield request.param + + def test_banana_to_dec_known(banana_known): word, value = banana_known assert banana2dec(word) == value @@ -87,6 +115,16 @@ def test_dec_to_avocado_known(avocado_known): assert dec2avocado(value) == word +def test_ananas_to_dec_known(ananas_known): + word, value = ananas_known + assert ananas2dec(word) == value + + +def test_dec_to_ananas_known(ananas_known): + word, value = ananas_known + assert dec2ananas(value) == word + + def test_answer_to_life_the_universe_and_everything(): banana = banana2dec("banana") assert banana != 42