__author__ = 'Kevin Chen' __status__ = 'Development' import os from unittest import TestCase from MathematicaToLaTeX import master_function from MathematicaToLaTeX import arg_split with open(os.path.dirname(os.path.realpath(__file__)) + '/../data/functions') as functions: FUNCTION_CONVERSIONS = list( arg_split(line.replace(' ', ''), ',') for line in functions.read().split('\n') if (line != '' and '#' not in line)) for index, item in enumerate(FUNCTION_CONVERSIONS): FUNCTION_CONVERSIONS[index][2] = tuple( arg_split(FUNCTION_CONVERSIONS[index][2][1:-1], ',')) if FUNCTION_CONVERSIONS[index][3] == '()': FUNCTION_CONVERSIONS[index][3] = '' else: FUNCTION_CONVERSIONS[index][3] = tuple( FUNCTION_CONVERSIONS[index][3][1:-1].split(',')) FUNCTION_CONVERSIONS[index] = tuple(FUNCTION_CONVERSIONS[index]) FUNCTION_CONVERSIONS = tuple(FUNCTION_CONVERSIONS) class TestMasterFunction(TestCase):
def test_none(self): self.assertEqual(arg_split('noseperator', ','), ['noseperator'])
__author__ = 'Kevin Chen' __status__ = 'Development' import os from unittest import TestCase from MathematicaToLaTeX import master_function from MathematicaToLaTeX import arg_split with open(os.path.dirname(os.path.realpath(__file__)) + '/../data/functions') as functions: FUNCTION_CONVERSIONS = list(arg_split(line.replace(' ', ''), ',') for line in functions.read().split('\n') if (line != '' and '#' not in line)) for index, item in enumerate(FUNCTION_CONVERSIONS): FUNCTION_CONVERSIONS[index][2] = tuple(arg_split(FUNCTION_CONVERSIONS[index][2][1:-1], ',')) if FUNCTION_CONVERSIONS[index][3] == '()': FUNCTION_CONVERSIONS[index][3] = '' else: FUNCTION_CONVERSIONS[index][3] = tuple(FUNCTION_CONVERSIONS[index][3][1:-1].split(',')) FUNCTION_CONVERSIONS[index] = tuple(FUNCTION_CONVERSIONS[index]) FUNCTION_CONVERSIONS = tuple(FUNCTION_CONVERSIONS) class TestMasterFunction(TestCase):
def test_parens(self): before = '(a,b),[c,d],{e,(f,g)}' after = ['(a,b)', '[c,d]', '{e,(f,g)}'] self.assertEqual(arg_split(before, ','), after)
def test_combined(self): before = 'a,(b,c),,[d,e],,,{fg,hi}' after = ['a', '(b,c)', '', '[d,e]', '', '', '{fg,hi}'] self.assertEqual(arg_split(before, ','), after)
def test_empty(self): self.assertEqual(arg_split(',,,,,,', ','), ',,,,,,'.split(','))
def test_some_empty(self): before = 'a,,b,,c,,d' after = ['a', '', 'b', '', 'c', '', 'd'] self.assertEqual(arg_split(before, ','), after)
def test_normal(self): self.assertEqual(arg_split(','.join(list('abcdef')), ','), ','.join(list('abcdef')).split(','))