m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
12 KiB

6 months ago
  1. from sympy.core.singleton import S
  2. from sympy.core.symbol import Symbol
  3. from sympy.functions.elementary.exponential import log
  4. from sympy.functions.elementary.miscellaneous import sqrt
  5. from sympy.functions.elementary.trigonometric import sin
  6. from sympy.plotting.textplot import textplot_str
  7. def test_axes_alignment():
  8. x = Symbol('x')
  9. lines = [
  10. ' 1 | ..',
  11. ' | ... ',
  12. ' | .. ',
  13. ' | ... ',
  14. ' | ... ',
  15. ' | .. ',
  16. ' | ... ',
  17. ' | ... ',
  18. ' | .. ',
  19. ' | ... ',
  20. ' 0 |--------------------------...--------------------------',
  21. ' | ... ',
  22. ' | .. ',
  23. ' | ... ',
  24. ' | ... ',
  25. ' | .. ',
  26. ' | ... ',
  27. ' | ... ',
  28. ' | .. ',
  29. ' | ... ',
  30. ' -1 |_______________________________________________________',
  31. ' -1 0 1'
  32. ]
  33. assert lines == list(textplot_str(x, -1, 1))
  34. lines = [
  35. ' 1 | ..',
  36. ' | .... ',
  37. ' | ... ',
  38. ' | ... ',
  39. ' | .... ',
  40. ' | ... ',
  41. ' | ... ',
  42. ' | .... ',
  43. ' 0 |--------------------------...--------------------------',
  44. ' | .... ',
  45. ' | ... ',
  46. ' | ... ',
  47. ' | .... ',
  48. ' | ... ',
  49. ' | ... ',
  50. ' | .... ',
  51. ' -1 |_______________________________________________________',
  52. ' -1 0 1'
  53. ]
  54. assert lines == list(textplot_str(x, -1, 1, H=17))
  55. def test_singularity():
  56. x = Symbol('x')
  57. lines = [
  58. ' 54 | . ',
  59. ' | ',
  60. ' | ',
  61. ' | ',
  62. ' | ',' | ',
  63. ' | ',
  64. ' | ',
  65. ' | ',
  66. ' | ',
  67. ' 27.5 |--.----------------------------------------------------',
  68. ' | ',
  69. ' | ',
  70. ' | ',
  71. ' | . ',
  72. ' | \\ ',
  73. ' | \\ ',
  74. ' | .. ',
  75. ' | ... ',
  76. ' | ............. ',
  77. ' 1 |_______________________________________________________',
  78. ' 0 0.5 1'
  79. ]
  80. assert lines == list(textplot_str(1/x, 0, 1))
  81. lines = [
  82. ' 0 | ......',
  83. ' | ........ ',
  84. ' | ........ ',
  85. ' | ...... ',
  86. ' | ..... ',
  87. ' | .... ',
  88. ' | ... ',
  89. ' | .. ',
  90. ' | ... ',
  91. ' | / ',
  92. ' -2 |-------..----------------------------------------------',
  93. ' | / ',
  94. ' | / ',
  95. ' | / ',
  96. ' | . ',
  97. ' | ',
  98. ' | . ',
  99. ' | ',
  100. ' | ',
  101. ' | ',
  102. ' -4 |_______________________________________________________',
  103. ' 0 0.5 1'
  104. ]
  105. assert lines == list(textplot_str(log(x), 0, 1))
  106. def test_sinc():
  107. x = Symbol('x')
  108. lines = [
  109. ' 1 | . . ',
  110. ' | . . ',
  111. ' | ',
  112. ' | . . ',
  113. ' | ',
  114. ' | . . ',
  115. ' | ',
  116. ' | ',
  117. ' | . . ',
  118. ' | ',
  119. ' 0.4 |-------------------------------------------------------',
  120. ' | . . ',
  121. ' | ',
  122. ' | . . ',
  123. ' | ',
  124. ' | ..... ..... ',
  125. ' | .. \\ . . / .. ',
  126. ' | / \\ / \\ ',
  127. ' |/ \\ . . / \\',
  128. ' | \\ / \\ / ',
  129. ' -0.2 |_______________________________________________________',
  130. ' -10 0 10'
  131. ]
  132. assert lines == list(textplot_str(sin(x)/x, -10, 10))
  133. def test_imaginary():
  134. x = Symbol('x')
  135. lines = [
  136. ' 1 | ..',
  137. ' | .. ',
  138. ' | ... ',
  139. ' | .. ',
  140. ' | .. ',
  141. ' | .. ',
  142. ' | .. ',
  143. ' | .. ',
  144. ' | .. ',
  145. ' | / ',
  146. ' 0.5 |----------------------------------/--------------------',
  147. ' | .. ',
  148. ' | / ',
  149. ' | . ',
  150. ' | ',
  151. ' | . ',
  152. ' | . ',
  153. ' | ',
  154. ' | ',
  155. ' | ',
  156. ' 0 |_______________________________________________________',
  157. ' -1 0 1'
  158. ]
  159. assert list(textplot_str(sqrt(x), -1, 1)) == lines
  160. lines = [
  161. ' 1 | ',
  162. ' | ',
  163. ' | ',
  164. ' | ',
  165. ' | ',
  166. ' | ',
  167. ' | ',
  168. ' | ',
  169. ' | ',
  170. ' | ',
  171. ' 0 |-------------------------------------------------------',
  172. ' | ',
  173. ' | ',
  174. ' | ',
  175. ' | ',
  176. ' | ',
  177. ' | ',
  178. ' | ',
  179. ' | ',
  180. ' | ',
  181. ' -1 |_______________________________________________________',
  182. ' -1 0 1'
  183. ]
  184. assert list(textplot_str(S.ImaginaryUnit, -1, 1)) == lines