def test_floats(self): tests = [ {"val": 4, "round": "norm", "res": 4}, {"val": 4.4, "round": "norm", "res": 5}, {"val": 4, "round": "up", "res": 5}, {"val": 4.4, "round": "up", "res": 5}, {"val": 4.6, "round": "up", "res": 6}, {"val": 4, "round": "down", "res": 4}, {"val": 4.4, "round": "down", "res": 4}, {"val": 4.6, "round": "down", "res": 5}, ] list = numpy.linspace(0,10,12) for t in tests: res = CF.find_index_for_value(list, value = t["val"], round = t["round"]) self.assertEqual(t["res"], res)
def test_ints(self): tests = [ {"val": 4, "round": "norm", "res": 4}, {"val": 4.4, "round": "norm", "res": 4}, {"val": 4.6, "round": "norm", "res": 5}, {"val": 4.5, "round": "norm", "res": 5}, {"val": 4, "round": "up", "res": 4}, {"val": 4.4, "round": "up", "res": 5}, {"val": 4.6, "round": "up", "res": 5}, {"val": 4, "round": "down", "res": 4}, {"val": 4.4, "round": "down", "res": 4}, {"val": 4.6, "round": "down", "res": 4}, ] list = numpy.arange(10) for t in tests: res = CF.find_index_for_value(list, value = t["val"], round = t["round"]) self.assertEqual(t["res"], res)