Since I use ints to simplify things, I forget that special "." that makes 1./3 different from 1/3 (hint: the difference is a third)
Which really means, remember to use . anytime you don't specifically mean an integer!
class TestNormalizeFunction(unittest.TestCase):
def setUp(self):
## Setup for weight test
self.dateList2 = [1,1,1,2,2,2]
self.countryList2 = ["us","us","mx","us","us","mx"]
self.list2 = [1.,3.,3.,1.,3.,3.] ## <--- NOT THE SAME AS [1,3,3,1,3,3]!
def test_weights (self):
self.assertEqual(process.calculateWeights(
self.dateList2, self.countryList2, self.list2),
[self.list2[0] / sum(self.list2[:2]),
self.list2[1] / sum(self.list2[:2]),
1.,
self.list2[3] / sum(self.list2[3:5]),
self.list2[4] / sum(self.list2[3:5]),
1.])
if __name__ == "__main__":
unittest.main()
No comments:
Post a Comment