misc.doctest 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. .. Copyright (C) 2001-2019 NLTK Project
  2. .. For license information, see LICENSE.TXT
  3. --------------------------------------------------------------------------------
  4. Unit tests for the miscellaneous sort functions.
  5. --------------------------------------------------------------------------------
  6. >>> from copy import deepcopy
  7. >>> from nltk.misc.sort import *
  8. A (very) small list of unsorted integers.
  9. >>> test_data = [12, 67, 7, 28, 92, 56, 53, 720, 91, 57, 20, 20]
  10. Test each sorting method - each method returns the number of operations
  11. required to sort the data, and sorts in-place (desctructively - hence the need
  12. for multiple copies).
  13. >>> sorted_data = deepcopy(test_data)
  14. >>> selection(sorted_data)
  15. 66
  16. >>> sorted_data
  17. [7, 12, 20, 20, 28, 53, 56, 57, 67, 91, 92, 720]
  18. >>> sorted_data = deepcopy(test_data)
  19. >>> bubble(sorted_data)
  20. 30
  21. >>> sorted_data
  22. [7, 12, 20, 20, 28, 53, 56, 57, 67, 91, 92, 720]
  23. >>> sorted_data = deepcopy(test_data)
  24. >>> merge(sorted_data)
  25. 30
  26. >>> sorted_data
  27. [7, 12, 20, 20, 28, 53, 56, 57, 67, 91, 92, 720]
  28. >>> sorted_data = deepcopy(test_data)
  29. >>> quick(sorted_data)
  30. 13
  31. >>> sorted_data
  32. [7, 12, 20, 20, 28, 53, 56, 57, 67, 91, 92, 720]
  33. --------------------------------------------------------------------------------
  34. Unit tests for Wordfinder class
  35. --------------------------------------------------------------------------------
  36. >>> import random
  37. >>> # The following is not enough for reproducibility under Python 2/3
  38. >>> # (see http://bugs.python.org/issue9025) so this test is skipped.
  39. >>> random.seed(12345)
  40. >>> from nltk.misc import wordfinder
  41. >>> wordfinder.word_finder() # doctest: +SKIP
  42. Word Finder
  43. <BLANKLINE>
  44. J V L A I R O T A T I S I V O D E R E T
  45. H U U B E A R O E P O C S O R E T N E P
  46. A D A U Z E E S R A P P A L L M E N T R
  47. C X A D Q S Z T P E O R S N G P J A D E
  48. I G Y K K T I A A R G F I D T E L C N S
  49. R E C N B H T R L T N N B W N T A O A I
  50. A Y I L O E I A M E I A A Y U R P L L D
  51. G L T V S T S F E A D I P H D O O H N I
  52. R L S E C I N I L R N N M E C G R U E A
  53. A A Y G I C E N L L E O I G Q R T A E L
  54. M R C E T I S T A E T L L E U A E N R L
  55. O U O T A S E E C S O O N H Y P A T G Y
  56. E M H O M M D R E S F P U L T H C F N V
  57. L A C A I M A M A N L B R U T E D O M I
  58. O R I L N E E E E E U A R S C R Y L I P
  59. H T R K E S N N M S I L A S R E V I N U
  60. T X T A A O U T K S E T A R R E S I B J
  61. A E D L E L J I F O O R P E L K N I R W
  62. K H A I D E Q O P R I C K T I M B E R P
  63. Z K D O O H G N I H T U R V E Y D R O P
  64. <BLANKLINE>
  65. 1: INTERCHANGER
  66. 2: TEARLESSNESS
  67. 3: UNIVERSALISM
  68. 4: DESENSITIZER
  69. 5: INTERMENTION
  70. 6: TRICHOCYSTIC
  71. 7: EXTRAMURALLY
  72. 8: VEGETOALKALI
  73. 9: PALMELLACEAE
  74. 10: AESTHETICISM
  75. 11: PETROGRAPHER
  76. 12: VISITATORIAL
  77. 13: OLEOMARGARIC
  78. 14: WRINKLEPROOF
  79. 15: PRICKTIMBER
  80. 16: PRESIDIALLY
  81. 17: SCITAMINEAE
  82. 18: ENTEROSCOPE
  83. 19: APPALLMENT
  84. 20: TURVEYDROP
  85. 21: THINGHOOD
  86. 22: BISERRATE
  87. 23: GREENLAND
  88. 24: BRUTEDOM
  89. 25: POLONIAN
  90. 26: ACOLHUAN
  91. 27: LAPORTEA
  92. 28: TENDING
  93. 29: TEREDO
  94. 30: MESOLE
  95. 31: UNLIMP
  96. 32: OSTARA
  97. 33: PILY
  98. 34: DUNT
  99. 35: ONYX
  100. 36: KATH
  101. 37: JUNE