Skip to content

Commit f9a9407

Browse files
committed
Finished AboutStrings
1 parent 0593058 commit f9a9407

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

python2/koans/about_strings.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,127 +8,127 @@ class AboutStrings(Koan):
88

99
def test_double_quoted_strings_are_strings(self):
1010
string = "Hello, world."
11-
self.assertEqual(__, isinstance(string, basestring))
11+
self.assertEqual(True, isinstance(string, basestring))
1212

1313
def test_single_quoted_strings_are_also_strings(self):
1414
string = 'Goodbye, world.'
15-
self.assertEqual(__, isinstance(string, basestring))
15+
self.assertEqual(True, isinstance(string, basestring))
1616

1717
def test_triple_quote_strings_are_also_strings(self):
1818
string = """Howdy, world!"""
19-
self.assertEqual(__, isinstance(string, basestring))
19+
self.assertEqual(True, isinstance(string, basestring))
2020

2121
def test_triple_single_quotes_work_too(self):
2222
string = '''Bonjour tout le monde!'''
23-
self.assertEqual(__, isinstance(string, basestring))
23+
self.assertEqual(True, isinstance(string, basestring))
2424

2525
def test_raw_strings_are_also_strings(self):
2626
string = r"Konnichi wa, world!"
27-
self.assertEqual(__, isinstance(string, basestring))
27+
self.assertEqual(True, isinstance(string, basestring))
2828

2929
def test_use_single_quotes_to_create_string_with_double_quotes(self):
3030
string = 'He said, "Go Away."'
31-
self.assertEqual(__, string)
31+
self.assertEqual('He said, "Go Away."', string)
3232

3333
def test_use_double_quotes_to_create_strings_with_single_quotes(self):
3434
string = "Don't"
35-
self.assertEqual(__, string)
35+
self.assertEqual("Don't", string)
3636

3737
def test_use_backslash_for_escaping_quotes_in_strings(self):
3838
a = "He said, \"Don't\""
3939
b = 'He said, "Don\'t"'
40-
self.assertEqual(__, (a == b))
40+
self.assertEqual(True, (a == b))
4141

4242
def test_use_backslash_at_the_end_of_a_line_to_continue_onto_the_next_line(self):
4343
string = "It was the best of times,\n\
4444
It was the worst of times."
45-
self.assertEqual(__, len(string))
45+
self.assertEqual(52, len(string))
4646

4747
def test_triple_quoted_strings_can_span_lines(self):
4848
string = """
4949
Howdy,
5050
world!
5151
"""
52-
self.assertEqual(__, len(string))
52+
self.assertEqual(15, len(string))
5353

5454
def test_triple_quoted_strings_need_less_escaping(self):
5555
a = "Hello \"world\"."
5656
b = """Hello "world"."""
57-
self.assertEqual(__, (a == b))
57+
self.assertEqual(True, (a == b))
5858

5959
def but_quotes_at_the_end_of_a_triple_quoted_string_are_still_tricky(self):
6060
string = """Hello "world\""""
6161

6262
def test_plus_concatenates_strings(self):
6363
string = "Hello, " + "world"
64-
self.assertEqual(__, string)
64+
self.assertEqual('Hello, world', string)
6565

6666
def test_adjacent_strings_are_concatenated_automatically(self):
6767
string = "Hello" ", " "world"
68-
self.assertEqual(__, string)
68+
self.assertEqual("Hello, world", string)
6969

7070
def test_plus_will_not_modify_original_strings(self):
7171
hi = "Hello, "
7272
there = "world"
7373
string = hi + there
74-
self.assertEqual(__, hi)
75-
self.assertEqual(__, there)
74+
self.assertEqual('Hello, ', hi)
75+
self.assertEqual('world', there)
7676

7777
def test_plus_equals_will_append_to_end_of_string(self):
7878
hi = "Hello, "
7979
there = "world"
8080
hi += there
81-
self.assertEqual(__, hi)
81+
self.assertEqual('Hello, world', hi)
8282

8383
def test_plus_equals_also_leaves_original_string_unmodified(self):
8484
original = "Hello, "
8585
hi = original
8686
there = "world"
8787
hi += there
88-
self.assertEqual(__, original)
88+
self.assertEqual('Hello, ', original)
8989

