Christoph Schindler avatar Christoph Schindler committed a36d2ea

Ergebnis der dritten Dojo-Session.

Comments (0)

Files changed (2)

Number2LCD/number2lcd.py

+DATA = ((" _ ",
+         "| |",
+         "|_|"),
+        ("   ",
+         "  |",
+         "  |"),
+        (" _ ",
+         " _|",
+         "|_ "))
+
+#""""
+DATA = (
+  (" _ ", "   ", " _ "),
+  ("| |", "  |", " _|"),
+  ("|_|", "  |", "|_ "),
+) # """
+
+DATA = zip(*DATA)
+
+def convert_to_lcd(number):
+    if 0 <= number < 10:
+        return '\n'.join(DATA[int(number)])
+    
+    output = ['']*3
+    
+    for digit in str(number):
+        led = DATA[int(digit)]
+        for line in range(len(output)):
+            if output[line]:
+                output[line] += ' '
+            output[line] += led[line]
+    
+    return '\n'.join(output)
+    
+    
+if __name__ == '__main__':
+    import sys
+    for arg in sys.argv[1:]: 
+        print convert_to_lcd(arg)
+        print '='*50
+
+    

Number2LCD/test_number2lcd.py

+from nose.tools import assert_equal
+
+import number2lcd
+
+def test_0_returns_lcd():
+    LCD = '\n'.join((" _ ",
+                     "| |",
+                     "|_|"))
+    assert_equal(number2lcd.convert_to_lcd(0),LCD)
+
+
+def test_1_returns_lcd():
+    LCD = '\n'.join(("   ",
+                     "  |",
+                     "  |"))
+    assert_equal(number2lcd.convert_to_lcd(1),LCD)
+
+def test_2_returns_lcd():
+    LCD = '\n'.join((" _ ",
+                     " _|",
+                     "|_ "))
+    assert_equal(number2lcd.convert_to_lcd(2),LCD)
+    
+
+NULL_121212 = """
+ _       _       _       _ 
+| |   |  _|   |  _|   |  _|
+|_|   | |_    | |_    | |_ 
+""".strip('\n')
+
+def test_regressiontest__leading_zero():
+    assert_equal(number2lcd.convert_to_lcd("0121212"),NULL_121212)
+    
+def test_12_returns_lcd():
+    LCD = '\n'.join(("     _ ",
+                     "  |  _|",
+                     "  | |_ "))
+    assert_equal(number2lcd.convert_to_lcd(12),LCD)
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.