# scipy-yli: Helpful SciPy utilities and recipes # Copyright © 2022 Lee Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import yli from yli.config import config from yli.utils import PValueStyle, fmt_p def test_fmt_pvalues_ord(): """Test formatting of p values requiring no special handling""" # Default config config.pvalue_min_dps = 2 config.pvalue_max_dps = 3 config.pvalue_leading_zero = True config.alpha = 0.05 assert fmt_p(0.0096, PValueStyle.RELATION) == '= 0.01*' assert fmt_p(0.01, PValueStyle.RELATION) == '= 0.01*' assert fmt_p(0.04, PValueStyle.RELATION) == '= 0.04*' assert fmt_p(0.11, PValueStyle.RELATION) == '= 0.11' assert fmt_p(0.55, PValueStyle.RELATION) == '= 0.55' def test_fmt_pvalues_ord_noleadingzero(): """Test formatting of p values requiring no special handling, no leading zero""" # Default config config.pvalue_min_dps = 2 config.pvalue_max_dps = 3 config.pvalue_leading_zero = False config.alpha = 0.05 assert fmt_p(0.0096, PValueStyle.RELATION) == '= .01*' assert fmt_p(0.01, PValueStyle.RELATION) == '= .01*' assert fmt_p(0.04, PValueStyle.RELATION) == '= .04*' assert fmt_p(0.11, PValueStyle.RELATION) == '= .11' assert fmt_p(0.55, PValueStyle.RELATION) == '= .55' def test_fmt_pvalues_small(): """Test formatting of small p values requiring extra decimal points to represent""" # Default config config.pvalue_min_dps = 2 config.pvalue_max_dps = 3 config.pvalue_leading_zero = True config.alpha = 0.05 assert fmt_p(0.009, PValueStyle.RELATION) == '= 0.009*' def test_fmt_pvalues_ambiguous(): """Test formatting of p values requiring extra decimal points to avoid ambiguity""" # Default config config.pvalue_min_dps = 2 config.pvalue_max_dps = 3 config.pvalue_leading_zero = True config.alpha = 0.05 assert fmt_p(0.048, PValueStyle.RELATION) == '= 0.048*' assert fmt_p(0.052, PValueStyle.RELATION) == '= 0.052' # Special rounding rules assert fmt_p(0.04999, PValueStyle.RELATION) == '= 0.049*' assert fmt_p(0.05001, PValueStyle.RELATION) == '= 0.051' def test_fmt_pvalues_extreme(): """Test formatting of p values too small or large to be represented""" # Default config config.pvalue_min_dps = 2 config.pvalue_max_dps = 3 config.pvalue_leading_zero = True config.alpha = 0.05 assert fmt_p(0.0009, PValueStyle.RELATION) == '< 0.001*' assert fmt_p(0.999, PValueStyle.RELATION) == '> 0.99'