python_koans / python2 / koans / about_true_and_false.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from runner.koan import *


class AboutTrueAndFalse(Koan):
    def truth_value(self, condition):
        if condition:
            return 'true stuff'
        else:
            return 'false stuff'
        
    def test_true_is_treated_as_true(self):
        self.assertEqual(__, self.truth_value(True))
        
    def test_false_is_treated_as_false(self):
        self.assertEqual(__, self.truth_value(False))
        
    def test_none_is_treated_as_false(self):
        self.assertEqual(__, self.truth_value(None))

    def test_zero_is_treated_as_false(self):
        self.assertEqual(__, self.truth_value(0))

    def test_empty_collections_are_treated_as_false(self):
        self.assertEqual(__, self.truth_value([]))
        self.assertEqual(__, self.truth_value(()))
        self.assertEqual(__, self.truth_value({}))
        self.assertEqual(__, self.truth_value(set()))

    def test_blank_strings_are_treated_as_false(self):
        self.assertEqual(__, self.truth_value(""))
        
    def test_everything_else_is_treated_as_true(self):
        self.assertEqual(__, self.truth_value(1))
        self.assertEqual(__, self.truth_value(1,))
        self.assertEqual(
            __,
            self.truth_value("Python is named after Monty Python"))
        self.assertEqual(__, self.truth_value(' '))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.