UNPKG

1.42 kBtext/coffeescriptView Raw
1test_expand = ->
2 run_test [
3
4 # general cases
5
6 "expand(1/(x+1)/(x+2))",
7 "1/(x+1)-1/(x+2)",
8
9 "expand((2x^3-x+2)/(x^2-2x+1))",
10 "4+2*x+5/(x-1)+3/(x^2-2*x+1)",
11
12 "expand(1/x^2/(x-1))",
13 "-1/(x^2)-1/x+1/(x-1)",
14
15 "p=5s+2",
16 "",
17
18 "q=(s+1)*(s+2)^2",
19 "",
20
21 "expand(p/q)",
22 "-3/(s+1)+3/(s+2)+8/(s^2+4*s+4)",
23
24 # ensure denominators are expanded (result seems preferable that way)
25
26 "q=(x-1)*(x-2)^3",
27 "",
28
29 "expand(1/q)",
30 "1/(x^3-6*x^2+12*x-8)+1/(x-2)-1/(x-1)-1/(x^2-4*x+4)",
31
32 # fractional poles
33
34 "expand(1/(x+1/2)/(x+1/3))",
35 "-12/(2*x+1)+18/(3*x+1)",
36
37 # expand tensor
38
39 "f=1/(x+1)/(x+2)",
40 "",
41
42 "g=1/(x+1)-1/(x+2)",
43 "",
44
45 "expand([[f,f],[f,f]])-[[g,g],[g,g]]",
46 "[[0,0],[0,0]]",
47
48 # denominator normalized?
49
50 "expand(1/(1+1/x))",
51 "1-1/(x+1)",
52
53 # poles at zero
54
55 "expand(1/x/(x+1))",
56 "1/x-1/(x+1)",
57
58 "expand(1/x^2/(x+1))",
59 #"x^(-2)-1/x+1/(x+1)",
60 "1/x^2-1/x+1/(x+1)",
61
62 # other corner cases
63
64 "expand(1/x)",
65 "1/x",
66
67 "expand(1/x^2)",
68 #"x^(-2)",
69 "1/x^2",
70
71 "expand(1/(x^2-4x+4))",
72 "1/(x^2-4*x+4)",
73
74 # cases where nothing can be done
75
76 "expand(sin(x))",
77 "sin(x)",
78
79 "expand(x)",
80 "x",
81
82 "expand(1/sin(x))",
83 # unclear why the extra parens are added but no biggie
84 "1/(sin(x))",
85
86 # note that expand isn't needed to execute the
87 # multiplications, expand does something
88 # different.
89 "expand(expand((sin(x)+1)^2))",
90 "1+sin(x)^2+2*sin(x)",
91
92 ]