FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lpython/integration_tests/enum_02.py at main · sak-codes/lpython · GitHub
sak-codes
/
lpython
Public
forked from
lcompilers/lpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lpython
/
integration_tests
/
enum_02.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (31 loc) · 1.27 KB
Breadcrumbs
lpython
/
integration_tests
/
enum_02.py
Copy path
File metadata and controls
39 lines (31 loc) · 1.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
enum
import
Enum
from
ltypes
import
i32
,
f64
class
MolecularMass
(
Enum
):
water
:
i32
=
18
methane
:
i32
=
16
ammonia
:
i32
=
17
oxygen
:
i32
=
16
class
RelativeCharge
(
Enum
):
proton
:
i32
=
1
electron
:
i32
=
-
1
neutron
:
i32
=
0
class
AbsoluteChargeWithoutExp
(
Enum
):
proton
:
f64
=
1.602
# ignoring 10**(-19) because of printing limitations
electron
:
f64
=
-
1.602
neutron
:
f64
=
0.0
def
test_mm
():
assert
MolecularMass
.
methane
.
value
==
MolecularMass
.
oxygen
.
value
assert
MolecularMass
.
ammonia
.
value
-
MolecularMass
.
methane
.
value
==
1
assert
MolecularMass
.
water
.
value
==
MolecularMass
.
oxygen
.
value
+
2
def
test_rc
():
assert
RelativeCharge
.
proton
.
value
+
RelativeCharge
.
electron
.
value
==
RelativeCharge
.
neutron
.
value
def
charge_ratio
(
c1
:
AbsoluteChargeWithoutExp
,
c2
:
AbsoluteChargeWithoutExp
)
->
f64
:
return
c1
.
value
/
c2
.
value
def
test_ac
():
print
(
AbsoluteChargeWithoutExp
.
proton
.
name
,
AbsoluteChargeWithoutExp
.
proton
.
value
)
print
(
AbsoluteChargeWithoutExp
.
electron
.
name
,
AbsoluteChargeWithoutExp
.
electron
.
value
)
print
(
AbsoluteChargeWithoutExp
.
neutron
.
name
,
AbsoluteChargeWithoutExp
.
neutron
.
value
)
assert
charge_ratio
(
AbsoluteChargeWithoutExp
.
proton
,
AbsoluteChargeWithoutExp
.
electron
)
==
-
1.0
test_mm
()
test_rc
()
test_ac
()
Back
|
FazBrowse Home
|
New Git URL