Skip to content

Commit 8f90a85

Browse files
author
Pieter
committed
Updating
1 parent 41f52e7 commit 8f90a85

8 files changed

Lines changed: 119 additions & 118 deletions

python3/koans/about_asserts.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ def test_assert_truth(self):
1414
#
1515
# http://bit.ly/about_asserts
1616

17-
self.assertTrue(False) # This should be true
17+
self.assertTrue(True) # This should be true
1818

1919
def test_assert_with_message(self):
2020
"""
2121
Enlightenment may be more easily achieved with appropriate messages.
2222
"""
23-
self.assertTrue(False, "This should be true -- Please fix this")
23+
self.assertTrue(True, "This should be true -- Please fix this")
2424

2525
def test_fill_in_values(self):
2626
"""
2727
Sometimes we will ask you to fill in the values
2828
"""
29-
self.assertEqual(__, 1 + 1)
29+
self.assertEqual(2, 1 + 1)
3030

3131
def test_assert_equality(self):
3232
"""
3333
To understand reality, we must compare our expectations against reality.
3434
"""
35-
expected_value = __
35+
expected_value = 2
3636
actual_value = 1 + 1
3737
self.assertTrue(expected_value == actual_value)
3838

3939
def test_a_better_way_of_asserting_equality(self):
4040
"""
4141
Some ways of asserting equality are better than others.
4242
"""
43-
expected_value = __
43+
expected_value = 2
4444
actual_value = 1 + 1
4545

4646
self.assertEqual(expected_value, actual_value)
@@ -51,7 +51,7 @@ def test_that_unittest_asserts_work_the_same_way_as_python_asserts(self):
5151
"""
5252

5353
# This throws an AssertionError exception
54-
assert False
54+
assert True
5555

5656
def test_that_sometimes_we_need_to_know_the_class_type(self):
5757
"""
@@ -70,7 +70,7 @@ def test_that_sometimes_we_need_to_know_the_class_type(self):
7070
#
7171
# See for yourself:
7272

73-
self.assertEqual(__, "naval".__class__) # It's str, not <type 'str'>
73+
self.assertEqual(str, "naval".__class__) # It's str, not <type 'str'>
7474

7575
# Need an illustration? More reading can be found here:
7676
#

python3/koans/about_dictionaries.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,46 @@ def test_creating_dictionaries(self):
1212
empty_dict = dict()
1313
self.assertEqual(dict, type(empty_dict))
1414
self.assertDictEqual({}, empty_dict)
15-
self.assertEqual(__, len(empty_dict))
15+
self.assertEqual(0, len(empty_dict))
1616

1717
def test_dictionary_literals(self):
1818
empty_dict = {}
1919
self.assertEqual(dict, type(empty_dict))
2020
babel_fish = { 'one': 'uno', 'two': 'dos' }
21-
self.assertEqual(__, len(babel_fish))
21+
self.assertEqual(2, len(babel_fish))
2222

2323
def test_accessing_dictionaries(self):
2424
babel_fish = { 'one': 'uno', 'two': 'dos' }
25-
self.assertEqual(__, babel_fish['one'])
26-
self.assertEqual(__, babel_fish['two'])
25+
self.assertEqual('uno', babel_fish['one'])
26+
self.assertEqual('dos', babel_fish['two'])
2727

2828
def test_changing_dictionaries(self):
2929
babel_fish = { 'one': 'uno', 'two': 'dos' }
3030
babel_fish['one'] = 'eins'
3131

32-
expected = { 'two': 'dos', 'one': __ }
32+
expected = { 'two': 'dos', 'one': 'eins' }
3333
self.assertDictEqual(expected, babel_fish)
3434

3535
def test_dictionary_is_unordered(self):
3636
dict1 = { 'one': 'uno', 'two': 'dos' }
3737
dict2 = { 'two': 'dos', 'one': 'uno' }
3838

39-
self.assertEqual(__, dict1 == dict2)
39+
self.assertEqual(True, dict1 == dict2)
4040

4141

4242
def test_dictionary_keys_and_values(self):
4343
babel_fish = {'one': 'uno', 'two': 'dos'}
44-
self.assertEqual(__, len(babel_fish.keys()))
45-
self.assertEqual(__, len(babel_fish.values()))
46-
self.assertEqual(__, 'one' in babel_fish.keys())
47-
self.assertEqual(__, 'two' in babel_fish.values())
48-
self.assertEqual(__, 'uno' in babel_fish.keys())
49-
self.assertEqual(__, 'dos' in babel_fish.values())
44+
self.assertEqual(2, len(babel_fish.keys()))
45+
self.assertEqual(2, len(babel_fish.values()))
46+
self.assertEqual(True, 'one' in babel_fish.keys())
47+
self.assertEqual(False, 'two' in babel_fish.values())
48+
self.assertEqual(False, 'uno' in babel_fish.keys())
49+
self.assertEqual(True, 'dos' in babel_fish.values())
5050

