Iterate a test function through many context settings.
(method, testspecs, testfunc)
| 928 | sys.stdout.flush() |
| 929 | |
| 930 | def test_method(method, testspecs, testfunc): |
| 931 | """Iterate a test function through many context settings.""" |
| 932 | log("testing %s ...", method) |
| 933 | stat = defaultdict(int) |
| 934 | for spec in testspecs: |
| 935 | if 'samples' in spec: |
| 936 | spec['prec'] = sorted(random.sample(range(1, 101), |
| 937 | spec['samples'])) |
| 938 | for prec in spec['prec']: |
| 939 | context.prec = prec |
| 940 | for expts in spec['expts']: |
| 941 | emin, emax = expts |
| 942 | if emin == 'rand': |
| 943 | context.Emin = random.randrange(-1000, 0) |
| 944 | context.Emax = random.randrange(prec, 1000) |
| 945 | else: |
| 946 | context.Emin, context.Emax = emin, emax |
| 947 | if prec > context.Emax: continue |
| 948 | log(" prec: %d emin: %d emax: %d", |
| 949 | (context.prec, context.Emin, context.Emax)) |
| 950 | restr_range = 9999 if context.Emax > 9999 else context.Emax+99 |
| 951 | for rounding in RoundModes: |
| 952 | context.rounding = rounding |
| 953 | context.capitals = random.randrange(2) |
| 954 | if spec['clamp'] == 'rand': |
| 955 | context.clamp = random.randrange(2) |
| 956 | else: |
| 957 | context.clamp = spec['clamp'] |
| 958 | exprange = context.c.Emax |
| 959 | testfunc(method, prec, exprange, restr_range, |
| 960 | spec['iter'], stat) |
| 961 | log(" result types: %s" % sorted([t for t in stat.items()])) |
| 962 | |
| 963 | def test_unary(method, prec, exp_range, restricted_range, itr, stat): |
| 964 | """Iterate a unary function through many test cases.""" |