MCPcopy Index your code
hub / github.com/numpy/numpy / test_fromstring

Method test_fromstring

numpy/f2py/tests/test_symbolic.py:296–388  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

294 assert as_eq(x, y).substitute({x: y + z}) == as_eq(y + z, y)
295
296 def test_fromstring(self):
297
298 x = as_symbol("x")
299 y = as_symbol("y")
300 z = as_symbol("z")
301 f = as_symbol("f")
302 s = as_string('"ABC"')
303 t = as_string('"123"')
304 a = as_array((x, y))
305
306 assert fromstring("x") == x
307 assert fromstring("+ x") == x
308 assert fromstring("- x") == -x
309 assert fromstring("x + y") == x + y
310 assert fromstring("x + 1") == x + 1
311 assert fromstring("x * y") == x * y
312 assert fromstring("x * 2") == x * 2
313 assert fromstring("x / y") == x / y
314 assert fromstring("x ** 2", language=Language.Python) == x**2
315 assert fromstring("x ** 2 ** 3", language=Language.Python) == x**2**3
316 assert fromstring("(x + y) * z") == (x + y) * z
317
318 assert fromstring("f(x)") == f(x)
319 assert fromstring("f(x,y)") == f(x, y)
320 assert fromstring("f[x]") == f[x]
321 assert fromstring("f[x][y]") == f[x][y]
322
323 assert fromstring('"ABC"') == s
324 assert (normalize(
325 fromstring('"ABC" // "123" ',
326 language=Language.Fortran)) == s // t)
327 assert fromstring('f("ABC")') == f(s)
328 assert fromstring('MYSTRKIND_"ABC"') == as_string('"ABC"', "MYSTRKIND")
329
330 assert fromstring("(/x, y/)") == a, fromstring("(/x, y/)")
331 assert fromstring("f((/x, y/))") == f(a)
332 assert fromstring("(/(x+y)*z/)") == as_array(((x + y) * z, ))
333
334 assert fromstring("123") == as_number(123)
335 assert fromstring("123_2") == as_number(123, 2)
336 assert fromstring("123_myintkind") == as_number(123, "myintkind")
337
338 assert fromstring("123.0") == as_number(123.0, 4)
339 assert fromstring("123.0_4") == as_number(123.0, 4)
340 assert fromstring("123.0_8") == as_number(123.0, 8)
341 assert fromstring("123.0e0") == as_number(123.0, 4)
342 assert fromstring("123.0d0") == as_number(123.0, 8)
343 assert fromstring("123d0") == as_number(123.0, 8)
344 assert fromstring("123e-0") == as_number(123.0, 4)
345 assert fromstring("123d+0") == as_number(123.0, 8)
346 assert fromstring("123.0_myrealkind") == as_number(123.0, "myrealkind")
347 assert fromstring("3E4") == as_number(30000.0, 4)
348
349 assert fromstring("(1, 2)") == as_complex(1, 2)
350 assert fromstring("(1e2, PI)") == as_complex(as_number(100.0),
351 as_symbol("PI"))
352
353 assert fromstring("[1, 2]") == as_array((as_number(1), as_number(2)))

Callers

nothing calls this directly

Calls 15

as_symbolFunction · 0.90
as_stringFunction · 0.90
as_arrayFunction · 0.90
fromstringFunction · 0.90
normalizeFunction · 0.90
as_numberFunction · 0.90
as_complexFunction · 0.90
as_applyFunction · 0.90
as_ternaryFunction · 0.90
as_derefFunction · 0.90
as_refFunction · 0.90
as_eqFunction · 0.90

Tested by

no test coverage detected