Skip to content

Commit

Permalink
feat: added tests for avgwordlen function
Browse files Browse the repository at this point in the history
  • Loading branch information
kphaterp committed Jan 20, 2022
1 parent c089983 commit fcb72f2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_avg_word_len.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from textfeatureinfo.textfeatureinfo import avg_word_len


def test_avg_word_len():
"""
Tests the calculation of the average word length from a string.
"""
s1 = ""
s2 = "Hello World"
s3 = "!!!hello!!!"
s4 = "Here.are.some.words."
s5 = "Hello, World!"

assert avg_word_len(s1) == 0, "Output should be 0"
assert avg_word_len(s2) == 5, "Output should be 5"
assert avg_word_len(s3) == 5, "Output should be 5"
assert avg_word_len(s4) == 4, "Output should be 4"
assert avg_word_len(s5) == 5, "Output should be 5"


def test_avg_word_len_errors():
"""
Checks for TypeErrors when the incorrect argument type is passed into avg_word_len.
"""
with pytest.raises(TypeError):
alist = ["a list of words"]
avg_word_len(alist)

with pytest.raises(TypeError):
adict = {"a": "dictionary of words"}
avg_word_len(adict)


test_avg_word_len()

0 comments on commit fcb72f2

Please sign in to comment.