Browse Source

Add output to bottom of scripts

John Tyree 11 năm trước cách đây
mục cha
commit
f61504c1bd
29 tập tin đã thay đổi với 304 bổ sung0 xóa
  1. 14 0
      3-tier.py
  2. 14 0
      abstract_factory.py
  3. 3 0
      adapter.py
  4. 11 0
      borg.py
  5. 4 0
      bridge.py
  6. 4 0
      builder.py
  7. 3 0
      catalog.py
  8. 11 0
      chain.py
  9. 6 0
      command.py
  10. 4 0
      composite.py
  11. 5 0
      decorator.py
  12. 20 0
      facade.py
  13. 6 0
      factory_method.py
  14. 5 0
      flyweight.py
  15. 5 0
      graph_search.py
  16. 6 0
      iterator.py
  17. 19 0
      mediator.py
  18. 25 0
      memento.py
  19. 17 0
      mvc.py
  20. 7 0
      null.py
  21. 19 0
      observer.py
  22. 6 0
      pool.py
  23. 4 0
      prototype.py
  24. 6 0
      proxy.py
  25. 8 0
      publish_subscribe.py
  26. 12 0
      state.py
  27. 5 0
      strategy.py
  28. 50 0
      template.py
  29. 5 0
      visitor.py

+ 14 - 0
3-tier.py

@@ -56,3 +56,17 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# PRODUCT LIST:
+# eggs
+# milk
+# cheese
+# 
+# PRODUCT INFORMATION:
+# Name: Cheese, Price: 2.00, Quantity: 10
+# PRODUCT INFORMATION:
+# Name: Eggs, Price: 0.20, Quantity: 100
+# PRODUCT INFORMATION:
+# Name: Milk, Price: 1.50, Quantity: 10
+# That product "arepas" does not exist in the records

+ 14 - 0
abstract_factory.py

@@ -76,3 +76,17 @@ if __name__ == "__main__":
         shop.pet_factory = get_factory()
         shop.show_pet()
         print("=" * 20)
+
+### OUTPUT ###
+# This is a lovely Dog
+# It says woof
+# It eats dog food
+# ====================
+# This is a lovely Cat
+# It says meow
+# It eats cat food
+# ====================
+# This is a lovely Dog
+# It says woof
+# It eats dog food
+# ====================

+ 3 - 0
adapter.py

@@ -91,3 +91,6 @@ def main():
 if __name__ == "__main__":
     import doctest
     doctest.testmod()
+
+### OUTPUT ###
+

+ 11 - 0
borg.py

@@ -38,3 +38,14 @@ if __name__ == '__main__':
     print('rm1: {0}'.format(rm1))
     print('rm2: {0}'.format(rm2))
     print('rm3: {0}'.format(rm3))
+
+### OUTPUT ###
+# rm1: Running
+# rm2: Running
+# rm1: Zombie
+# rm2: Zombie
+# rm1 id: 139825262601040
+# rm2 id: 139825262601104
+# rm1: Zombie
+# rm2: Zombie
+# rm3: Zombie

+ 4 - 0
bridge.py

@@ -46,3 +46,7 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# API1.circle at 1:2 radius 7.5
+# API2.circle at 5:7 radius 27.5

+ 4 - 0
builder.py

@@ -68,3 +68,7 @@ if __name__ == "__main__":
     director.construct_building()
     building = director.get_building()
     print(building)
+
+### OUTPUT ###
+# Floor: One | Size: Big
+# Floor: More than One | Size: Small

+ 3 - 0
catalog.py

@@ -58,3 +58,6 @@ def main():
 
 if __name__ == "__main__":
     main()
+
+### OUTPUT ###
+# executed method 2!

+ 11 - 0
chain.py

@@ -53,3 +53,14 @@ if __name__ == "__main__":
     client = Client()
     requests = [2, 5, 14, 22, 18, 3, 35, 27, 20]
     client.delegate(requests)
+
+### OUTPUT ###
+# request 2 handled in handler 1
+# request 5 handled in handler 1
+# request 14 handled in handler 2
+# request 22 handled in handler 3
+# request 18 handled in handler 2
+# request 3 handled in handler 1
+# end of chain, no handler for 35
+# request 27 handled in handler 3
+# request 20 handled in handler 2

+ 6 - 0
command.py

@@ -38,3 +38,9 @@ def main():
 
 if __name__ == "__main__":
     main()
+
+### OUTPUT ###
+# renaming foo.txt to bar.txt
+# renaming bar.txt to baz.txt
+# renaming baz.txt to bar.txt
+# renaming bar.txt to foo.txt

+ 4 - 0
composite.py

@@ -332,3 +332,7 @@ if __name__ == "__main__":
     # print(window.Frame.Button2)
     print(window.Frame.Button1.label)
     print(window.Frame.Button2.label)
