Skip to content

Commit

Permalink
add tests, remove setup test
Browse files Browse the repository at this point in the history
  • Loading branch information
idanpa committed Mar 31, 2024
1 parent 56d9ae7 commit 615d4d5
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 32 deletions.
78 changes: 78 additions & 0 deletions calcpy/tests/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
In [1]: 12
Out[1]: 12 0x0c 0000 1100
In [1]: 30/3deg
Out[1]:
1800
---- ≈ 572.957795130823
pi
In [1]: [pi/2, log(x)/sin(y), Sum(1/n**2,(n,1,4))]
Out[1]:
4
____
\ `
\ 1 log(x)
pi log(x) \ -- ≈ [1.57079632679490, ------, 1.42361111111111]
[--, ------, / 2] sin(y)
2 sin(y) / n
/___,
n = 1
In [1]: SymmetricGroup(3).conjugacy_classes()
Out[1]: [{()}, {(0 1 2), (0 2 1)}, {(0 2), (1 2), (0 1)}]
In [1]: latex(diff($\frac{1}{x}$ * $\sin{x}$))
Out[1]: \frac{\cos{\left(x \right)}}{x} - \frac{\sin{\left(x \right)}}{x^{2}}
In [1]: 8x**2+2x-10 = 0
In [1]: ?23232
Out[1]: 23232 0x5ac0 0101 1010 1100 0000

2 6 1
11 *2 *3 {2: 6, 3: 1, 11: 2} = factorint(_)
In [1]: ?((1,2),(2,3))
Out[1]:
[1 2]
[ ]
[2 3]

-1 = det(_)
4 = trace(_)

[-3 2 ]
[ ]
[2 -1] = _**-1

2
lambda - 4*lambda - 1 = _.charpoly().as_expr()

[ ___ ] [ ___]
[ \/ 5 1] [ 1 \/ 5 ]
___ [- ----- - -] ___ [- - + -----]
[(2 - \/ 5 , 1, [[ 2 2]]), (2 + \/ 5 , 1, [[ 2 2 ]])]
[ ] [ ]
[ 1 ] [ 1 ] = _.eigenvects() # ((eval, mult, evec),...

[ ___ ___]
[ \/ 5 1 1 \/ 5 ] [ ___ ]
[- ----- - - - - + -----] [2 - \/ 5 0 ]
([ 2 2 2 2 ], [ ])
[ ] [ ___]
[ 1 1 ] [ 0 2 + \/ 5 ] = _.diagonalize() # (P,D) so _=PDP^-1
In [1]: ?e**(-x**2)
Out[1]:
2
-x
e

2
-x
-2*x*e = diff(_)

____
\/ pi *erf(x)
-------------
2 = integrate(_)

4
2 x / 6\
1 - x + -- + O\x /
2 = series(_)

[] = solve(_)
File renamed without changes.
44 changes: 44 additions & 0 deletions calcpy/tests/test_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import os
from time import sleep

OUTPUT_FILE_PATH = os.path.join(os.path.dirname(__file__), 'output.txt')

def run_flow(ip):
def run_cell(raw_cell):
print('In [1]: ' + raw_cell)
ip.run_cell(raw_cell)

run_cell('12')
run_cell('30/3deg')
run_cell('[pi/2, log(x)/sin(y), Sum(1/n**2,(n,1,4))]')
run_cell('SymmetricGroup(3).conjugacy_classes()')
run_cell(r'latex(diff($\frac{1}{x}$ * $\sin{x}$))')
run_cell('8x**2+2x-10 = 0')
run_cell('?23232')
sleep(1)
run_cell('?((1,2),(2,3))')
sleep(1)
run_cell('?e**(-x**2)')
sleep(2)

def test_output(ip, capsys):
run_flow(ip)
captured = capsys.readouterr()
with open(OUTPUT_FILE_PATH, 'r', encoding='utf-8') as f:
assert f.read() == captured.out, \
r'output mismatch, regenerate output by `python calcpy\tests\test_output.py`'
assert '' == captured.err

if __name__ == '__main__':
import os
from contextlib import redirect_stdout
from IPython.testing.globalipapp import start_ipython

ip = start_ipython()
ip.run_line_magic('load_ext', 'calcpy')
print(f'writing output to {OUTPUT_FILE_PATH}')
with open(OUTPUT_FILE_PATH, 'w', encoding='utf-8') as f:
with redirect_stdout(f):
run_flow(ip)

29 changes: 0 additions & 29 deletions calcpy/tests/test_setup.py

This file was deleted.

6 changes: 6 additions & 0 deletions calcpy/tests/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ def test_auto_product(ip):
assert ip.run_cell('(x+1)x').result == (x+1)*x
assert ip.run_cell('2(x+1)').result == 2*(x+1)
assert ip.run_cell('(x+1)2').result == (x+1)*2
assert ip.run_cell('(x+1)2y').result == (x+1)*2*y
assert ip.run_cell('5x^5 + 4x ^ 4 + 3x**3 + 2x ** 2').result == 5*x**5 + 4*x**4 + 3*x**3 + 2*x**2
assert ip.run_cell('5x^y').result == 5*x**y
assert ip.run_cell('1/2x').result == x/2 # controversial

assert ip.run_cell('f\'{1.1:1.2f}\'').result == '1.10'
assert ip.run_cell('\'%1.2f\' % 1.234').result == '1.23'
assert ip.run_cell('\'%.3f\' % 1.234').result == '1.234'

assert ip.run_cell('10MB/1MB').result == 10

# check no false positives:
assert ip.run_cell('0b1010').result == 0b1010
Expand Down
5 changes: 2 additions & 3 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ Out[1]:
```

```
In [1]: a,b,c,d = symbols('a b c d')
In [2]: ((a,b),(c,d))**-1
Out[2]:
In [1]: ((a,b),(c,d))**-1
Out[1]:
⎡ d -b ⎤
⎢───────── ─────────⎥
⎢a*d - b*c a*d - b*c⎥
Expand Down

0 comments on commit 615d4d5

Please sign in to comment.