#!python # vim: encoding=latin1 ts=8 sts=4 et si sw=4 ft=python """ Test ranges module on pool of float values """ VERSION = '.'.join(map(str, (0, 1, ))) import unittest from ranges import * POOL = (0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.4, 2.8, 3.2, 3.6) class Testcase_working_semicolon(unittest.TestCase): """ Testcase for correct expressions without commas. For float values, only range operations make sense, since floats are not enumerable """ known_values = ( ('1 to 3', (1.2, 1.6, 2.0, 2.4, 2.8,), '1 <= x <= 3'), ('1.0 to 3.0', (1.2, 1.6, 2.0, 2.4, 2.8,), '1.0 <= x <= 3.0'), ) def test_knownvalues(self): "filter functions yield predicted subsets" for expr, predicted, pyex in self.known_values: eo = make_expression(expr) res = filter(eo.filter_func(), POOL) self.assertEqual(res, predicted) def test_python_expressions(self): "Expression objects yield predicted Python expressions" for expr, predicted, pyex in self.known_values: eo = make_expression(expr) self.assertEqual(pyex, eo.python_expression()) if __name__ == '__main__': unittest.main()