Added map snippet.

This commit is contained in:
Donne Martin 2015-01-26 14:07:37 -05:00
parent 42f6f9f6b5
commit 9fabf8e01b
2 changed files with 12 additions and 2 deletions

View File

@ -1,7 +1,7 @@
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:8c91cadf8bbcbcdd5a60fc0a89e964b846a6f5328eaa57d57afbaedda06ad3ca" "signature": "sha256:93f08d982c73b7b50d2c679984dc25a00cc198f32a1a82269c2c119da5d0e26e"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
@ -108,6 +108,11 @@
" \n", " \n",
" def test_remove_punctuation(self):\n", " def test_remove_punctuation(self):\n",
" assert_equal(TransformUtil.remove_punctuation('!#?'), '')\n", " assert_equal(TransformUtil.remove_punctuation('!#?'), '')\n",
" \n",
" def test_map_remove_punctuation(self):\n",
" # Map applies a function to a collection\n",
" output = map(TransformUtil.remove_punctuation, self.states)\n",
" assert_equal('!#?' not in output, True)\n",
"\n", "\n",
" def test_clean_strings(self):\n", " def test_clean_strings(self):\n",
" clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title] \n", " clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title] \n",
@ -141,10 +146,11 @@
"stream": "stdout", "stream": "stdout",
"text": [ "text": [
"core.tests.test_transform_util.TestTransformUtil.test_clean_strings ... ok\r\n", "core.tests.test_transform_util.TestTransformUtil.test_clean_strings ... ok\r\n",
"core.tests.test_transform_util.TestTransformUtil.test_map_remove_punctuation ... ok\r\n",
"core.tests.test_transform_util.TestTransformUtil.test_remove_punctuation ... ok\r\n", "core.tests.test_transform_util.TestTransformUtil.test_remove_punctuation ... ok\r\n",
"\r\n", "\r\n",
"----------------------------------------------------------------------\r\n", "----------------------------------------------------------------------\r\n",
"Ran 2 tests in 0.001s\r\n", "Ran 3 tests in 0.002s\r\n",
"\r\n", "\r\n",
"OK\r\n" "OK\r\n"
] ]

View File

@ -17,6 +17,10 @@ class TestTransformUtil():
def test_remove_punctuation(self): def test_remove_punctuation(self):
assert_equal(TransformUtil.remove_punctuation('!#?'), '') assert_equal(TransformUtil.remove_punctuation('!#?'), '')
def test_map_remove_punctuation(self):
output = map(TransformUtil.remove_punctuation, self.states)
assert_equal('!#?' not in output, True)
def test_clean_strings(self): def test_clean_strings(self):
clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title] clean_ops = [str.strip, TransformUtil.remove_punctuation, str.title]