<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 18, 2015 at 2:59 PM, kirby urner <span dir="ltr"><<a href="mailto:kirby.urner@gmail.com" target="_blank">kirby.urner@gmail.com</a>></span> wrote:<br><div><br></div><div><< SNIP >> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">I'm currently teaching a course in Python for the State of California.  My adult students join me in real time for 10 four hour segments.  I've just completed my fourth.  We're coding classes (types) already, were looking at simple class constructs from Day One.  I've suggested they adopt the mindset of a future high school student, privileged to have a real REPL.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div></div></blockquote><div><br></div><div>My pedagogy / andragogy is much influenced by my since-2011 use of Steve Holden's four part Python series.  He introduces unittesting by the very start of the second course i.e. right after the basic basics (up through writing a first class, along with significant string manipulation).  <br><br>I think that's productive, as it gives flavor and context to not just the importance of unittests, but the philosophy known as Agile and its various tenants such as: <br><br>(1) no ownership of code <br>(2) release early / often <br>(3) TDD or test-driven development as a way of making these early-often micro-steps.  <br><br>Write the tests first, as a way of giving your day traction.  You end up with a pile of audits.  That can be worth a lot when it comes to guarding against corrupting code.<br><br></div><div>Given I get to yak for literally hours, you can bet I was persuasive. :-D   Although my focus is core Python out to some standard library, some talk of 3rd party is encouraged (we're using Anaconda after all).  Plus I'm eager to reach out to that anchoring context (of developing according to some established best practices).  Using a language, like using a musical instrument, needs to be embedded in its larger context.<br><br>I know Steve, a veteran coder, is not unique in stressing TDD.  Just letting students know of these ramified schools of thought...  whole workflows, practices, such as SCRUM.<br><br>I've put my own spin on some of this e.g. around (1) "no ownership of code" I talk a lot about learning to play chess against yourself.  <br><br>It's when you have that ability to "turn on yourself" now suddenly white's worst enemy in a good way (ideal sparring partner) that you demonstrate your ability to "let go and play for the other side" (the testers are like the skeptics, with the developers the earnest dreamers striving to best more tests (the athletes, the stars -- as a solo coder, your mindset goes back and forth, whereas in a bigger company, these may be different teams (that's what I tell my students)). <br></div><div><br></div><div>Anyway, my previous post included what I introduce as "raw" or "naive" tests appended to the module itself.  We learn that it's better to split off the testing code, but you'll notice the unit tests are pointedly probing the same features.   Two ways of saying the same thing.<br></div><div><br>Kirby<br><br></div><div><span style="font-family:monospace,monospace"><br># -*- coding: utf-8 -*-<br>"""<br>Created on Thu Nov 19 10:48:49 2015<br><br>@author: kurner<br>"""<br><br>import unittest<br>from px_class import P<br><br>class Test_Permutation(unittest.TestCase):<br>    <br>    def test_1(self):<br>        """<br>        any p * ~p should give Identity<br>        """<br>        p = P() # identity permutation<br>        new_p = p.shuffle()<br>        inv_p = ~new_p <br>        self.assertEqual(p, inv_p * new_p, "expected identity fails")<br>        <br>    def test_2(self):<br>        """<br>        encrypt and decrypt are inverse operations on string<br>        """<br>        p = P().shuffle() # arbitrary permutation<br>        s = "the rain in spain stays mainly in the plain"<br>        c = p.encrypt(s)<br>        self.assertEqual(p.decrypt(c), s, "decrypted phrase differs")<br>                    <br>if __name__ == "__main__":<br>    unittest.main()<br></span><br><br></div></div></div></div>