5151
def test_making_a_dictionary_from_a_sequence_of_keys(self):
5252
cards = {}.fromkeys(('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', 'confused looking zebra'), 42)
5353

54-
self.assertEqual(__, len(cards))
55-
self.assertEqual(__, cards['green elf'])
56-
self.assertEqual(__, cards['yellow dwarf'])
54+
self.assertEqual(5, len(cards))
55+
self.assertEqual(42, cards['green elf'])
56+
self.assertEqual(42, cards['yellow dwarf'])
5757

python3/koans/about_list_assignments.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010
class AboutListAssignments(Koan):
1111
def test_non_parallel_assignment(self):
1212
names = ["John", "Smith"]
13-
self.assertEqual(__, names)
13+
self.assertEqual(['John','Smith'], names)
1414

1515
def test_parallel_assignments(self):
1616
first_name, last_name = ["John", "Smith"]
17-
self.assertEqual(__, first_name)
18-
self.assertEqual(__, last_name)
17+
self.assertEqual('John', first_name)
18+
self.assertEqual('Smith', last_name)
1919

2020
def test_parallel_assignments_with_extra_values(self):
2121
title, *first_names, last_name = ["Sir", "Ricky", "Bobby", "Worthington"]
22-
self.assertEqual(__, title)
23-
self.assertEqual(__, first_names)
24-
self.assertEqual(__, last_name)
22+
self.assertEqual('Sir', title)
23+
self.assertEqual(['Ricky','Bobby'], first_names)
24+
self.assertEqual('Worthington', last_name)
2525

2626
def test_parallel_assignments_with_sublists(self):
2727
first_name, last_name = [["Willie", "Rae"], "Johnson"]
28-
self.assertEqual(__, first_name)
29-
self.assertEqual(__, last_name)
28+
self.assertEqual(['Willie','Rae'], first_name)
29+
self.assertEqual('Johnson', last_name)
3030

3131
def test_swapping_with_parallel_assignment(self):
3232
first_name = "Roy"
3333
last_name = "Rob"
3434
first_name, last_name = last_name, first_name
35-
self.assertEqual(__, first_name)
36-
self.assertEqual(__, last_name)
35+
self.assertEqual('Rob', first_name)
36+
self.assertEqual('Roy', last_name)
3737

python3/koans/about_lists.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AboutLists(Koan):
1111
def test_creating_lists(self):
1212
empty_list = list()
1313
self.assertEqual(list, type(empty_list))
14-
self.assertEqual(__, len(empty_list))
14+
self.assertEqual(0, len(empty_list))
1515

1616
def test_list_literals(self):
1717
nums = list()
@@ -21,69 +21,69 @@ def test_list_literals(self):
2121
self.assertEqual([1], nums)
2222

2323
nums[1:] = [2]
24-
self.assertListEqual([1, __], nums)
24+
self.assertListEqual([1, 2], nums)
2525

2626
nums.append(333)
27-
self.assertListEqual([1, 2, __], nums)
27+
self.assertListEqual([1, 2, 333], nums)
2828

2929
def test_accessing_list_elements(self):
3030
noms = ['peanut', 'butter', 'and', 'jelly']
3131

32-
self.assertEqual(__, noms[0])
33-
self.assertEqual(__, noms[3])
34-
self.assertEqual(__, noms[-1])
35-
self.assertEqual(__, noms[-3])
32+
self.assertEqual('peanut', noms[0])
33+
self.assertEqual('jelly', noms[3])
34+
self.assertEqual('jelly', noms[-1])
35+
self.assertEqual('butter', noms[-3])
3636

3737
def test_slicing_lists(self):
3838
noms = ['peanut', 'butter', 'and', 'jelly']
3939

40-
self.assertEqual(__, noms[0:1])
41-
self.assertEqual(__, noms[0:2])
42-
self.assertEqual(__, noms[2:2])
43-
self.assertEqual(__, noms[2:20])
44-
self.assertEqual(__, noms[4:0])
45-
self.assertEqual(__, noms[4:100])
46-
self.assertEqual(__, noms[5:0])
40+
self.assertEqual(['peanut'], noms[0:1])
41+
self.assertEqual(['peanut','butter'], noms[0:2])
42+
self.assertEqual([], noms[2:2])
43+
self.assertEqual(['and','jelly'], noms[2:20])
44+
self.assertEqual([], noms[4:0])
45+
self.assertEqual([], noms[4:100])
46+
self.assertEqual([], noms[5:0])
4747

