Skip to content

Commit dd53efd

Browse files
committed
refactor(tes): add test coverage
1 parent 64246e4 commit dd53efd

File tree

5 files changed

+250
-4
lines changed

5 files changed

+250
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
__pycache__
2-
dist
2+
.pytest_cache
3+
dist
4+
.coverag

poetry.lock

Lines changed: 170 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "rotate_group_words"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
description = ""
55
authors = [
66
{name = "TSX",email = "miladtsx@gmail.com"}
@@ -10,6 +10,10 @@ requires-python = ">=3.13"
1010
dependencies = [
1111
]
1212

13+
[tool.poetry.group.dev.dependencies]
14+
pytest = "^8.0"
15+
pytest-cov = "^6.1.1"
16+
1317
[tool.poetry]
1418
packages = [{include = "rotate_group_words", from = "src"}]
1519

src/rotate_group_words/rotate_group_words.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def rotate_word(word: str, count_of_rotation: int) -> str:
2121

2222

2323
def rotate_word_once(word: str) -> str:
24+
if len(word) == 0 or len(word) == 1: return word
2425
the_last_word = word[-1]
2526
return the_last_word + word[:-1]
2627

tests/test_rotate_group_words.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import pytest
2+
from rotate_group_words.rotate_group_words import (
3+
is_similar, rotate_word, rotate_word_once, iterating_through_input, rotate_group_words
4+
)
5+
6+
# --- Unit tests ---
7+
def test_is_similar_true():
8+
assert is_similar("abcd", "cdab")
9+
assert is_similar("abcd", "dabc")
10+
assert is_similar("abcd", "bcda")
11+
assert is_similar("a", "a")
12+
assert is_similar("", "")
13+
14+
def test_is_similar_false():
15+
assert not is_similar("abcd", "abce")
16+
assert not is_similar("abcd", "abc")
17+
assert not is_similar("abcd", "efgh")
18+
assert not is_similar("abcd", "")
19+
assert not is_similar("", "abcd")
20+
21+
def test_rotate_word_once():
22+
assert rotate_word_once("abcd") == "dabc"
23+
assert rotate_word_once("a") == "a"
24+
assert rotate_word_once("") == ""
25+
26+
def test_rotate_word():
27+
assert rotate_word("abcd", 1) == "dabc"
28+
assert rotate_word("abcd", 2) == "cdab"
29+
assert rotate_word("abcd", 4) == "abcd"
30+
assert rotate_word("a", 3) == "a"
31+
assert rotate_word("", 5) == ""
32+
33+
def test_iterating_through_input_basic():
34+
words = ["abcd", "cdab", "dabc", "bcda", "efgh", "ghfe"]
35+
result = iterating_through_input(words)
36+
assert set(result.keys()) == {"abcd", "efgh", "ghfe"}
37+
assert set(result["abcd"]) == {"abcd", "cdab", "dabc", "bcda"}
38+
assert result["efgh"] == ["efgh"]
39+
assert result["ghfe"] == ["ghfe"]
40+
41+
def test_iterating_through_input_empty():
42+
assert iterating_through_input([]) == {}
43+
44+
def test_iterating_through_input_single():
45+
assert iterating_through_input(["a"]) == {"a": ["a"]}
46+
47+
# --- Integration test for rotate_group_words (captures print output) ---
48+
def test_rotate_group_words_print(monkeypatch):
49+
words = ["abcd", "cdab", "dabc", "bcda", "efgh", "ghfe"]
50+
output = []
51+
monkeypatch.setattr("builtins.print", lambda x: output.append(x))
52+
rotate_group_words(words)
53+
assert any("abcd: [abcd, cdab, dabc, bcda]" in line for line in output)
54+
assert any("efgh: [efgh]" in line for line in output)
55+
assert any("ghfe: [ghfe]" in line for line in output)
56+
57+
# --- CLI integration test ---
58+
import subprocess
59+
import sys
60+
import os
61+
62+
def test_cli_entry(tmp_path):
63+
script = os.path.join(os.path.dirname(__file__), "../src/rotate_group_words/entry.py")
64+
result = subprocess.run(
65+
[sys.executable, script, "-w", "abcd,cdab,dabc,bcda,efgh,ghfe"],
66+
capture_output=True, text=True
67+
)
68+
assert "abcd: [abcd, cdab, dabc, bcda]" in result.stdout
69+
assert "efgh: [efgh]" in result.stdout
70+
assert "ghfe: [ghfe]" in result.stdout
71+
assert result.returncode == 0

0 commit comments

Comments
 (0)