Lead Application Developer
Ask me about...
A kōan is a story, dialogue, question, or statement, which is used in Zen practice to provoke the "great doubt" and test a student's progress in Zen practice.
--Wikipedia
"You can hear the sound of two hands when they clap together, now show me the sound of one hand."
triangle project (1 & 2)
dice project
scoring project
proxy object project
assertEqual(self, first, second, msg=None) # Tests that first = second
# Example
self.assertEqual(3, 3) # Passes
self.assertEqual(2, 3) # Fails
assertMatch(self, pattern, string, msg=None) # Tests that pattern is in string
# Example
self.assertMatch("lumberjack", "I'm a lumberjack and I'm OK") # Passes
self.assertMatch("Spam", "Always look on the bright side of life") # Fails
# P.S. there is also assertNoMatch(self, pattern, string, msg=None)
assertTrue(self, expr, msg=None) # Tests if expr is true
# Example
self.assertTrue(1 == 1) # Passes
self.assertTrue(2 == 1) # Fails
__ = "-=> FILL ME IN! <=-"
____ = "-=> TRUE OR FALSE? <=-"
The double and quadruple underscore variables are placeholders for your answers to the koans.
Replace these with the correct value.
from runner.koan import *
class AboutLists(Koan):
def test_accessing_list_elements(self):
noms = ['peanut', 'butter', 'and', 'jelly']
self.assertEqual(__, noms[0])
self.assertEqual(__, noms[3])
self.assertEqual(__, noms[-1])
self.assertEqual(__, noms[-3])
Occasionally you will encounter some failing tests that are already filled out. In these cases you will need to finish implementing some code to progress. For example, there is an exercise for writing some code that will tell you if a triangle is equilateral, isosceles or scalene.
def triangle(a, b, c):
# DELETE 'PASS' AND WRITE THIS CODE
pass
class AboutTriangleProject(Koan):
def test_equilateral_triangles_have_equal_sides(self):
self.assertEqual('equilateral', triangle(2, 2, 2))
self.assertEqual('equilateral', triangle(10, 10, 10))
def test_isosceles_triangles_have_exactly_two_sides_equal(self):
self.assertEqual('isosceles', triangle(3, 4, 4))
self.assertEqual('isosceles', triangle(4, 3, 4))
self.assertEqual('isosceles', triangle(4, 4, 3))
self.assertEqual('isosceles', triangle(10, 10, 2))
def test_scalene_triangles_have_no_equal_sides(self):
self.assertEqual('scalene', triangle(3, 4, 5))
self.assertEqual('scalene', triangle(10, 11, 12))
self.assertEqual('scalene', triangle(5, 4, 2))
$ git clone git@github.com:gregmalcolm/python_koans.git
Cloning into 'python_koans'...
remote: Counting objects: 1769, done.
remote: Total 1769 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1769/1769), 498.42 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1039/1039), done.
Checking connectivity... done.
$ cd python_koans/python2/
$ python contemplate_koans.py