4848
def test_slicing_to_the_edge(self):
4949
noms = ['peanut', 'butter', 'and', 'jelly']
5050

51-
self.assertEqual(__, noms[2:])
52-
self.assertEqual(__, noms[:2])
51+
self.assertEqual(['and','jelly'], noms[2:])
52+
self.assertEqual(['peanut','butter'], noms[:2])
5353

5454
def test_lists_and_ranges(self):
5555
self.assertEqual(range, type(range(5)))
5656
self.assertNotEqual([1, 2, 3, 4, 5], range(1,6))
57-
self.assertEqual(__, list(range(5)))
58-
self.assertEqual(__, list(range(5, 9)))
57+
self.assertEqual([0,1,2,3,4], list(range(5)))
58+
self.assertEqual([5,6,7,8], list(range(5, 9)))
5959

6060
def test_ranges_with_steps(self):
61-
self.assertEqual(__, list(range(0, 8, 2)))
62-
self.assertEqual(__, list(range(1, 8, 3)))
63-
self.assertEqual(__, list(range(5, -7, -4)))
64-
self.assertEqual(__, list(range(5, -8, -4)))
61+
self.assertEqual([0,2,4,6], list(range(0, 8, 2)))
62+
self.assertEqual([1,4,7], list(range(1, 8, 3)))
63+
self.assertEqual([5,1,-3], list(range(5, -7, -4)))
64+
self.assertEqual([5,1,-3,-7], list(range(5, -8, -4)))
6565

6666
def test_insertions(self):
6767
knight = ['you', 'shall', 'pass']
6868
knight.insert(2, 'not')
69-
self.assertEqual(__, knight)
69+
self.assertEqual(['you','shall','not','pass'], knight)
7070

7171
knight.insert(0, 'Arthur')
72-
self.assertEqual(__, knight)
72+
self.assertEqual(['Arthur','you','shall','not','pass'], knight)
7373

7474
def test_popping_lists(self):
7575
stack = [10, 20, 30, 40]
7676
stack.append('last')
7777

78-
self.assertEqual(__, stack)
78+
self.assertEqual([10, 20, 30, 40, 'last'], stack)
7979

8080
popped_value = stack.pop()
81-
self.assertEqual(__, popped_value)
82-
self.assertEqual(__, stack)
81+
self.assertEqual('last', popped_value)
82+
self.assertEqual([10,20,30,40], stack)
8383

8484
popped_value = stack.pop(1)
85-
self.assertEqual(__, popped_value)
86-
self.assertEqual(__, stack)
85+
self.assertEqual(20, popped_value)
86+
self.assertEqual([10,30,40], stack)
8787

8888
# Notice that there is a "pop" but no "push" in python?
8989

@@ -97,11 +97,11 @@ def test_making_queues(self):
9797
queue = [1, 2]
9898
queue.append('last')
9999

100-
self.assertEqual(__, queue)
100+
self.assertEqual([1,2,'last'], queue)
101101

102102
popped_value = queue.pop(0)
103-
self.assertEqual(__, popped_value)
104-
self.assertEqual(__, queue)
103+
self.assertEqual(1, popped_value)
104+
self.assertEqual([2,'last'], queue)
105105

106106
# Note, for Python 2 popping from the left hand side of a list is
107107
# inefficient. Use collections.deque instead.

python3/koans/about_none.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class AboutNone(Koan):
1111

1212
def test_none_is_an_object(self):
1313
"Unlike NULL in a lot of languages"
14-
self.assertEqual(__, isinstance(None, object))
14+
self.assertEqual(True, isinstance(None, object))
1515

1616
def test_none_is_universal(self):
1717
"There is only one None"
18-
self.assertEqual(____, None is None)
18+
self.assertEqual(True, None is None)
1919

