def test_cai_2(self): """cai_2 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA':4, 'AGG':2, 'CCC':5, 'CCA':1, 'UGG':1}) #tests with arithmetic mean gene_freqs = {'AGA':1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.6) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_2(ref_freqs_2, gene_freqs, average=arithmetic_mean) vals = [1,1,1,.5,1,1,.2,1,.5,.5] expect = sum(vals)/len(vals) self.assertEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA':1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_2(ref_freqs_2, gene_freqs, average=geometric_mean) vals = [1,1,1,.5,1,1,.2,1,.5,.5] expect = (product(vals))**(1./len(vals)) self.assertEqual(obs, expect) #test that results match example on Gang Wu's CAI calculator page ref_freqs = cu.copy() ref_freqs.update({'UUU':78743, 'UUC':56591, 'UUA':51320, 'UUG':45581, \ 'CUU':42704, 'CUC':35873, 'CUA':15275, 'CUG':168885}) gene_freqs={'UUU':6, 'UUC':3, 'CUU':3, 'CUC':2, 'CUG':8} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ exp((6*log(1) + 3*log(56591./78743) + 3*log(42704./168885) + \ 2*log(35873./168885)+8*log(1))/22.))
def test_cai_1(self): """cai_1 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA':4, 'AGG':2, 'CCC':4, 'CCA':1, 'UGG':1}) #tests with arithmetic mean gene_freqs = {'AGA':1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.625) ref_freqs_2 = cu.copy() ref_freqs_2.update({'AGA':4, 'AGG':2, 'CCC':5, 'CCA':1, 'UGG':1}) ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_1(ref_freqs_2, gene_freqs, average=arithmetic_mean) vals = [.8,.8,.8,.4,1,1,.2,.4,.2,.2] expect = sum(vals)/len(vals) self.assertFloatEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA':1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertFloatEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertFloatEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.25**5)**0.1) ref_freqs_2 = cu.copy() ref_freqs_2.update({'AGA':4, 'AGG':2, 'CCC':5, 'CCA':1, 'UGG':1}) ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_1(ref_freqs_2, gene_freqs, average=geometric_mean) vals = [.8,.8,.8,.4,1,1,.2,.4,.2,.2] expect = (product(vals))**(1./len(vals)) self.assertFloatEqual(obs, expect)
def test_cai_3(self): """cai_3 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA':4, 'AGG':2, 'CCC':5, 'CCA':1, 'UGG':1}) #tests with arithmetic mean gene_freqs = {'AGA':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.6) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_3(ref_freqs_2, gene_freqs, average=arithmetic_mean) family_vals = [[1,1,1,.5],[1,1,.2],[1,.5,.5]] family_averages = map(amean, family_vals) expect = amean(family_averages) self.assertEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs={'AGA':5,'CCA':5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_3(ref_freqs_2, gene_freqs, average=geometric_mean) family_vals = [[1,1,1,.5],[1,1,.2],[1,.5,.5]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertEqual(obs, expect) #tests with Eyre-Walker's variant -- should be same as geometric mean gene_freqs = {'AGA':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs = {'AGA':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs = {'AGG':5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 0.5) gene_freqs = {'AGG':5,'AGA':5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), \ (1**5 * 0.5**5)**(0.1)) gene_freqs={'AGA':5,'CCC':1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs={'AGA':5,'CCA':5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU':2,'UUC':1}) gene_freqs = {'AGA':3,'AGG':1,'CCC':2,'CCA':1,'UUU':1, 'UUC':2} obs = cai_3(ref_freqs_2, gene_freqs, average='eyre_walker') family_vals = [[1,1,1,.5],[1,1,.2],[1,.5,.5]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertEqual(obs, expect) #test results for Gang Wu's example (unfortunately, no worked example for #this model) ref_freqs = cu.copy() ref_freqs.update({'UUU':78743, 'UUC':56591, 'UUA':51320, 'UUG':45581, \ 'CUU':42704, 'CUC':35873, 'CUA':15275, 'CUG':168885}) gene_freqs={'UUU':6, 'UUC':3, 'CUU':3, 'CUC':2, 'CUG':8} obs = cai_3(ref_freqs, gene_freqs, average=geometric_mean) family_vals = [6*[1]+3*[56591./78743],\ 3*[42704./168885] + 2*[35873./168885]+8*[1]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertFloatEqual(obs, expect)
def test_cai_3(self): """cai_3 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA': 4, 'AGG': 2, 'CCC': 5, 'CCA': 1, 'UGG': 1}) #tests with arithmetic mean gene_freqs = {'AGA': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=arithmetic_mean), 0.6) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_3(ref_freqs_2, gene_freqs, average=arithmetic_mean) family_vals = [[1, 1, 1, .5], [1, 1, .2], [1, .5, .5]] family_averages = map(amean, family_vals) expect = amean(family_averages) self.assertEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_3(ref_freqs_2, gene_freqs, average=geometric_mean) family_vals = [[1, 1, 1, .5], [1, 1, .2], [1, .5, .5]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertEqual(obs, expect) #tests with Eyre-Walker's variant -- should be same as geometric mean gene_freqs = {'AGA': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), \ (1**5 * 0.5**5)**(0.1)) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertFloatEqual(cai_3(ref_freqs, gene_freqs, average='eyre_walker'), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_3(ref_freqs_2, gene_freqs, average='eyre_walker') family_vals = [[1, 1, 1, .5], [1, 1, .2], [1, .5, .5]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertEqual(obs, expect) #test results for Gang Wu's example (unfortunately, no worked example for #this model) ref_freqs = cu.copy() ref_freqs.update({'UUU':78743, 'UUC':56591, 'UUA':51320, 'UUG':45581, \ 'CUU':42704, 'CUC':35873, 'CUA':15275, 'CUG':168885}) gene_freqs = {'UUU': 6, 'UUC': 3, 'CUU': 3, 'CUC': 2, 'CUG': 8} obs = cai_3(ref_freqs, gene_freqs, average=geometric_mean) family_vals = [6*[1]+3*[56591./78743],\ 3*[42704./168885] + 2*[35873./168885]+8*[1]] family_averages = map(gmean, family_vals) expect = gmean(family_averages) self.assertFloatEqual(obs, expect)
def test_cai_2(self): """cai_2 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA': 4, 'AGG': 2, 'CCC': 5, 'CCA': 1, 'UGG': 1}) #tests with arithmetic mean gene_freqs = {'AGA': 1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=arithmetic_mean), 0.6) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_2(ref_freqs_2, gene_freqs, average=arithmetic_mean) vals = [1, 1, 1, .5, 1, 1, .2, 1, .5, .5] expect = sum(vals) / len(vals) self.assertEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA': 1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.2**5)**0.1) ref_freqs_2 = ref_freqs.copy() ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_2(ref_freqs_2, gene_freqs, average=geometric_mean) vals = [1, 1, 1, .5, 1, 1, .2, 1, .5, .5] expect = (product(vals))**(1. / len(vals)) self.assertEqual(obs, expect) #test that results match example on Gang Wu's CAI calculator page ref_freqs = cu.copy() ref_freqs.update({'UUU':78743, 'UUC':56591, 'UUA':51320, 'UUG':45581, \ 'CUU':42704, 'CUC':35873, 'CUA':15275, 'CUG':168885}) gene_freqs = {'UUU': 6, 'UUC': 3, 'CUU': 3, 'CUC': 2, 'CUG': 8} self.assertFloatEqual(cai_2(ref_freqs, gene_freqs, average=geometric_mean), \ exp((6*log(1) + 3*log(56591./78743) + 3*log(42704./168885) + \ 2*log(35873./168885)+8*log(1))/22.))
def test_cai_1(self): """cai_1 should produce expected results""" ref_freqs = cu.copy() ref_freqs.update({'AGA': 4, 'AGG': 2, 'CCC': 4, 'CCA': 1, 'UGG': 1}) #tests with arithmetic mean gene_freqs = {'AGA': 1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.75) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=arithmetic_mean), 0.625) ref_freqs_2 = cu.copy() ref_freqs_2.update({'AGA': 4, 'AGG': 2, 'CCC': 5, 'CCA': 1, 'UGG': 1}) ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_1(ref_freqs_2, gene_freqs, average=arithmetic_mean) vals = [.8, .8, .8, .4, 1, 1, .2, .4, .2, .2] expect = sum(vals) / len(vals) self.assertFloatEqual(obs, expect) #tests with geometric mean gene_freqs = {'AGA': 1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGG': 5} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 0.5) gene_freqs = {'AGG': 5, 'AGA': 5} self.assertFloatEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.5**5)**(0.1)) gene_freqs = {'AGA': 5, 'CCC': 1} self.assertEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), 1) gene_freqs = {'AGA': 5, 'CCA': 5} self.assertFloatEqual(cai_1(ref_freqs, gene_freqs, average=geometric_mean), \ (1**5 * 0.25**5)**0.1) ref_freqs_2 = cu.copy() ref_freqs_2.update({'AGA': 4, 'AGG': 2, 'CCC': 5, 'CCA': 1, 'UGG': 1}) ref_freqs_2.update({'UUU': 2, 'UUC': 1}) gene_freqs = { 'AGA': 3, 'AGG': 1, 'CCC': 2, 'CCA': 1, 'UUU': 1, 'UUC': 2 } obs = cai_1(ref_freqs_2, gene_freqs, average=geometric_mean) vals = [.8, .8, .8, .4, 1, 1, .2, .4, .2, .2] expect = (product(vals))**(1. / len(vals)) self.assertFloatEqual(obs, expect)