def test_average_string(self): stringCheck = False try: main.average(["1, 2, -3, 4, -5, -6, 7, 8"]) except: stringCheck = True self.assertEqual(True, stringCheck)
def test_average_empty(self): NaN = False try: main.average([]) NaN = False except: NaN = True self.assertEqual(False, NaN)
def __init__(self, adults): ft = [x.fitness for x in adults] sd = 2*main.standard_deviation(ft) if sd == 0: self.h = [1]*len(adults) else: avg = main.average(ft) self.h = [] for a in adults: self.h.append((1+(a.fitness-avg)/sd)) s = sum(self.h,0.0) self.h[0] /= s for i in range(1, len(self.h)): self.h[i] /= s self.h[i] += self.h[i-1] self.h = zip(self.h, adults)
def test_average_float(self): self.assertEqual(-0.333, main.average([1, 1 / 3, -5, -6, 8]))
def test_average_complex(self): self.assertEqual( 1.625 + 0.625j, main.average([1, 2 + 8j, 2 - 3j, 4, -5, -6, 7 + 0j, 8]))
def test_average_negs(self): self.assertEqual(1.0, main.average([1, 2, -3, 4, -5, -6, 7, 8]))
def test_average_int(self): self.assertEqual(4.5, main.average([1, 2, 3, 4, 5, 6, 7, 8]))
import main import matplotlib.pyplot as plt import numpy as np import math from scipy.stats import norm dataSet = main.dataSet average = main.average(main.dataSet) # mean stDev = main.stdev # sigma calculated = [] # list that will get appended with (dataset[i] - stDev) accepted = [] rejected = [] confidenceLevel = 99.7 for i in range (0, len(dataSet)): calcMeanDev = float(dataSet[i] - stDev) calculated.append(calcMeanDev) print(calcMeanDev) for i in range (0, len(calculated)): if calculated[i] >= (-3 * stDev) and calculated[i] <= (3 * stDev): accepted.append(calculated[i]) else: rejected.append(calculated[i]) print(f'The rejected values were {rejected}') def marginOfError(stDev, confidenceLevel, calculated): standardError = (stDev / (math.sqrt(len(calculated)))) errorMargin = standardError * confidenceLevel
def test_avg(self): self.assertEqual(main.average([1, 2, 3]), 2) self.assertEqual(main.average([1, 1, 1]), 1)