src.test.test_general_method
1import pandas as pd 2import sys 3import os 4import numpy as np 5sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 6from general_method import run_general_method 7 8def generate_synthetic_dataset(num_users=5, num_values=10): 9 """ 10 Generates a synthetic dataset for testing. 11 12 Args: 13 num_users (int): The number of users to generate in the dataset (default is 5). 14 num_values (int): The number of values per user in the dataset (default is 10). 15 16 Returns: 17 pd.DataFrame: A DataFrame containing the synthetic dataset with user IDs and associated values. 18 19 The dataset contains two columns: 20 - 'user': A list of user IDs in the form 'u1', 'u2', ..., 'un'. 21 - 'values': A list of values assigned to each user, with each user having a list of randomly chosen "AOI" values. 22 """ 23 data = { 24 "user": [f"u{i+1}" for i in range(num_users)], 25 "values": [np.random.choice([f"AOI {str(i+1).zfill(3)}" for i in range(3)], num_values).tolist() for _ in range(num_users)] 26 } 27 return pd.DataFrame(data) 28 29def test_general_method(): 30 """ 31 Tests the general method with a generated synthetic dataset. 32 33 Generates a synthetic dataset and passes it to the `run_general_method` function for processing. 34 """ 35 df = generate_synthetic_dataset() 36 run_general_method(df) 37 38if __name__ == "__main__": 39 test_general_method()
def
generate_synthetic_dataset(num_users=5, num_values=10):
10def generate_synthetic_dataset(num_users=5, num_values=10): 11 """ 12 Generates a synthetic dataset for testing. 13 14 Args: 15 num_users (int): The number of users to generate in the dataset (default is 5). 16 num_values (int): The number of values per user in the dataset (default is 10). 17 18 Returns: 19 pd.DataFrame: A DataFrame containing the synthetic dataset with user IDs and associated values. 20 21 The dataset contains two columns: 22 - 'user': A list of user IDs in the form 'u1', 'u2', ..., 'un'. 23 - 'values': A list of values assigned to each user, with each user having a list of randomly chosen "AOI" values. 24 """ 25 data = { 26 "user": [f"u{i+1}" for i in range(num_users)], 27 "values": [np.random.choice([f"AOI {str(i+1).zfill(3)}" for i in range(3)], num_values).tolist() for _ in range(num_users)] 28 } 29 return pd.DataFrame(data)
Generates a synthetic dataset for testing.
Args: num_users (int): The number of users to generate in the dataset (default is 5). num_values (int): The number of values per user in the dataset (default is 10).
Returns: pd.DataFrame: A DataFrame containing the synthetic dataset with user IDs and associated values.
The dataset contains two columns: - 'user': A list of user IDs in the form 'u1', 'u2', ..., 'un'. - 'values': A list of values assigned to each user, with each user having a list of randomly chosen "AOI" values.
def
test_general_method():
31def test_general_method(): 32 """ 33 Tests the general method with a generated synthetic dataset. 34 35 Generates a synthetic dataset and passes it to the `run_general_method` function for processing. 36 """ 37 df = generate_synthetic_dataset() 38 run_general_method(df)
Tests the general method with a generated synthetic dataset.
Generates a synthetic dataset and passes it to the run_general_method
function for processing.