Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. from nose.tools import *
  2. from testing import *
  3.  
  4.  
  5. def test_directions():
  6. assert_equal(scan("north"), [('direction', 'north')])
  7. result = scan("north south east")
  8. assert_equal(result, [('direction', 'north'), ('direction', 'south'), ('direction', 'east')])
  9.  
  10. import string
  11.  
  12. def convert_number(s):
  13. try:
  14. return int(s)
  15. except ValueError:
  16. return None
  17.  
  18. def scan(s):
  19.  
  20. direction_words= ("north", "south", "east", "west", "down", "up", "left", "right", "back", "forwards", "backwards")
  21. verbs= ("go", "stop", "kill", "eat", "shoot", "run", "hide", "dodge")
  22. stop_words= ("the", "in", "of", "from", "at", "it")
  23. nouns= ("door", "bear", "princess", "cabinet", "gold", "money", "chest", "gun", "sword")
  24. numbers= s.split()
  25. i=0
  26. j=0
  27. g=0
  28. m=0
  29. a=0
  30. b=0
  31.  
  32. while a < len(numbers):
  33. if type(convert_number(numbers[a])) == int:
  34. print [('number', int(numbers[a]) )]
  35. a += 1
  36. else:
  37. a += 1
  38.  
  39.  
  40. while i < len(direction_words):
  41. if direction_words[i] in s.split():
  42. s= string.lower(s)
  43. print [('direction', direction_words[i] ) ]
  44. i+=1
  45. else:
  46. i+=1
  47.  
  48. while j < len(verbs):
  49. if verbs[j] in s.split():
  50. s= string.lower(s)
  51. print [('verb', verbs[j] )]
  52. j+=1
  53. else:
  54. j+=1
  55.  
  56. while g < len(stop_words):
  57. if stop_words[g] in s.split():
  58. s= string.lower(s)
  59. print [('stop', stop_words[g] )]
  60. g+=1
  61. else:
  62. g+=1
  63.  
  64. while m < len(nouns):
  65. if nouns[m] in s.split():
  66. s= string.lower(s)
  67. print [('noun', nouns[m] )]
  68. m+=1
  69.  
  70. else:
  71. m+=1
  72.  
  73. while b< len(s.split()):
  74. if numbers[b] not in nouns:
  75. if numbers[b] not in stop_words:
  76. if numbers[b] not in verbs:
  77. if numbers[b] not in direction_words:
  78. if type(convert_number(numbers[b])) != int:
  79. print [('error', numbers[b] )]
  80. b += 1
  81.  
  82. else:
  83. b+=1
  84. else: b+=1
  85. else: b+=1
  86. else: b+=1
  87. else: b+=1
  88.  
  89.  
  90. else:
  91. return
  92.  
  93. F
  94. ======================================================================
  95. FAIL: tests.ex48_tests.test_directions
  96. ----------------------------------------------------------------------
  97. Traceback (most recent call last):
  98. File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
  99. self.test(*self.arg)
  100. File "/Users/Adam/Desktop/projects/ex48/tests/ex48_tests.py", line 6, in test_directions
  101. assert_equal(scan("north"), [('direction', 'north')])
  102. AssertionError: None != [('direction', 'north')]
  103. -------------------- >> begin captured stdout << ---------------------
  104. [('direction', 'north')]
  105.  
  106. --------------------- >> end captured stdout << ----------------------
  107.  
  108. ----------------------------------------------------------------------
  109. Ran 1 test in 0.015s
  110.  
  111. FAILED (failures=1)
  112.  
  113. while i < len(direction_words):
  114. if direction_words[i] in s.split():
  115. s= string.lower(s)
  116. print [('direction', direction_words[i] ) ] # <--- HERE
  117. i+=1
  118.  
  119. def scan(s):
  120. result = []
  121. ...
  122.  
  123. while i < len(direction_words):
  124. if direction_words[i] in s.split():
  125. s= string.lower(s)
  126. # change the `print` statements to `result += …`
  127. result += [('direction', direction_words[i] ) ]
  128. i+=1
  129.  
  130. ...
  131. return result
  132.  
  133. assert_equal(scan("north"), [('direction', 'north')])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement