Files
Neutron/tests/test_gadget_controls.py
T

70 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pathlib import Path
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT/'tools/binary'))
from gadget_controls import (collect, tab_action, hit_gadgets, practice_toggle,
default_device_selection, TILES)
class GadgetControlTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.report = collect(ROOT.parent/'Original')
def test_source_identity_spans_and_virtual_targets(self):
self.assertEqual(len(self.report['bodies']), 9)
self.assertEqual(len(self.report['sites']), 40)
self.assertEqual(len(self.report['vtables']), 10)
sites = {s['name']: s for s in self.report['sites']}
self.assertEqual(sites['tab_byte']['bytes'], 'a041985000')
self.assertEqual(sites['space_byte']['bytes'], 'a058985000')
self.assertEqual(sites['unequip_global']['file_offset'], '0x25ac2')
def test_tab_distinguishes_close_unequip_and_open_and_held_edge(self):
self.assertEqual(tab_action(True, -1), 'close')
self.assertEqual(tab_action(False, 5), 'unequip')
self.assertEqual(tab_action(False, -1), 'open_gadgets')
for opened in (True, False):
self.assertEqual(tab_action(opened, -1, latched=True), 'none')
def test_exact_tile_layout_and_strict_boundaries(self):
self.assertEqual(TILES[3], (157, 327))
for item, (x, y) in enumerate(TILES):
self.assertEqual(hit_gadgets([1]*8, x+70, y+70), item)
for a, b in ((x, y+70), (x+141, y+70), (x+70, y), (x+70, y+141)):
self.assertIsNone(hit_gadgets([1]*8, a, b))
def test_hit_filter_is_raw_state_not_owned_boolean(self):
x, y = TILES[3]
for state in (0, 4):
self.assertIsNone(hit_gadgets([state]*8, x+70, y+70))
for state in (1, 2, 3, -1):
self.assertEqual(hit_gadgets([state]*8, x+70, y+70), 3)
def test_display_highlight_three_is_not_equipped_mode_three(self):
table = self.report['selection_table']
self.assertEqual(table[0], table[4]) # Requested−1 and3 share branch428DE0.
state = default_device_selection(3)
self.assertEqual((state['highlight'], state['equipped_mode']), (3, -1))
self.assertIsNone(state['practice_level'])
def test_practice_toggles_only_outside_tutorial_and_before_scene500(self):
self.assertEqual(practice_toggle(3, 'LV1B', 60), 2)
self.assertEqual(practice_toggle(2, 'LV1B', 60), 3)
self.assertEqual(practice_toggle(3, 'LV1B', 500), 3)
for i in range(1, 9):
self.assertEqual(practice_toggle(3, f'VR0{i}', 60), 3)
state = default_device_selection(2)
self.assertEqual((state['practice_level'], state['practice_state']), ('VR04', 1))
def test_practice_destination_calls_match_all_eight_item_indices(self):
self.assertEqual([p['level'] for p in self.report['practice']], [f'vr0{i}.gam' for i in range(1,9)])
sites = {s['name']: s for s in self.report['sites']}
self.assertEqual(sites['initial_practice_return_state1']['bytes'], '6a016a0953e8f814feff6a016a0a53e8ee14feff')
if __name__ == '__main__':
unittest.main()