2019-12-08 22:43:49 +01:00
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
import struct
|
|
|
|
import unittest
|
|
|
|
import random
|
|
|
|
from unittest.mock import Mock
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from bemani.backend.iidx.pendual import IIDXPendual
|
|
|
|
from bemani.data import Score
|
|
|
|
|
|
|
|
|
|
|
|
class TestIIDXPendual(unittest.TestCase):
|
|
|
|
def __make_score(self, ghost: List[int]) -> Score:
|
|
|
|
return Score(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
sum(ghost),
|
|
|
|
1234567890,
|
|
|
|
1234567890,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
{
|
2022-10-15 20:56:30 +02:00
|
|
|
"ghost": bytes(ghost),
|
2019-12-08 22:43:49 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_average_no_scores(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
base = IIDXPendual(Mock(), Mock(), Mock())
|
2019-12-08 22:43:49 +01:00
|
|
|
self.assertEqual(
|
|
|
|
base.delta_score([], 3),
|
|
|
|
(None, None),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_average_identity(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
base = IIDXPendual(Mock(), Mock(), Mock())
|
2019-12-08 22:43:49 +01:00
|
|
|
self.assertEqual(
|
2022-10-15 20:56:30 +02:00
|
|
|
base.delta_score(
|
|
|
|
[
|
|
|
|
self.__make_score([10, 20, 30]),
|
|
|
|
],
|
|
|
|
3,
|
|
|
|
),
|
|
|
|
(60, struct.pack("bbb", *[-10, 0, 10])),
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_average_basic(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
base = IIDXPendual(Mock(), Mock(), Mock())
|
2019-12-08 22:43:49 +01:00
|
|
|
self.assertEqual(
|
2022-10-15 20:56:30 +02:00
|
|
|
base.delta_score(
|
|
|
|
[
|
|
|
|
self.__make_score([10, 20, 30]),
|
|
|
|
self.__make_score([0, 0, 0]),
|
|
|
|
],
|
|
|
|
3,
|
|
|
|
),
|
|
|
|
(30, struct.pack("bbb", *[-5, 0, 5])),
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_average_complex(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
base = IIDXPendual(Mock(), Mock(), Mock())
|
2019-12-08 22:43:49 +01:00
|
|
|
self.assertEqual(
|
2022-10-15 20:56:30 +02:00
|
|
|
base.delta_score(
|
|
|
|
[
|
|
|
|
self.__make_score([10, 20, 30]),
|
|
|
|
self.__make_score([20, 30, 40]),
|
|
|
|
self.__make_score([30, 40, 50]),
|
|
|
|
],
|
|
|
|
3,
|
|
|
|
),
|
|
|
|
(90, struct.pack("bbb", *[-10, 0, 10])),
|
2019-12-08 22:43:49 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_average_always_zero(self) -> None:
|
2021-08-20 06:43:59 +02:00
|
|
|
base = IIDXPendual(Mock(), Mock(), Mock())
|
2022-10-15 20:56:30 +02:00
|
|
|
ex_score, ghost = base.delta_score(
|
|
|
|
[
|
|
|
|
self.__make_score([random.randint(0, 10) for _ in range(64)]),
|
|
|
|
self.__make_score([random.randint(0, 10) for _ in range(64)]),
|
|
|
|
],
|
|
|
|
64,
|
|
|
|
)
|
|
|
|
self.assertEqual(sum(struct.unpack("b" * 64, ghost)), 0)
|