
import sys, math, random
import HypoTesting

print("2 sided hypothesis testing:\n")

n = int(input("Number of (Bernoulli) experiments = "))
p = float(input("Probability of success = "))


mu_0, sigma_0 = HypoTesting.normal_approximation_to_binomial(n, p)
print(f"Mu and sigma to approximate bin({n},{p}) = ", mu_0, sigma_0)

conf = float(input("\nConfidence (0.95 or 0.99) = "))

lo, hi = HypoTesting.normal_two_sided_bounds(conf, mu_0, sigma_0)

print(f"\nnormal_two_sided_bounds({conf}):")
print( ">>>>> ", lo, "----", hi )
print( ">>>>> ", f"{conf*100}% of the time, the value will fall in this range")


# Perform the experiment 100000 times:
count = 0
for _ in range(100000):
    num_heads = sum(1 if random.random() < p else 0    # Count # of heads
                    for _ in range(n))                # in 1000 flips

    if num_heads >= lo and num_heads <= hi:   # Count how often
        count += 1                            # the experiment fall in range

print(f"\nExperimental prob {lo} < Count < {hi} = ", count / 100000) 


