def test_avg(self): """ Test procedure for function avg(). """ print('Testing avg()') result = avg(()) self.assertEqual(0, result) result = avg((7, 1, 4, 3, 6, 8)) self.assertEqual(4.833333333333333, result) result = avg((-1, 1, 3, 5)) self.assertEqual(2.0, result) result = avg((2.5, )) self.assertEqual(2.5, result) result = avg((1.0, 1.0, 1.0)) self.assertEqual(1.0, result) tup = tuple(range(10, 20)) result = avg(tup) self.assertEqual(14.5, result)
def test_avg_empty(self): self.assertEqual(average.avg([]), 0)
def test_avg_string(self): self.assertEqual(average.avg(['a', 'b', 'c', 'd', 'e']), 'f')
def test_avg_floating(self): self.assertEqual(average.avg([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5.5)
#!/usr/bin/env python3 """Vstupní bod do testované aplikace.""" from average import avg if __name__ == '__main__': # pouze se ujistíme, že lze spustit funkci average print(avg([1, 2]))
def test_average(self): result = average.avg(4,4,6,6) self.assertEqual(result, 5)
def test_average_basic(): """Otestování výpočtu průměru.""" result = average.avg([1, 2]) expected = 1.5 assert result == expected, "Očekávaná hodnota {}, vráceno {}".format(expected, result)
def test_empty(self): n = average.avg([]) self.assertEqual(n, 'error') #can't be empty
def test_average_more_values(values, expected): """Otestování výpočtu průměru.""" result = average.avg(values) assert result == expected, "Očekávaná hodnota {}, vráceno {}".format( expected, result)
def test_complexnumber(self): v = average.avg([-30, 40, 50]) self.assertEqual(v, 20)
def test_av(self): v = average.avg([1, 2, 3, 4, 5]) self.assertEqual(v, 3.0)
if pz > .001: y_pz.append(pz) x_z.append(z) if len(y_pz) > 0: #print(x_z) #print(average.avg(x_z)) #print(average.stdev(x_z)) not using this bc we are not taking the stdev of just the x_z values, we want to fit the distribution to a gaussian #popt, pcov = curve_fit(gaussian.gauss_function, x_z, y_pz) #optimizes parameters #print (i) try: popt,pcov = scipy.optimize.curve_fit(gaussian.gauss_function, x_z, y_pz,p0= [1,(average.avg(x_z)), .3]) #the try-except error handling procedure is to exceed the max call to fcn of 800 times except RuntimeError: print("Error - curve_fit failed") #print(popt) print i #popt[0], popt[1], popt[2] = map(float, popt.split()) #assign values to popt (a, x0, sigma) outfile.write("%s \t %s \t %s \t %s \n" % (i, popt[0], popt[1], abs(popt[2]))) #writing values from outfile to 4colAmpAvgStdev.py if popt[1]<0: print i, popt if popt[0]<0: print i, popt data.close() outfile.close()
def test_avg(self): self.assertEqual(average.avg([2, 3, 4, 5]), 3.5)
def test_average1(self): result = average.avg(1,1,1,1) self.assertEqual(result, 1)
def test_avg_whole(self): self.assertEqual(average.avg([2, 2, 2, 2]), 2)
def test_average_empty_list(): """Otestování výpočtu průměru pro prázdný vstup.""" with pytest.raises(ZeroDivisionError) as excinfo: result = average.avg([])
def test_float_neg(self): self.assertEqual(avg([.5, -.5, 3]), 1.0)
def test_average2(self): result = average.avg(.5,1.5,2.5,3.5) self.assertEqual(result, 2)