tests package
tests.Sandbox module
A sandbox script for various experiments, statistical tests, and debugging.
This file serves as a collection of independent code snippets used for development, analysis, and exploratory work. It is not part of the main application logic or the formal test suite.
The contents include:
Statistical analysis scripts to compare beta distributions that model agent preferences, using methods like the KS-test and permutation tests on the Jensen-Shannon distance.
A utility for checking system environment variables for debugging purposes.
- Authors:
Ivan Digel <ivan.digel@uni-kassel.de>
tests.Test module
A script for miscellaneous testing, debugging, and data exploration.
This file serves as a “scratchpad” for developers to run quick, ad-hoc tests, experiments, or data checks. It is not part of the formal, automated test suite and contains several independent functions for different purposes.
These include: - A simple Monte Carlo simulation function. - Functions to test breakdown probabilities using a Weibull distribution. - A utility to perform a detailed, column-by-column comparison of two
simulation output DataFrames.
- Authors:
Ivan Digel <ivan.digel@uni-kassel.de>
- monte_carlo(steps, lists, weights)[source]
Performs a simple Monte Carlo simulation for a discrete choice.
This function simulates a random choice from a list of outcomes a given number of times, where each choice is weighted by a corresponding probability. It then prints the frequency of each outcome.
- Parameters:
- stepsint
The number of simulation trials to run.
- listslist
A list of the possible outcomes to choose from.
- weightslist
A list of probabilities corresponding to the outcomes in lists.
- breakdown_check(age)[source]
Checks for a system breakdown based on a Weibull distribution.
This function simulates whether a component of a certain age fails. The probability of failure is determined by a Weibull distribution with hardcoded scale and shape parameters.
- Parameters:
- ageint or float
The current age of the component to be checked.
- Returns:
- bool
True if a breakdown occurs, False otherwise.
- weibull_trial(trials)[source]
Runs multiple breakdown checks to observe the failure frequency.
This function calls breakdown_check repeatedly for a component of a fixed age to see how many times it fails over a large number of trials.
- Parameters:
- trialsint
The number of breakdown checks to perform.
- compare_runs()[source]
Compares two agent DataFrame pickle files for differences.
This utility function loads two specified agent_df pickle files and performs a deep, column-by-column comparison. It reports which columns are identical and which ones differ. It includes special logic to handle floating-point comparisons within a column of dictionaries. This is useful for debugging and verifying model determinism between runs.
tests.conftest module
tests.test_energy_advisor module
tests.test_houseowner module
Pytest unit tests for the Houseowner agent class.
This file contains a suite of unit tests that cover a wide range of the Houseowner agent’s behaviours and methods. It uses the pytest framework and relies on fixtures defined in conftest.py to provide the necessary agent instances and other objects for testing.
The tests are organised logically to follow the agent’s decision-making process, from evaluating its current situation to gathering information, making choices, and finally installing a new heating system.
- Authors:
Sascha Holzhauer <sascha.holzhauer@uni-kassel.de>
Dmytro Mykhailiuk <dmytromykhailiuk6@gmail.com>
- test_evaluation_of_current_hs_cognitive_resource_depleting(houseowner)[source]
Tests that evaluating the current heating system depletes cognitive resources.
- test_evaluation_of_current_hs_dissatisfied(houseowner)[source]
Tests that the houseowner remains ‘Satisfied’ if their heating system is relatively new.
- test_evaluation_of_current_hs_satisfied(houseowner)[source]
Tests that the houseowner becomes ‘Dissatisfied’ when the heating system approaches the end of its lifetime.
- test_exception_when_consultation_is_already_ordered(houseowner)[source]
Tests that get_data depletes cognitive resources if a consultation is already ordered.
- test_ordered_consulation_after_breakdown(houseowner)[source]
Tests that a consultation is ordered automatically when the heating system breaks down.
Tests that two neighbours correctly share and store each other’s heating system ratings.
Tests that a neighbour acquires knowledge of a new heating system from another houseowner.
Tests that redundant knowledge (of an already known heating system) is not shared.
- test_sharing_params_knowledge(houseowner, neighbour, heating_system_oil)[source]
Tests that knowledge sharing updates the parameters (e.g., operation effort) of a known heating system.
Tests that a houseowner’s satisfaction ratio for a heating system is updated based on neighbours’ opinions.
- test_gaining_information_about_hs(houseowner, information_source_internet, information_source_magazine, information_source_preference_cut)[source]
Tests that a houseowner can gain knowledge of new heating systems from media sources.
- test_gaining_information_about_hs_no_cognitive_resource(houseowner, information_source_preference_cut, information_source_internet, information_source_magazine)[source]
Tests that a houseowner with zero cognitive resources cannot gain new information.
- test_calculate_attitude(houseowner, heating_system_gas, heating_system_oil, heating_system_heat_pump)[source]
Tests that the calculated attitude (rating) for a heating system is within the expected bounds.
- test_define_choice(houseowner, heating_system_gas, heating_system_oil, heating_system_heat_pump)[source]
Tests that the houseowner identifies at least one suitable heating system when budget is unlimited.
- test_define_choice_when_infeasible(houseowner, heating_system_gas, heating_system_oil, heating_system_heat_pump)[source]
Tests that no suitable heating systems are chosen if all known systems are marked as infeasible.
- test_calculate_social_norm(houseowner, heating_system_gas)[source]
Tests that the calculated social norm for a heating system is a valid value between 0 and 1.
- test_calculate_social_norm_no_opinions(houseowner, heating_system_gas)[source]
Tests that the social norm is 0 when there are no neighbours’ opinions available.
- test_calculate_PBC(houseowner, heating_system_heat_pump)[source]
Tests that the Perceived Behavioural Control (PBC) is calculated as a value between 0 and 1.
- test_calculate_integral_rating(houseowner, heating_system_gas, heating_system_heat_pump)[source]
Tests that the final integral rating of suitable heating systems falls within the expected range.
- test_compare_hs(houseowner, heating_system_heat_pump, heating_system_gas)[source]
Tests that the houseowner selects a desired heating system after comparing suitable options.
- test_compare_hs_quitting(houseowner)[source]
Tests that the houseowner quits the decision process if no suitable heating systems are found.
- test_install_no_money(houseowner, plumber, heating_system_heat_pump)[source]
Tests that the installation process is halted if the houseowner lacks the budget.
- test_install(houseowner, plumber, heating_system_heat_pump)[source]
Tests that a plumber is correctly ordered when the houseowner decides to install a heating system.
- test_install_return_to_compare_hs(houseowner, plumber, heating_system_heat_pump, heating_system_gas)[source]
Tests that the houseowner re-evaluates choices if their first desired system is found to be infeasible.
- test_system_has_been_installed(houseowner, heating_system_heat_pump)[source]
Tests that the houseowner’s state progresses after a successful installation.
- test_calculate_dissatisfaction(houseowner, heating_system_heat_pump, heating_system_gas, heating_system_oil)[source]
Tests that the houseowner becomes dissatisfied when their current system is significantly worse than other known options.
Notes
The test depends on default parameter settings and is therefore not reliable.
- test_calculate_satisfaction(houseowner, heating_system_heat_pump)[source]
Tests that the houseowner is satisfied when their current system is the only known/suitable option.