Skip to content

Commit a4ec66d

Browse files
committed
Moved tests to test/
1 parent 69b9dcf commit a4ec66d

13 files changed

+68
-4
lines changed

pixi.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
authors = ["Pablo Winant <[email protected]>","Ousema Bouaneni <[email protected]>"]
2+
authors = ["Pablo Winant <[email protected]>"]
33
description = "Dolo Modeling Language"
44
channels = ["conda-forge"]
55
preview = ["pixi-build"]
@@ -10,10 +10,10 @@ name = "dolang"
1010
version = "0.0.21"
1111

1212
[dependencies]
13-
dolang = { path = "." }
13+
dolang = { path = "."}
14+
interegular = ">=0.3.3,<0.4"
1415

1516
[package.run-dependencies]
16-
python = ">=3.9,<3.13"
1717
numpy = ">=2.2.6,<3"
1818
sympy = ">=1.14.0,<2"
1919
lark = ">=1.2.2,<2"
@@ -63,6 +63,5 @@ docs = "mkdocs serve"
6363

6464

6565
[environments]
66-
prod = []
6766
test = ["test"]
6867
dev = ["test", "lint", "docs"]
File renamed without changes.

tests/test_new_grammar.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
def test_formulas():
2+
# import dolang.grammar
3+
4+
from dolang.grammar import parser_f, parser
5+
print("Testing formulas grammar:")
6+
7+
formulas = [
8+
"x[t-1]",
9+
"x[t]",
10+
"x[t+1]",
11+
"x[t]^alpha*x[t-1]^(1-alpha)",
12+
"-x[t]^alpha*x[t-1]^(1-alpha)",
13+
"sin(x[t])",
14+
"cos(x[t]+1)",
15+
"exp(x[t]+sin(x[t-1]))",
16+
]
17+
import time
18+
t = time.time()
19+
for f in formulas:
20+
print(f)
21+
res = parser_f.parse(f, start="formula")
22+
print(res.pretty())
23+
print("time:", time.time() - t)
24+
25+
26+
t = time.time()
27+
for f in formulas:
28+
print(f)
29+
res = parser.parse(f, start="equation")
30+
print(res.pretty())
31+
print("time:", time.time() - t)
32+
33+
def test_parse_neoclassical():
34+
35+
import time
36+
txt = """
37+
z[t] = ρ*z[t-1] + e_z[t] + e_y[t]
38+
y[t] = exp(z[t])*k[t-1]^α
39+
k[t] = k[t-1]*(1-δ) + i[t]
40+
c[t] = exp(z[t])*k[t-1]^α - i[t]
41+
β*(c[t+1]/c[t])^(-γ)*(1-δ+α*y[t+1]/k[t]) = 1
42+
43+
α = 0.387
44+
β = 0.96
45+
γ = 4.0
46+
δ = 0.1
47+
z = 0.0
48+
ρ = 0.9
49+
k = ((1/β-(1-δ))/α)**(1/(α-1))
50+
y = k^α
51+
i = δ*k
52+
c = y - i
53+
"""
54+
55+
from dolang.grammar import parser_f, parser
56+
print("Testing neoclassical model")
57+
58+
t = time.time()
59+
res = parser.parse(txt, start="equation_block")
60+
print("time:", time.time() - t)
61+
62+
t = time.time()
63+
res = parser_f.parse(txt, start="equation_block")
64+
print("time:", time.time() - t)
65+

0 commit comments

Comments
 (0)