refactor; remove the term interface
This commit is contained in:
@@ -16,14 +16,14 @@ def test_create_new_user_and_renew_keys(nkode_api, keypad_size, passocode_len):
|
||||
username = "test_username"
|
||||
nkode_policy = NKodePolicy() # default policy
|
||||
customer_id = nkode_api.create_new_customer(keypad_size, nkode_policy)
|
||||
session_id, set_interface = nkode_api.generate_signup_interface(customer_id)
|
||||
user_passcode = set_interface[:passocode_len]
|
||||
session_id, set_keypad = nkode_api.generate_signup_keypad(customer_id)
|
||||
user_passcode = set_keypad[:passocode_len]
|
||||
|
||||
signup_key_selection = lambda interface: [interface.index(attr) // keypad_size.numb_of_keys for attr in user_passcode]
|
||||
set_key_selection = signup_key_selection(set_interface)
|
||||
signup_key_selection = lambda keypad: [keypad.index(attr) // keypad_size.numb_of_keys for attr in user_passcode]
|
||||
set_key_selection = signup_key_selection(set_keypad)
|
||||
|
||||
confirm_interface = nkode_api.set_nkode(username, customer_id, set_key_selection, session_id)
|
||||
confirm_key_selection = signup_key_selection(confirm_interface)
|
||||
confirm_keypad = nkode_api.set_nkode(username, customer_id, set_key_selection, session_id)
|
||||
confirm_key_selection = signup_key_selection(confirm_keypad)
|
||||
successful_confirm = nkode_api.confirm_nkode(
|
||||
username,
|
||||
customer_id,
|
||||
@@ -32,21 +32,21 @@ def test_create_new_user_and_renew_keys(nkode_api, keypad_size, passocode_len):
|
||||
)
|
||||
assert successful_confirm
|
||||
|
||||
sign_in_key_selection = lambda interface: [interface.index(attr) // keypad_size.attrs_per_key for attr in user_passcode]
|
||||
login_interface = nkode_api.get_login_interface(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_interface)
|
||||
sign_in_key_selection = lambda keypad: [keypad.index(attr) // keypad_size.attrs_per_key for attr in user_passcode]
|
||||
login_keypad = nkode_api.get_login_keypad(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_keypad)
|
||||
successful_login = nkode_api.login(customer_id, username, login_key_selection)
|
||||
assert successful_login
|
||||
|
||||
successful_renew = nkode_api.renew_attributes(customer_id)
|
||||
assert successful_renew
|
||||
|
||||
login_interface = nkode_api.get_login_interface(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_interface)
|
||||
login_keypad = nkode_api.get_login_keypad(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_keypad)
|
||||
successful_login = nkode_api.login(customer_id, username, login_key_selection)
|
||||
assert successful_login
|
||||
|
||||
login_interface = nkode_api.get_login_interface(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_interface)
|
||||
login_keypad = nkode_api.get_login_keypad(username, customer_id)
|
||||
login_key_selection = sign_in_key_selection(login_keypad)
|
||||
successful_login = nkode_api.login(customer_id, username, login_key_selection)
|
||||
assert successful_login
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from src.user_interface import UserInterface
|
||||
from src.user_keypad import UserKeypad
|
||||
from src.models import KeypadSize
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from src.models import KeypadSize
|
||||
[KeypadSize(numb_of_keys=10, attrs_per_key=11)]
|
||||
)
|
||||
def test_attr_set_idx(keypad_size):
|
||||
user_interface = UserInterface.create(keypad_size)
|
||||
user_keypad = UserKeypad.create(keypad_size)
|
||||
for attr_idx in range(keypad_size.numb_of_attrs):
|
||||
user_interface_idx = user_interface.interface[attr_idx]
|
||||
user_keypad_idx = user_keypad.keypad[attr_idx]
|
||||
|
||||
assert (attr_idx % keypad_size.attrs_per_key == user_interface_idx % keypad_size.attrs_per_key)
|
||||
assert (attr_idx % keypad_size.attrs_per_key == user_keypad_idx % keypad_size.attrs_per_key)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import pytest
|
||||
from src.user_interface import UserInterface
|
||||
from src.models import KeypadSize
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def user_interface():
|
||||
return UserInterface.create(keypad_size=KeypadSize(attrs_per_key=7, numb_of_keys=10))
|
||||
|
||||
|
||||
def test_dispersion(user_interface):
|
||||
for _ in range(10000):
|
||||
pre_dispersion_graph = user_interface.attribute_adjacency_graph()
|
||||
user_interface.disperse_interface()
|
||||
post_dispersion_graph = user_interface.attribute_adjacency_graph()
|
||||
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.interface
|
||||
user_interface.partial_interface_shuffle()
|
||||
post_shuffle_interface = user_interface.interface
|
||||
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))
|
||||
))
|
||||
35
test/test_user_keypad.py
Normal file
35
test/test_user_keypad.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from src.user_keypad import UserKeypad
|
||||
from src.models import KeypadSize
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def user_keypad():
|
||||
return UserKeypad.create(keypad_size=KeypadSize(attrs_per_key=7, numb_of_keys=10))
|
||||
|
||||
|
||||
def test_dispersion(user_keypad):
|
||||
for _ in range(10000):
|
||||
pre_dispersion_graph = user_keypad.attribute_adjacency_graph()
|
||||
user_keypad.disperse_keypad()
|
||||
post_dispersion_graph = user_keypad.attribute_adjacency_graph()
|
||||
for attr, adj_graph in pre_dispersion_graph.items():
|
||||
assert (adj_graph.isdisjoint(post_dispersion_graph[attr]))
|
||||
|
||||
|
||||
def test_shuffle_attrs(user_keypad):
|
||||
"""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_keypad = user_keypad.keypad
|
||||
user_keypad.partial_keypad_shuffle()
|
||||
post_shuffle_keypad = user_keypad.keypad
|
||||
assert (not all(
|
||||
post_shuffle_keypad[idx] == pre_shuffle_keypad[idx] for idx in range(len(post_shuffle_keypad))
|
||||
))
|
||||
assert (not all(
|
||||
post_shuffle_keypad[idx] != pre_shuffle_keypad[idx] for idx in range(len(post_shuffle_keypad))
|
||||
))
|
||||
Reference in New Issue
Block a user