+
+### OUTPUT ###
+# Submit
+# Browse

+ 5 - 0
decorator.py

@@ -45,3 +45,8 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# decorated f1
+# original f1
+# original f2

+ 20 - 0
facade.py

@@ -61,3 +61,23 @@ class TestRunner:
 if __name__ == '__main__':
     testrunner = TestRunner()
     testrunner.runAll()
+
+### OUTPUT ###
+# ###### In Test 1 ######
+# Setting up
+# Running test
+# Tearing down
+# Test Finished
+# 
+# ###### In Test 2 ######
+# Setting up
+# Running test
+# Tearing down
+# Test Finished
+# 
+# ###### In Test 3 ######
+# Setting up
+# Running test
+# Tearing down
+# Test Finished
+# 

+ 6 - 0
factory_method.py

@@ -33,3 +33,9 @@ e, g = get_localizer("English"), get_localizer("Greek")
 # Localize some text
 for msgid in "dog parrot cat bear".split():
     print(e.get(msgid), g.get(msgid))
+
+### OUTPUT ###
+# dog σκύλος
+# parrot parrot
+# cat γάτα
+# bear bear

+ 5 - 0
flyweight.py

@@ -34,3 +34,8 @@ if __name__ == '__main__':
     print(c1, c2)
     print(c1 == c2)
     print(id(c1), id(c2))
+
+### OUTPUT ###
+# <Card: 9h> <Card: 9h>
+# True
+# 140368617673296 140368617673296

+ 5 - 0
graph_search.py

@@ -78,3 +78,8 @@ graph1 = GraphSearch(graph)
 print(graph1.find_path('A', 'D'))
 print(graph1.find_all_path('A', 'D'))
 print(graph1.find_shortest_path('A', 'D'))
+
+### OUTPUT ###
+# ['A', 'B', 'C', 'D']
+# [['A', 'B', 'C', 'D']]
+# ['A', 'B', 'C', 'D']

+ 6 - 0
iterator.py

@@ -29,3 +29,9 @@ for number in count_to_five():
     print(number, end=' ')
 
 print()
+
+### OUTPUT ###
+# Counting to two...
+# one two 
+# Counting to five...
+# one two three four five 

+ 19 - 0
mediator.py

@@ -118,3 +118,22 @@ if __name__ == '__main__':
         tc.setup()
         tc.execute()
         tc.tearDown()
+
+### OUTPUT ###
+# Setting up the Test
+# Inserting the execution begin status in the Database
+# Executing the test
+# Tearing down
+# Updating the test results in Database
+# Reporting the results of Test
+# Setting up the Test
+# Inserting the execution begin status in the Database
+# Reporter Class is preparing to report the results
+# Problem in setup. Test not executed.
+# Test not executed. No tear down required.
+# Setting up the Test
+# Inserting the execution begin status in the Database
+# Executing the test
+# Tearing down
+# Updating the test results in Database
+# Reporting the results of Test

+ 25 - 0
memento.py

@@ -95,3 +95,28 @@ if __name__ == '__main__':
         traceback.print_exc(file=sys.stdout)
         pass
     print(n)
+
+### OUTPUT ###
+# <NumObj: -1>
+# <NumObj: 0>
+# <NumObj: 1>
+# <NumObj: 2>
+# -- commited
+# <NumObj: 3>
+# <NumObj: 4>
+# <NumObj: 5>
+# -- rolled back
+# <NumObj: 2>
+# -- now doing stuff ...
+# -> doing stuff failed!
+# Traceback (most recent call last):
+#   File "memento.py", line 91, in <module>
+#     n.DoStuff()
+#   File "memento.py", line 47, in transaction
+#     return self.method(obj, *args, **kwargs)
+#   File "memento.py", line 67, in DoStuff
+#     self.Increment()     # <- will fail and rollback
+#   File "memento.py", line 62, in Increment
+#     self.value += 1
+# TypeError: Can't convert 'int' object to str implicitly
+# <NumObj: 2>

+ 17 - 0
mvc.py

@@ -55,3 +55,20 @@ if __name__ == '__main__':
     controller.get_product_information('eggs')
     controller.get_product_information('milk')
     controller.get_product_information('arepas')
+
+### OUTPUT ###
+# PRODUCT LIST:
+# cheese
+# eggs
+# milk
+# 
+# PRODUCT INFORMATION:
+# Name: Cheese, Price: 2.00, Quantity: 10
+# 
+# PRODUCT INFORMATION:
+# Name: Eggs, Price: 0.20, Quantity: 100
+# 
+# PRODUCT INFORMATION:
+# Name: Milk, Price: 1.50, Quantity: 10
+# 
+# That product "arepas" does not exist in the records