2020
def test_what_exception_do_you_get_when_calling_nonexistent_methods(self):
2121
"""
@@ -37,15 +37,15 @@ def test_what_exception_do_you_get_when_calling_nonexistent_methods(self):
3737
#
3838
# http://bit.ly/__class__
3939

40-
self.assertEqual(__, ex2.__class__)
40+
self.assertEqual(AttributeError, ex2.__class__)
4141

4242
# What message was attached to the exception?
4343
# (HINT: replace __ with part of the error message.)
44-
self.assertRegexpMatches(ex2.args[0], __)
44+
self.assertRegexpMatches(ex2.args[0], "object has no attribute")
4545

4646
def test_none_is_distinct(self):
4747
"""
4848
None is distinct from other things which are False.
4949
"""
50-
self.assertEqual(__, None is not 0)
51-
self.assertEqual(__, None is not False)
50+
self.assertEqual(True, None is not 0)
51+
self.assertEqual(True, None is not False)

python3/koans/about_string_manipulation.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ def test_use_format_to_interpolate_variables(self):
99
value1 = 'one'
1010
value2 = 2
1111
string = "The values are {0} and {1}".format(value1, value2)
12-
self.assertEqual(__, string)
12+
self.assertEqual("The values are one and 2", string)
1313

1414
def test_formatted_values_con_be_shown_in_any_order_or_be_repeated(self):
1515
value1 = 'doh'
1616
value2 = 'DOH'
1717
string = "The values are {1}, {0}, {0} and {1}!".format(value1, value2)
18-
self.assertEqual(__, string)
18+
self.assertEqual("The values are DOH, doh, doh and DOH!", string)
1919

2020
def test_any_python_expression_may_be_interpolated(self):
2121
import math # import a standard python module with math functions
2222

2323
decimal_places = 4
2424
string = "The square root of 5 is {0:.{1}f}".format(math.sqrt(5), \
2525
decimal_places)
26-
self.assertEqual(__, string)
26+
self.assertEqual("The square root of 5 is 2.2361", string)
2727

2828
def test_you_can_get_a_substring_from_a_string(self):
2929
string = "Bacon, lettuce and tomato"
30-
self.assertEqual(__, string[7:10])
30+
self.assertEqual("let", string[7:10])
3131

3232
def test_you_can_get_a_single_character_from_a_string(self):
3333
string = "Bacon, lettuce and tomato"
34-
self.assertEqual(__, string[1])
34+
self.assertEqual("a", string[1])
3535

3636
def test_single_characters_can_be_represented_by_integers(self):
37-
self.assertEqual(__, ord('a'))
38-
self.assertEqual(__, ord('b') == (ord('a') + 1))
37+
self.assertEqual(97, ord('a'))
38+
self.assertEqual(True, ord('b') == (ord('a') + 1))
3939

4040
def test_strings_can_be_split(self):
4141
string = "Sausage Egg Cheese"
4242
words = string.split()
43-
self.assertListEqual([__, __, __], words)
43+
self.assertListEqual(["Sausage", "Egg", "Cheese"], words)
4444

4545
def test_strings_can_be_split_with_different_patterns(self):
4646
import re #import python regular expression library
@@ -50,25 +50,25 @@ def test_strings_can_be_split_with_different_patterns(self):
5050

5151
words = pattern.split(string)
5252

53-
self.assertListEqual([__, __, __, __], words)
53+
self.assertListEqual(["the", "rain", "in", "spain"], words)
5454

5555
# Pattern is a Python regular expression pattern which matches ',' or ';'
5656

5757
def test_raw_strings_do_not_interpret_escape_characters(self):
5858
string = r'\n'
5959
self.assertNotEqual('\n', string)
60-
self.assertEqual(__, string)
61-
self.assertEqual(__, len(string))
60+
self.assertEqual('\\n', string)
61+
self.assertEqual(2, len(string))
6262

6363
# Useful in regular expressions, file paths, URLs, etc.
6464

6565
def test_strings_can_be_joined(self):
6666
words = ["Now", "is", "the", "time"]
67-
self.assertEqual(__, ' '.join(words))
67+
self.assertEqual("Now is the time", ' '.join(words))
6868

6969
def test_strings_can_change_case(self):
70-
self.assertEqual(__, 'guido'.capitalize())
71-
self.assertEqual(__, 'guido'.upper())
72-
self.assertEqual(__, 'TimBot'.lower())
73-
self.assertEqual(__, 'guido van rossum'.title())
74-
self.assertEqual(__, 'ToTaLlY aWeSoMe'.swapcase())
70+
self.assertEqual("Guido", 'guido'.capitalize())
71+
self.assertEqual("GUIDO", 'guido'.upper())
72+
self.assertEqual("timbot", 'TimBot'.lower())
73+
self.assertEqual("Guido Van Rossum", 'guido van rossum'.title())
74+
self.assertEqual("tOtAlLy AwEsOmE", 'ToTaLlY aWeSoMe'.swapcase())

0 commit comments

Comments
 (0)