Repository navigation
Expand file tree
/
Copy pathtest_simple_utils.py
More file actions
84 lines (55 loc) · 2.62 KB
/
Copy pathtest_simple_utils.py
File metadata and controls
84 lines (55 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Unit tests for simple_utils.py"""
import pytest
from simple_utils import celsius_to_fahrenheit, count_words, reverse_string
class TestReverseString:
def test_reverses_basic_word(self):
assert reverse_string("hello") == "olleh"
def test_reverses_sentence_with_spaces(self):
assert reverse_string("hello world") == "dlrow olleh"
def test_empty_string_returns_empty(self):
assert reverse_string("") == ""
def test_single_character(self):
assert reverse_string("a") == "a"
def test_palindrome_is_unchanged(self):
assert reverse_string("racecar") == "racecar"
def test_reversing_twice_returns_original(self):
text = "Reversal Test 123"
assert reverse_string(reverse_string(text)) == text
def test_string_with_special_characters(self):
assert reverse_string("a1! b2@") == "2b !1a"
def test_string_with_unicode_characters(self):
assert reverse_string("héllo") == "olléh"
def test_string_with_only_whitespace(self):
assert reverse_string(" ") == " "
class TestCountWords:
def test_counts_words_in_normal_sentence(self):
assert count_words("The quick brown fox") == 4
def test_single_word(self):
assert count_words("hello") == 1
def test_empty_string_has_zero_words(self):
assert count_words("") == 0
def test_whitespace_only_string_has_zero_words(self):
assert count_words(" ") == 0
def test_multiple_spaces_between_words_are_collapsed(self):
assert count_words("hello world") == 2
def test_leading_and_trailing_whitespace_ignored(self):
assert count_words(" hello world ") == 2
def test_counts_words_separated_by_tabs_and_newlines(self):
assert count_words("hello\tworld\nfoo") == 3
def test_sentence_with_punctuation_counts_tokens(self):
assert count_words("Hello, world!") == 2
class TestCelsiusToFahrenheit:
def test_freezing_point_of_water(self):
assert celsius_to_fahrenheit(0) == 32
def test_boiling_point_of_water(self):
assert celsius_to_fahrenheit(100) == 212
def test_negative_temperature(self):
assert celsius_to_fahrenheit(-40) == -40
def test_body_temperature_approx(self):
assert celsius_to_fahrenheit(37) == pytest.approx(98.6)
def test_float_input(self):
assert celsius_to_fahrenheit(36.6) == pytest.approx(97.88)
def test_zero_kelvin_offset_like_extreme_negative(self):
assert celsius_to_fahrenheit(-273.15) == pytest.approx(-459.67)
def test_large_positive_value(self):
assert celsius_to_fahrenheit(1000) == pytest.approx(1832.0)