+ 7 - 0
null.py

@@ -80,3 +80,10 @@ def test():
 
 if __name__ == '__main__':
     test()
+
+### OUTPUT ###
+# Null
+# Null
+# Null
+# Null
+# attr1 Null

+ 19 - 0
observer.py

@@ -83,3 +83,22 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# Setting Data 1 = 10
+# DecimalViewer: Subject Data 1 has data 10
+# HexViewer: Subject Data 1 has data 0xa
+# Setting Data 2 = 15
+# HexViewer: Subject Data 2 has data 0xf
+# DecimalViewer: Subject Data 2 has data 15
+# Setting Data 1 = 3
+# DecimalViewer: Subject Data 1 has data 3
+# HexViewer: Subject Data 1 has data 0x3
+# Setting Data 2 = 5
+# HexViewer: Subject Data 2 has data 0x5
+# DecimalViewer: Subject Data 2 has data 5
+# Detach HexViewer from data1 and data2.
+# Setting Data 1 = 10
+# DecimalViewer: Subject Data 1 has data 10
+# Setting Data 2 = 15
+# DecimalViewer: Subject Data 2 has data 15

+ 6 - 0
pool.py

@@ -52,3 +52,9 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# Inside with: yam
+# Outside with: yam
+# Inside func: sam
+# Outside func: sam

+ 4 - 0
prototype.py

@@ -38,3 +38,7 @@ def main():
 
 if __name__ == '__main__':
     main()
+
+### OUTPUT ###
+# <__main__.main.<locals>.A object at 0x7fc1d23272d0>
+# 1 2 3

+ 6 - 0
proxy.py

@@ -33,3 +33,9 @@ if __name__ == '__main__':
     p.work()
     p.busy = 'Yes'
     p.work()
+
+### OUTPUT ###
+# Proxy checking for Sales Manager availability
+# Sales Manager ready to talk
+# Proxy checking for Sales Manager availability
+# Sales Manager is busy

+ 8 - 0
publish_subscribe.py

@@ -79,3 +79,11 @@ def main():
 
 if __name__ == "__main__":
     main()
+
+### OUTPUT ###
+# jim got cartoon
+# jack got music
+# gee got movie
+# jim got cartoon
+# jim got cartoon
+# gee got movie

+ 12 - 0
state.py

@@ -61,3 +61,15 @@ if __name__ == '__main__':
 
     for action in actions:
         action()
+
+### OUTPUT ###
+# Scanning... Station is 1380 AM
+# Scanning... Station is 1510 AM
+# Switching to FM
+# Scanning... Station is 89.1 FM
+# Scanning... Station is 103.9 FM
+# Scanning... Station is 81.3 FM
+# Scanning... Station is 89.1 FM
+# Switching to AM
+# Scanning... Station is 1250 AM
+# Scanning... Station is 1380 AM

+ 5 - 0
strategy.py

@@ -41,3 +41,8 @@ if __name__ == '__main__':
     strat0.execute()
     strat1.execute()
     strat2.execute()
+
+### OUTPUT ###
+# Strategy Example 0
+# Strategy Example 1 from execute 1
+# Strategy Example 2 from execute 2

+ 50 - 0
template.py

@@ -55,3 +55,53 @@ templates = [make_template(s, g, a)
 # Execute them
 for template in templates:
     template()
+
+### OUTPUT ###
+# spam
+# ----------
+# eggs
+# ----------
+# apple
+# ----------
+# apple
+# ----------
+# eggs
+# ----------
+# spam
+# ----------
+# maps
+# ----------
+# sgge
+# ----------
+# elppa
+# ----------
+# elppa
+# ----------
+# sgge
+# ----------
+# maps
+# ----------
+# ['s', 'p', 'a', 'm']
+# ----------
+# ['e', 'g', 'g', 's']
+# ----------
+# ['a', 'p', 'p', 'l', 'e']
+# ----------
+# ['a', 'p', 'p', 'l', 'e']
+# ----------
+# ['e', 'g', 'g', 's']
+# ----------
+# ['s', 'p', 'a', 'm']
+# ----------
+# ['m', 'a', 'p', 's']
+# ----------
+# ['s', 'g', 'g', 'e']
+# ----------
+# ['e', 'l', 'p', 'p', 'a']
+# ----------
+# ['e', 'l', 'p', 'p', 'a']
+# ----------
+# ['s', 'g', 'g', 'e']
+# ----------
+# ['m', 'a', 'p', 's']
+# ----------

+ 5 - 0
visitor.py

@@ -44,3 +44,8 @@ visitor = Visitor()
 visitor.visit(a)
 visitor.visit(b)
 visitor.visit(c)
+
+### OUTPUT ###
+# generic_visit A
+# visit_B B
+# visit_B C