Skip to content
This repository has been archived by the owner on Feb 10, 2018. It is now read-only.

Commit

Permalink
Add tests for utils.count. Fix case transform in count functions
Browse files Browse the repository at this point in the history
Also, edit test_utils_validate.py to add correct references in
documentation.
  • Loading branch information
Kaustav Das Modak committed Jan 20, 2013
1 parent 6cfef9f commit dd5b1cb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyavrophonetic/utils/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def count_vowels(text):
"""Count number of occurrences of vowels in a given string"""
count = 0
for i in text:
if i in config.AVRO_VOWELS:
if i.lower() in config.AVRO_VOWELS:
count += 1
return count

def count_consonants(text):
"""Count number of occurrences of consonants in a given string"""
count = 0
for i in text:
if i in config.AVRO_CONSONANTS:
if i.lower() in config.AVRO_CONSONANTS:
count += 1
return count
46 changes: 46 additions & 0 deletions tests/test_utils_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

"""Provides test cases for pyavrophonetic.avro.utils.count
-------------------------------------------------------------------------------
Copyright (C) 2013 Kaustav Das Modak <[email protected].
This file is part of pyAvroPhonetic.
pyAvroPhonetic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pyAvroPhonetic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pyAvroPhonetic. If not, see <http://www.gnu.org/licenses/>.
"""

# Imports
import unittest
from pyavrophonetic.utils import count


class TestUtilsCount(unittest.TestCase):
"""Tests validation methods for pyavrophonetic.utils.count"""

def test_count_vowels(self):
"""Test vowel count in a given string"""
self.assertEquals(count.count_vowels('haTTima Tim Tim'), 5)
self.assertEquals(count.count_vowels('tara maThe paRe Dim'), 7)
self.assertEquals(count.count_vowels('tader mathay duTO sing'), 7)
self.assertEquals(count.count_vowels('tara haTTima Tim Tim'), 7)

def test_count_consonants(self):
"""Test consonant count in a given string"""
self.assertEquals(count.count_consonants('ei dekh pensil'), 7)
self.assertEquals(count.count_consonants('nOTbuk e hate'), 6)
self.assertEquals(count.count_consonants('ei dekh bhora sob'), 8)
self.assertEquals(count.count_consonants('kil`bil lekha te'), 8)
2 changes: 1 addition & 1 deletion tests/test_utils_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class TestUtilsValidate(unittest.TestCase):
"""Tests validation methods for pyavrophonetic.utils.Validate"""
"""Tests validation methods for pyavrophonetic.utils.validate"""

def setUp(self):
"""Set up test environment"""
Expand Down

0 comments on commit dd5b1cb

Please sign in to comment.