-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for character code decoding and sheets
- Loading branch information
1 parent
2ee93bf
commit c61687f
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Tests for the newstyle character code decoder.""" | ||
import base64 | ||
import gzip | ||
import json | ||
|
||
import pytest | ||
|
||
from bot.helpers.qud_decode import Character | ||
|
||
# Test cases are lists in this format: | ||
# [ | ||
# build code, | ||
# [expected attributes in game order], | ||
# [expected bonuses in game order] | ||
# ] | ||
|
||
# game order is Strength, Agility, Toughness, Intelligence, Willpower, Ego | ||
|
||
CASES = [ | ||
[ | ||
"H4sIAAAAAAAAA81WXW/aMBR9r9T/YEV7DIgiNnWVeGDpNra1EmtoO2nqg5PcJV4d2/LHKob477MNhSSsg05qBBIKvud+HO49ufL8+AihIMcl/AKpCGfBGQr63V633xt0X58GoccTQ2hWcTixDr0VVvLMUFDW/N2dEZovH2toOhPggr5dXXSjAkucapDvXEbV/Woy9/0IjGvrdukDQjRSCsqEzjpRbANEiG6WtYcbZiGKDNVGwpCB0RLTEE1MQkn6BWZTfg9syAylS46eTIY1tjTW7KzplX4utXObZIvepojN+ejv0l4ajTVkaGxKzGpeW718xBbLH4vwv3sZm+RAW1ljtruTK3eXNE4LTrFsq4V+bja3OsAmNrjtbmMpbMZe1aKAQupzbF7a5WdePaCVgFdNjgpSgsTV3N4n4oZp63DSBG6wJNhDvSqyCPetOOb8XqEfXKIPALrFwtMH3hkDziBrs6gkgkLnJydMt1r4nFudQqc0KqWtFr5mSmNbGrmdWcKTlfv7Vt4c7lraFCOtJUmMhkNcFU1yu3fFxIlPTYxMC6ysFs7q8wtGOaFEz6z9bW0mwfucW+Obuv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7u8t/gCu1vr52wsAAA==", # noqa E501 | ||
[17, 17, 18, 16, 16, 19], # attributes | ||
[0, 0, 0, 0, 2, 0], # bonuses | ||
], | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("test_input,expected_attrs,_", CASES) | ||
def test_decode_attributes(test_input, expected_attrs, _): | ||
"""Check the decoded attributes against the expected attributes.""" | ||
decode = base64.b64decode(test_input) | ||
unzip = gzip.decompress(decode).decode(encoding='utf-8') | ||
code = json.loads(unzip) | ||
char = Character(code) | ||
assert char.attributes == expected_attrs | ||
|
||
|
||
@pytest.mark.parametrize("test_input,_,expected_bonuses", CASES) | ||
def test_decode_bonuses(test_input, _, expected_bonuses): | ||
"""Check the decoded bonuses against the expected bonuses.""" | ||
decode = base64.b64decode(test_input) | ||
unzip = gzip.decompress(decode).decode(encoding='utf-8') | ||
code = json.loads(unzip) | ||
char = Character(code) | ||
assert char.bonuses == expected_bonuses | ||
|
||
|
||
@pytest.mark.parametrize("test_input,_,__", CASES) | ||
def test_decode_make_sheet(test_input, _, __): | ||
"""Check that a text sheet can be rendered from each character code.""" | ||
decode = base64.b64decode(test_input) | ||
unzip = gzip.decompress(decode).decode(encoding='utf-8') | ||
code = json.loads(unzip) | ||
char = Character(code) | ||
sheet = char.make_sheet() | ||
assert len(sheet) > 100 |