Files
pynkode/test/test_user_interface.py
2024-07-19 10:39:05 -05:00

38 lines
1.5 KiB
Python

import pytest
from src.user_interface import UserInterface
from src.models import KeypadSize
@pytest.fixture()
def user_interface():
return UserInterface.new(keypad_size=KeypadSize(attrs_per_key=7, numb_of_keys=10))
def test_dispersion(user_interface):
pre_dispersion_graph = user_interface.attribute_adjacency_graph()
user_interface.disperse_interface()
post_dispersion_graph = user_interface.attribute_adjacency_graph()
for _ in range(10000):
for attr, adj_graph in pre_dispersion_graph.items():
assert (adj_graph.isdisjoint(post_dispersion_graph[attr]))
def test_shuffle_attrs(user_interface):
"""there's no easy way to test this. At some point we'll have to run this code thousands of time to see if we get
expected statistical outcomes like:
- every attribute gets to every key with a uniform distribution
- every attribute is adjacent to every other attribute with uniform distribution
- the order in which the attributes move from key to key is random (i.e. the distance traveled is uniform)
"""
pre_shuffle_interface = user_interface.attr_indices
user_interface.shuffle_interface()
post_shuffle_interface = user_interface.attr_indices
for i in range(1000):
assert (not all(
post_shuffle_interface[idx] == pre_shuffle_interface[idx] for idx in range(len(post_shuffle_interface))
))
assert (not all(
post_shuffle_interface[idx] != pre_shuffle_interface[idx] for idx in range(len(post_shuffle_interface))
))