mirror of
https://github.com/283375/arcaea-offline.git
synced 2025-04-07 00:20:17 +00:00
test: add tests
This commit is contained in:
parent
14f4cef426
commit
b14c3e82b4
2
.sourcery.yaml
Normal file
2
.sourcery.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
rule_settings:
|
||||
python_version: '3.8'
|
@ -2,3 +2,5 @@ black==23.3.0
|
||||
isort==5.12.0
|
||||
pre-commit==3.3.1
|
||||
pylint==3.0.2
|
||||
pytest==7.4.3
|
||||
tox==4.11.3
|
||||
|
22
tests/calculate/test_world_step.py
Normal file
22
tests/calculate/test_world_step.py
Normal file
@ -0,0 +1,22 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from arcaea_offline.calculate.world_step import (
|
||||
AwakenedAyuPartnerBonus,
|
||||
LegacyMapStepBooster,
|
||||
PlayResult,
|
||||
calculate_step_original,
|
||||
)
|
||||
|
||||
|
||||
def test_world_step():
|
||||
# the result was copied from https://arcaea.fandom.com/wiki/World_Mode_Mechanics#Calculation
|
||||
# CC BY-SA 3.0
|
||||
|
||||
booster = LegacyMapStepBooster(6, 250)
|
||||
partner_bonus = AwakenedAyuPartnerBonus("+3.6")
|
||||
play_result = PlayResult(play_rating=Decimal("11.299"), partner_step=92)
|
||||
result = calculate_step_original(
|
||||
play_result, partner_bonus=partner_bonus, step_booster=booster
|
||||
)
|
||||
|
||||
assert result.quantize(Decimal("0.000")) == Decimal("175.149")
|
0
tests/db/__init__.py
Normal file
0
tests/db/__init__.py
Normal file
5
tests/db/db.py
Normal file
5
tests/db/db.py
Normal file
@ -0,0 +1,5 @@
|
||||
from sqlalchemy import Engine, create_engine, inspect
|
||||
|
||||
|
||||
def create_engine_in_memory():
|
||||
return create_engine("sqlite:///:memory:")
|
0
tests/db/models/__init__.py
Normal file
0
tests/db/models/__init__.py
Normal file
118
tests/db/models/test_songs.py
Normal file
118
tests/db/models/test_songs.py
Normal file
@ -0,0 +1,118 @@
|
||||
from sqlalchemy import Engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from arcaea_offline.models.songs import (
|
||||
Chart,
|
||||
ChartInfo,
|
||||
Difficulty,
|
||||
Pack,
|
||||
Song,
|
||||
SongsBase,
|
||||
SongsViewBase,
|
||||
)
|
||||
|
||||
from ..db import create_engine_in_memory
|
||||
|
||||
|
||||
def _song(**kw):
|
||||
defaults = {"artist": "test"}
|
||||
defaults.update(kw)
|
||||
return Song(**defaults)
|
||||
|
||||
|
||||
def _difficulty(**kw):
|
||||
defaults = {"rating_plus": False, "audio_override": False, "jacket_override": False}
|
||||
defaults.update(kw)
|
||||
return Difficulty(**defaults)
|
||||
|
||||
|
||||
class Test_Chart:
|
||||
def init_db(self, engine: Engine):
|
||||
SongsBase.metadata.create_all(engine)
|
||||
SongsViewBase.metadata.create_all(engine)
|
||||
|
||||
def db(self):
|
||||
db = create_engine_in_memory()
|
||||
self.init_db(db)
|
||||
return db
|
||||
|
||||
def test_chart_info(self):
|
||||
pre_entites = [
|
||||
Pack(id="test", name="Test Pack"),
|
||||
_song(idx=0, id="song0", set="test", title="Full Chart Info"),
|
||||
_song(idx=1, id="song1", set="test", title="Partial Chart Info"),
|
||||
_song(idx=2, id="song2", set="test", title="No Chart Info"),
|
||||
_difficulty(song_id="song0", rating_class=2, rating=9),
|
||||
_difficulty(song_id="song1", rating_class=2, rating=9),
|
||||
_difficulty(song_id="song2", rating_class=2, rating=9),
|
||||
ChartInfo(song_id="song0", rating_class=2, constant=90, notes=1234),
|
||||
ChartInfo(song_id="song1", rating_class=2, constant=90),
|
||||
]
|
||||
|
||||
db = self.db()
|
||||
with Session(db) as session:
|
||||
session.add_all(pre_entites)
|
||||
session.commit()
|
||||
|
||||
chart_song0_ratingclass2 = (
|
||||
session.query(Chart)
|
||||
.where((Chart.song_id == "song0") & (Chart.rating_class == 2))
|
||||
.one()
|
||||
)
|
||||
|
||||
assert chart_song0_ratingclass2.constant == 90
|
||||
assert chart_song0_ratingclass2.notes == 1234
|
||||
|
||||
chart_song1_ratingclass2 = (
|
||||
session.query(Chart)
|
||||
.where((Chart.song_id == "song1") & (Chart.rating_class == 2))
|
||||
.one()
|
||||
)
|
||||
|
||||
assert chart_song1_ratingclass2.constant == 90
|
||||
assert chart_song1_ratingclass2.notes is None
|
||||
|
||||
chart_song2_ratingclass2 = (
|
||||
session.query(Chart)
|
||||
.where((Chart.song_id == "song2") & (Chart.rating_class == 2))
|
||||
.first()
|
||||
)
|
||||
|
||||
assert chart_song2_ratingclass2 is None
|
||||
|
||||
def test_difficulty_title_override(self):
|
||||
pre_entites = [
|
||||
Pack(id="test", name="Test Pack"),
|
||||
_song(idx=0, id="test", set="test", title="Test"),
|
||||
_difficulty(song_id="test", rating_class=0, rating=2),
|
||||
_difficulty(song_id="test", rating_class=1, rating=5),
|
||||
_difficulty(song_id="test", rating_class=2, rating=8),
|
||||
_difficulty(
|
||||
song_id="test", rating_class=3, rating=10, title="TEST ~REVIVE~"
|
||||
),
|
||||
ChartInfo(song_id="test", rating_class=0, constant=10),
|
||||
ChartInfo(song_id="test", rating_class=1, constant=10),
|
||||
ChartInfo(song_id="test", rating_class=2, constant=10),
|
||||
ChartInfo(song_id="test", rating_class=3, constant=10),
|
||||
]
|
||||
|
||||
db = self.db()
|
||||
with Session(db) as session:
|
||||
session.add_all(pre_entites)
|
||||
session.commit()
|
||||
|
||||
charts_original_title = (
|
||||
session.query(Chart)
|
||||
.where((Chart.song_id == "test") & (Chart.rating_class in [0, 1, 2]))
|
||||
.all()
|
||||
)
|
||||
|
||||
assert all(chart.title == "Test" for chart in charts_original_title)
|
||||
|
||||
chart_overrided_title = (
|
||||
session.query(Chart)
|
||||
.where((Chart.song_id == "test") & (Chart.rating_class == 3))
|
||||
.one()
|
||||
)
|
||||
|
||||
assert chart_overrided_title.title == "TEST ~REVIVE~"
|
Loading…
x
Reference in New Issue
Block a user