9090
def test_most_strings_interpret_escape_characters(self):
9191
string = "\n"
9292
self.assertEqual('\n', string)
9393
self.assertEqual("""\n""", string)
94-
self.assertEqual(__, len(string))
94+
self.assertEqual(1, len(string))
9595

9696
def test_use_format_to_interpolate_variables(self):
9797
value1 = 'one'
9898
value2 = 2
9999
string = "The values are {0} and {1}".format(value1, value2)
100-
self.assertEqual(__, string)
100+
self.assertEqual('The values are one and 2', string)
101101

102102
def test_formatted_values_con_be_shown_in_any_order_or_be_repeated(self):
103103
value1 = 'doh'
104104
value2 = 'DOH'
105105
string = "The values are {1}, {0}, {0} and {1}!".format(value1, value2)
106-
self.assertEqual(__, string)
106+
self.assertEqual('The values are DOH, doh, doh and DOH!', string)
107107

108108
def test_any_python_expression_may_be_interpolated(self):
109109
import math # import a standard python module with math functions
110110

111111
decimal_places = 4
112112
string = "The square root of 5 is {0:.{1}f}".format(math.sqrt(5), \
113113
decimal_places)
114-
self.assertEqual(__, string)
114+
self.assertEqual('The square root of 5 is 2.2361', string)
115115

116116
def test_you_can_get_a_substring_from_a_string(self):
117117
string = "Bacon, lettuce and tomato"
118-
self.assertEqual(__, string[7:10])
118+
self.assertEqual('let', string[7:10])
119119

120120
def test_you_can_get_a_single_character_from_a_string(self):
121121
string = "Bacon, lettuce and tomato"
122-
self.assertEqual(__, string[1])
122+
self.assertEqual('a', string[1])
123123

124124
def test_single_characters_can_be_represented_by_integers(self):
125-
self.assertEqual(__, ord('a'))
126-
self.assertEqual(__, ord('b') == (ord('a') + 1))
125+
self.assertEqual(97, ord('a'))
126+
self.assertEqual(True, ord('b') == (ord('a') + 1))
127127

128128
def test_strings_can_be_split(self):
129129
string = "Sausage Egg Cheese"
130130
words = string.split()
131-
self.assertEqual([__, __, __], words)
131+
self.assertEqual(['Sausage', 'Egg', 'Cheese'], words)
132132

133133
def test_strings_can_be_split_with_different_patterns(self):
134134
import re # import python regular expression library
@@ -138,26 +138,26 @@ def test_strings_can_be_split_with_different_patterns(self):
138138

139139
words = pattern.split(string)
140140

141-
self.assertEqual([__, __, __, __], words)
141+
self.assertEqual(['the', 'rain', 'in', 'spain'], words)
142142

143143
# `pattern` is a Python regular expression pattern which matches
144144
# ',' or ';'
145145

146146
def test_raw_strings_do_not_interpret_escape_characters(self):
147147
string = r'\n'
148148
self.assertNotEqual('\n', string)
149-
self.assertEqual(__, string)
150-
self.assertEqual(__, len(string))
149+
self.assertEqual('\\n', string)
150+
self.assertEqual(2, len(string))
151151

152152
# Useful in regular expressions, file paths, URLs, etc.
153153

154154
def test_strings_can_be_joined(self):
155155
words = ["Now", "is", "the", "time"]
156-
self.assertEqual(__, ' '.join(words))
156+
self.assertEqual('Now is the time', ' '.join(words))
157157

158158
def test_strings_can_change_case(self):
159-
self.assertEqual(__, 'guido'.capitalize())
160-
self.assertEqual(__, 'guido'.upper())
161-
self.assertEqual(__, 'TimBot'.lower())
162-
self.assertEqual(__, 'guido van rossum'.title())
163-
self.assertEqual(__, 'ToTaLlY aWeSoMe'.swapcase())
159+
self.assertEqual('Guido', 'guido'.capitalize())
160+
self.assertEqual('GUIDO', 'guido'.upper())
161+
self.assertEqual('timbot', 'TimBot'.lower())
162+
self.assertEqual('Guido Van Rossum', 'guido van rossum'.title())
163+
self.assertEqual('tOtAlLy AwEsOmE', 'ToTaLlY aWeSoMe'.swapcase())

0 commit comments

Comments
 (0)