Skip to content
Snippets Groups Projects
test_dataset.py 1.83 KiB
Newer Older
Sortofamudkip's avatar
Sortofamudkip committed
"""
This test file tests the Dataset class in Dataset.py.
"""

from Dataset import Dataset
import pandas as pd
from pathlib import Path
import pytest

this_file_dir = Path(__file__).parent


@pytest.fixture
def the_dataset() -> Dataset:
    dataset = Dataset(str(this_file_dir / "../data/GamingStudy_data.csv"))
Sortofamudkip's avatar
Sortofamudkip committed
    return dataset


def test_load_Dataset_class():
    """Tests if the dataset is successfully loaded."""
    dataset = Dataset(str(this_file_dir / "../data/GamingStudy_data.csv"))
Sortofamudkip's avatar
Sortofamudkip committed
    assert type(dataset) == Dataset
    assert type(dataset.dataframe) == pd.DataFrame


def test_get_dataframe(the_dataset: Dataset):
    """Tests Dataset.get_dataframe()."""
Sortofamudkip's avatar
Sortofamudkip committed
    assert type(the_dataset.get_dataframe()) == pd.DataFrame


def test_combined_anxiety_score(the_dataset: Dataset):
    """Tests Dataset.get_combined_anxiety_score()."""
Sortofamudkip's avatar
Sortofamudkip committed
    dataframe = the_dataset.get_dataframe()
    anxiety_scores = the_dataset.get_combined_anxiety_score(dataframe)
    assert anxiety_scores.dtype == float
    assert anxiety_scores.min() >= 0
    assert anxiety_scores.max() <= 1


def test_get_is_narcissist_col(the_dataset: Dataset):
    """Tests Dataset.get_is_narcissist_col()."""
Sortofamudkip's avatar
Sortofamudkip committed
    dataframe = the_dataset.get_dataframe()
    is_narcissist_row = the_dataset.get_is_narcissist_col(dataframe)
    assert is_narcissist_row.dtype == bool


def test_preprocessed_dataframe(the_dataset: Dataset):
    """Tests that the dataframe is preprocessed correctly."""
Sortofamudkip's avatar
Sortofamudkip committed
    dataframe = the_dataset.get_dataframe()
    columns_set = set(dataframe.columns)
    assert "League" not in columns_set
    assert "Anxiety_score" in columns_set
    assert "Is_narcissist" in columns_set


def test_get_sorted_columns(the_dataset: Dataset):
    """Tests Dataset.get_sorted_column()."""
    sorted_GAD1 = the_dataset.get_sorted_column("GAD_T")
Sortofamudkip's avatar
Sortofamudkip committed
    assert sorted_GAD1.iloc[0] <= sorted_GAD1.iloc[-1]