summaryrefslogtreecommitdiff
path: root/test/pygmathlib_test_formula.py
blob: fb550bd1448ddd9c11785bef234a57c29c818cc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# coding=utf-8

'''
gMathLib, mathematic expressions handling library

 # pyGMathLib test formula shared source

Copyright (C) 2007 Guillaume Seguin <guillaume@segu.in>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
'''

def make_test_formula (context):
    formula = context.Formula ()

    symbol0 = context.Atom ("0")
    symbol1 = context.Atom ("1")
    symbol2 = context.Atom ("2")
    symbol10 = context.Atom ("10")
    symbolx = context.Atom ("x")
    symboly = context.Atom ("y")
    symboli = context.Atom ("i")
    symbolalpha = context.Symbol (symtype = "alpha")
    symbolinfty = context.Symbol (symtype = "infty")

    sin = context.Symbol (symtype = "fun")
    sin.value = "sin"
    sin.set_child (symbolx, 0)
    frac = context.Symbol (symtype = "frac")
    frac.set_child (sin, 0)
    frac.set_child (symbolx.copy (), 1)
    app = context.Symbol (symtype = "approach")
    app.set_child (symbolx.copy (), 0)
    app.set_child (symbol0, 1)
    lim = context.Symbol (symtype = "lim")
    lim.set_child (app, 0)
    lim.set_child (frac, 1)
    equal = context.Symbol ("2op")
    equal.value = "="
    equal.set_child (lim, 0)
    equal.set_child (symbol1, 1)

    super = context.Symbol (symtype = "super")
    super.set_child (symbolx.copy (), 0)
    super.set_child (symbol2, 1)
    sub = context.Symbol (symtype = "sub")
    sub.set_child (symboly, 0)
    sub.set_child (symbolalpha, 1)
    add = context.Symbol (symtype = "2op")
    add.value = "+"
    add.set_child (super, 0)
    add.set_child (sub, 1)
    lparen = context.Symbol (symtype = "lparen")
    lparen.value = "("
    rparen = context.Symbol (symtype = "rparen")
    rparen.value = ")"
    paren = context.Symbol (symtype = "paren")
    paren.set_child (lparen, 0)
    paren.set_child (add, 1)
    paren.set_child (rparen, 2)
    fun = context.Symbol (symtype = "fun")
    fun.value = "sin"
    fun.set_child (paren, 0)
    frac = context.Symbol (symtype = "frac")
    frac.set_child (fun, 0)
    eq = equal.copy ()
    eq.set_child (symboli, 0)
    eq.set_child (symbol0.copy (), 1)
    lparen = lparen.copy ()
    rparen = rparen.copy ()
    paren = context.Symbol (symtype = "paren")
    paren.set_child (lparen, 0)
    paren.set_child (frac, 1)
    paren.set_child (rparen, 2)
    integral = context.Symbol (symtype = "integral")
    integral.set_child (symbol0.copy (), 0)
    integral.set_child (symbol1.copy (), 1)
    integral.set_child (paren, 2)
    product = context.Symbol (symtype = "product")
    product.set_child (eq, 0)
    product.set_child (symbol10, 1)
    product.set_child (integral, 2)
    equal2 = equal.copy ()
    equal2.set_child (product, 0)
    equal2.set_child (symbolinfty, 1)

    comma = context.Symbol (symtype = "2op")
    comma.value = ", "
    comma.set_child (equal, 0)
    comma.set_child (equal2, 1)

    formula.set_root (comma)

    return formula