Skip to content

Commit d44aec5

Browse files
kjcmpirnat
authored andcommitted
Fixes gregmalcolm#137: test_everything_else_is_treated_as_true (gregmalcolm#142)
In the Python 2 and 3 versions of koans/about_true_and_false.py: self.truth_value(1,) is an integer argument followed by an optional comma. It just happened to produce the desired answer, because bool(1) is True. self.truth_value((1,)) is a tuple argument. Changed the tuple to (0,) to demonstrate that its truthiness comes from the presence of _any_ elements, and not from the truth value of the element itself. Also, added an easier example before it --- self.truth_value([0]) --- to introduce the same idea with the simpler list-literal syntax (no "magic" comma to worry about). Finally, changed the whitespace and line wrapping so the Python 2 and 3 files are identical. Reported by: egonluo https://github.com/egonluo Issue gregmalcolm#137: gregmalcolm#137
1 parent 4e1bb9a commit d44aec5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

python2/koans/about_true_and_false.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def test_blank_strings_are_treated_as_false(self):
3434

3535
def test_everything_else_is_treated_as_true(self):
3636
self.assertEqual(__, self.truth_value(1))
37-
self.assertEqual(__, self.truth_value(1,))
37+
self.assertEqual(__, self.truth_value([0]))
38+
self.assertEqual(__, self.truth_value((0,)))
3839
self.assertEqual(
3940
__,
4041
self.truth_value("Python is named after Monty Python"))

python3/koans/about_true_and_false.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from runner.koan import *
55

6+
67
class AboutTrueAndFalse(Koan):
78
def truth_value(self, condition):
89
if condition:
@@ -33,7 +34,10 @@ def test_blank_strings_are_treated_as_false(self):
3334

3435
def test_everything_else_is_treated_as_true(self):
3536
self.assertEqual(__, self.truth_value(1))
36-
self.assertEqual(__, self.truth_value(1,))
37-
self.assertEqual(__, self.truth_value("Python is named after Monty Python"))
37+
self.assertEqual(__, self.truth_value([0]))
38+
self.assertEqual(__, self.truth_value((0,)))
39+
self.assertEqual(
40+
__,
41+
self.truth_value("Python is named after Monty Python"))
3842
self.assertEqual(__, self.truth_value(' '))
3943
self.assertEqual(__, self.truth_value('0'))

0 commit comments

Comments
 (0)