Debian Codegraph @

test/unit/symbolics/test_symbol.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2010 Kristian B. Oelgaard
3 #
4 # This file is part of FFC.
5 #
6 # FFC is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # FFC is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with FFC. If not, see <http://www.gnu.org/licenses/>.
18
19 import pytest
20 import time
21
22 # FFC modules
23 from ffc.quadrature.symbolics import *
24 from ffc.quadrature.cpp import format, set_float_formatting
25 from ffc.parameters import FFC_PARAMETERS
26 set_float_formatting(FFC_PARAMETERS['precision'])
27
28
29 def testSymbol():
30 "Test simple symbol instance."
31
32 s0 = Symbol("x", BASIS)
33 s1 = Symbol("y", IP)
34 s2 = Symbol("z", GEO)
35 s3 = Symbol("z", GEO)
36 s4 = Symbol("z", IP)
37
38 assert repr(s0) == "Symbol('x', BASIS)"
39 assert repr(s1) == "Symbol('y', IP)"
40 assert repr(s2) == "Symbol('z', GEO)"
41 assert repr(s4) == "Symbol('z', IP)"
42
43 assert s2 == s3
44 assert (s2 == s1) is False
45 assert (s2 == s4) is False
46 assert (s2 != s3) is False
47 assert s2 != s1
48
49 assert s0 < s1
50 assert s4 > s1
51
52 assert s0.ops() == 0
53 assert s1.ops() == 0
54 assert s2.ops() == 0
55 assert s3.ops() == 0
56 assert s4.ops() == 0
57
58 # Test hash
59 ll = [s0]
60 d = {s0: 0}
61 s5 = Symbol('x', BASIS)
62
63 assert s0 in ll
64 assert s0 in d
65 assert s5 in ll
66 assert s5 in d