mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from nose.tools import assert_equal
|
|
from ..transform_util import TransformUtil
|
|
|
|
|
|
class TestTransformUtil():
|
|
|
|
states = [' Alabama ', 'Georgia!', 'Georgia', 'georgia', \
|
|
'FlOrIda', 'south carolina##', 'West virginia?']
|
|
|
|
expected_output = ['Alabama',
|
|
'Georgia',
|
|
'Georgia',
|
|
'Georgia',
|
|
'Florida',
|
|
'South Carolina',
|
|
'West Virginia']
|
|
|
|
def test_remove_punctuation(self):
|
|
assert_equal(TransformUtil.remove_punctuation('!#?'), '')
|
|
|
|
def test_map_remove_punctuation(self):
|
|
# Map applies a function to a collection
|
|
output = map(TransformUtil.remove_punctuation, self.states)
|
|
assert_equal('!#?' not in output, True)
|
|
|
|
def test_clean_strings(self):
|
|
clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title]
|
|
output = TransformUtil.clean_strings(self.states, clean_ops)
|
|
assert_equal(output, self.expected_output) |