<s> import pytest <EOL> from bepasty . utils . _compat import range_type <EOL> from bepasty . utils . name import ItemName , encode , make_id <EOL> def test_create ( ) : <EOL> fake_storage = { } <EOL> n = ItemName . create ( fake_storage ) <EOL> assert n <EOL> def test_create_many ( ) : <EOL> fake_storage = { } <EOL> length = <NUM_LIT:1> <EOL> count = <NUM_LIT> <EOL> max_seen_length = <NUM_LIT:0> <EOL> for i in range_type ( count ) : <EOL> name = ItemName . create ( fake_storage , length = length , max_length = length * <NUM_LIT:4> , max_tries = <NUM_LIT:10> ) <EOL> fake_storage [ name ] = None <EOL> max_seen_length = max ( max_seen_length , len ( name ) ) <EOL> assert max_seen_length > length <EOL> assert len ( list ( fake_storage ) ) == count <EOL> def test_make_id_type ( ) : <EOL> assert isinstance ( make_id ( <NUM_LIT:2> ) , str ) <EOL> def test_make_id_length ( ) : <EOL> for length in range_type ( <NUM_LIT:10> ) : <EOL> assert len ( make_id ( length ) ) == length <EOL> def test_make_id_alphabet ( ) : <EOL> assert set ( make_id ( <NUM_LIT:10> , alphabet = "<STR_LIT:abc>" ) ) <= set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> def test_make_id_unique ( ) : <EOL> length , count = <NUM_LIT:6> , <NUM_LIT> <EOL> ids = set ( make_id ( length ) for i in range_type ( count ) ) <EOL> assert len ( ids ) == count <EOL> def test_encode_length ( ) : <EOL> length = <NUM_LIT> <EOL> assert len ( encode ( <NUM_LIT> , length ) ) == length <EOL> def test_encode_binary ( ) : <EOL> assert encode ( <NUM_LIT:0> , <NUM_LIT:0> , "<STR_LIT>" ) == [ ] <EOL> assert encode ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) == [ ] <EOL> assert encode ( <NUM_LIT:0> , <NUM_LIT:1> , "<STR_LIT>" ) == [ '<STR_LIT:0>' ] <EOL> assert encode ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT>" ) == [ '<STR_LIT:1>' ] <EOL> assert encode ( <NUM_LIT:0> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:0>' , '<STR_LIT:0>' ] <EOL> assert encode ( <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:0>' , '<STR_LIT:1>' ] <EOL> assert encode ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:1>' , '<STR_LIT:0>' ] <EOL> assert encode ( <NUM_LIT:3> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:1>' , '<STR_LIT:1>' ] <EOL> assert encode ( <NUM_LIT:4> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:0>' , '<STR_LIT:0>' ] <EOL> def test_encode_special ( ) : <EOL> assert encode ( <NUM_LIT:0> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:.>' , '<STR_LIT:.>' ] <EOL> assert encode ( <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:.>' , '<STR_LIT:+>' ] <EOL> assert encode ( <NUM_LIT:2> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:+>' , '<STR_LIT:.>' ] <EOL> assert encode ( <NUM_LIT:3> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:+>' , '<STR_LIT:+>' ] <EOL> def test_encode_decimal ( ) : <EOL> assert encode ( <NUM_LIT> , <NUM_LIT:3> , "<STR_LIT>" ) == [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ] <EOL> assert encode ( <NUM_LIT> , <NUM_LIT:4> , "<STR_LIT>" ) == [ '<STR_LIT:0>' , '<STR_LIT:4>' , '<STR_LIT:5>' , '<STR_LIT>' ] <EOL> assert encode ( <NUM_LIT> , <NUM_LIT:3> , "<STR_LIT>" ) == [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:0>' ] <EOL> def test_encode_hex ( ) : <EOL> assert encode ( <NUM_LIT> , <NUM_LIT:2> , "<STR_LIT>" ) == [ '<STR_LIT:1>' , '<STR_LIT:F>' ] <EOL> def test_encode_errors ( ) : <EOL> with pytest . raises ( ValueError ) : <EOL> encode ( <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:0>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> encode ( <NUM_LIT:1> , - <NUM_LIT:1> , "<STR_LIT:0>" ) <EOL> with pytest . raises ( ValueError ) : <EOL> encode ( - <NUM_LIT:1> , <NUM_LIT:1> , "<STR_LIT:0>" ) </s>
