def test_pop():
    # Check if the length of the dataframe is as expected
    assert len(generate_virtual_pop(100, "Height", np.random.normal, 0,
                                    1)) == 100
    assert len(generate_virtual_pop(200, "Height", np.random.poisson,
                                    10)) == 200
    assert len(generate_virtual_pop(50, "Height", np.random.gamma, 2, 2)) == 50
def test_draw_samples():
    """
    This function tests the draw_samples function.
    Returns:
    --------
    None
        All tests should pass and no asserts or errors should be raised.
    """

    # Create helper data
    pop = generate_virtual_pop(10, "Height", np.random.normal, 0, 1)
    pop1 = generate_virtual_pop(100000, "Height", np.random.exponential, 0)
    pop2 = generate_virtual_pop(100, "Height", np.random.normal, 0, 1)
    pop3 = generate_virtual_pop(10, "Height", np.random.poisson, 0)
    pop4 = generate_virtual_pop(100, 42, np.random.normal, 0, 1)

    # Check that column names are as expected
    assert (all(
        draw_samples(pop1, 1, [1]).columns.values == (
            ["replicate", "Height", "size", "rep_size"])))
    # Check that data frame has correct row and column length
    assert (len(draw_samples(pop2, 2, [2, 3, 4])) == 18)
    assert (len(draw_samples(pop3, 2, [2, 3]).columns) == 4)

    # Check that non valid data frame will raise TypeError
    with raises(TypeError, match="Population input is not a valid data frame"):
        draw_samples(np.array([1, 2, 3]), 1, [2, 3])

    # Check that if pop input is not string TypeError will be raised
    with raises(TypeError,
                match="Population input name "
                "is not a valid string"):
        draw_samples(pop4, 2, [5, 10, 15, 20])

    # Check that if rep input is non-integer TypeError is raised
    with raises(TypeError,
                match="Number of replications "
                "input must be an integer value"):
        draw_samples(pop, 1.5, [2, 3])

    # Check that if rep input is 0 or less ValueError is raised
    with raises(ValueError,
                match="Number of replications "
                "must be greater than 0"):
        draw_samples(pop, 0, [2, 3])

    # Check if not all sample array values are integers raise TypeError
    with raises(TypeError,
                match="At least one value in sample "
                "size array is not an integer value"):
        draw_samples(pop, 3, [2, 3, 4.5])
def test_not_func():
    # Check if the not exist function will give a AttributeError
    with pytest.raises(AttributeError):
        generate_virtual_pop(100, "Height", np.random.nomal, 0, 1)
    with pytest.raises(AttributeError):
        generate_virtual_pop(100, "Height", np.random.norma, 0, 1)
    with pytest.raises(AttributeError):
        generate_virtual_pop(200, "Height", np.random.ormal, 0, 1)
def test_neg_size():
    # Check if the negative size will give a ValueError
    with pytest.raises(ValueError):
        generate_virtual_pop(-100, "Height", np.random.normal, 0, 1)
    with pytest.raises(ValueError):
        generate_virtual_pop(-10, "Height", np.random.normal, 0, 1)
    with pytest.raises(ValueError):
        generate_virtual_pop(-1, "Height", np.random.normal, 0, 1)
def test_not_int():
    # Check if the float number size will give a ValueError
    with pytest.raises(TypeError,
                       match='Size of population must be a positive integer'):
        generate_virtual_pop(10.5, "Height", np.random.normal, 0, 1)
    with pytest.raises(TypeError,
                       match='Size of population must be a positive integer'):
        generate_virtual_pop(100.5, "Height", np.random.normal, 0, 1)
    with pytest.raises(TypeError,
                       match='Size of population must be a positive integer'):
        generate_virtual_pop(20.5, "Height", np.random.normal, 0, 1)
def test_not_right_number():
    # Check if the incorrect number of parameters will give a TypeError
    with pytest.raises(TypeError,
                       match='Please enter a valid distribution '
                       'function with correct number of parameters for '
                       'the distribution function'):
        generate_virtual_pop(100, "Height", np.random.normal, 0, 1, 2)
    with pytest.raises(TypeError,
                       match='Please enter a valid distribution '
                       'function with correct number of parameters for '
                       'the distribution function'):
        generate_virtual_pop(200, "Height", np.random.poisson, 10, 10)
    with pytest.raises(TypeError,
                       match='Please enter a valid distribution '
                       'function with correct number of parameters for '
                       'the distribution function'):
        generate_virtual_pop(50, "Height", np.random.gamma, 2, 2, 3)
import numpy as np
from samplingsimulatorpy.generate_virtual_pop import generate_virtual_pop
from samplingsimulatorpy.draw_samples import draw_samples
from samplingsimulatorpy.stat_summary import stat_summary
import pytest
import pandas as pd

# Get the helper data
pop1 = generate_virtual_pop(100, "Height", np.random.normal, 0, 1)
pop2 = generate_virtual_pop(10, "Height", np.random.poisson, 0)
samples1 = draw_samples(pop1, 2, [2, 3, 4])
samples2 = draw_samples(pop2, 2, [2, 3])


def test_pop():
    # Test if empty dataframes will get a TypeError
    with pytest.raises(TypeError,
                       match="Population input is not a valid data frame"):
        stat_summary([], [], [np.mean, np.std])
    # Test if a empty dataframe will get a TypeError
    with pytest.raises(TypeError,
                       match="Samples input is not a valid data frame"):
        stat_summary(pop1, [], [np.mean, np.std])
    # Test if not a wrong function will get a TypeError
    with pytest.raises(TypeError, match="Parameter input is not a valid list"):
        stat_summary(pop1, samples1, 'np.mean')


def test_value():
    # Test if the output of the dataframe is as expected
    assert (len(stat_summary(pop1, samples1, [np.mean, np.std])) == 2)