Template jEdit: spad_unittest.vm
-- Unittest .....: PQTY
-- Author .......: Kurt Pagani
-- Date .........: Sat Jul 28 16:56:04 CEST 2018
--
fricas
)set break resume
fricas
)expose UnittestCount UnittestAux Unittest
UnittestCount is now explicitly exposed in frame initial
UnittestAux is now explicitly exposed in frame initial
Unittest is now explicitly exposed in frame initial
--)lib PUSYS PQTY SI DIMAN
fricas
)expose PUSYS PQTY SI DIMAN
PhysicalUnitSystem is already explicitly exposed in frame initial
PhysQty is already explicitly exposed in frame initial
SIunit is already explicitly exposed in frame initial
DimensionalAnalysis is already explicitly exposed in frame initial
--)co pdim2
fricas
)sh SI
SIunit is a domain constructor.
Abbreviation for SIunit is SI
This constructor is exposed in this frame.
44 Names for 44 Operations in this Domain.
------------------------------- Operations --------------------------------
%A : Integer -> % %K : Integer -> %
%cd : Integer -> % %kg : Integer -> %
%m : Integer -> % %mol : Integer -> %
%s : Integer -> % ?*? : (%, %) -> %
?/? : (%, %) -> % ?=? : (%, %) -> Boolean
?^? : (%, Integer) -> % ampere : () -> %
baseUnits : () -> List(%) becquerel : () -> %
candela : () -> % coerce : % -> OutputForm
coulomb : () -> % dim : % -> List(Integer)
farad : () -> % gray : () -> %
henry : () -> % hertz : () -> %
joule : () -> % katal : () -> %
kelvin : () -> % kilogram : () -> %
latex : % -> String lumen : () -> %
lux : () -> % metre : () -> %
mole : () -> % newton : () -> %
ohm : () -> % one : () -> %
pascal : () -> % second : () -> %
siemens : () -> % sievert : () -> %
tesla : () -> % unitSystem : () -> Type
volt : () -> % watt : () -> %
weber : () -> % ?~=? : (%, %) -> Boolean
-- Usage
m:=1400.3 %kg(1)
fricas
v:=30.6 (%m(1)/%s(1))
fricas
E:=m*v^2/2
fricas
-- Test Suite
testsuite "PUSYS"
All user variables and function definitions have been cleared.
Type: Void
fricas
-- Cases
testcase "cgs"
All user variables and function definitions have been cleared.
Type: Void
fricas
CGS ==> PUSYS(['cm,'g,'s])
Type: Void
fricas
[cm,g,s]:=baseUnits()$CGS
Type: List(PhysicalUnitSystem
?([cm,
g,
s]))
fricas
erg:=g*cm^2/s^2
Type: PhysicalUnitSystem
?([cm,
g,
s])
fricas
dyne:=g*cm/s^2
Type: PhysicalUnitSystem
?([cm,
g,
s])
fricas
testEquals("dim cm", "[1,0,0]")
Type: Void
fricas
testEquals("dim g", "[0,1,0]")
Type: Void
fricas
testEquals("dim s", "[0,0,1]")
Type: Void
fricas
testEquals("dim(cm/s*g)","[1,1,-1]")
Type: Void
fricas
testEquals("factors(cm/g).1.exp","1")
Type: Void
fricas
testEquals("factors(cm/g).2.exp","-1")
Type: Void
fricas
testEquals("factors(one()$CGS)","[]")
Type: Void
fricas
testEquals("baseSymbols()$CGS","['cm,'g,'s]")
Type: Void
fricas
testEquals("(cm^2/s^4*g=g*s^(-4)*cm^2)$CGS","true")
Type: Void
fricas
testEquals("(dyne * cm = erg)$CGS","true")
Type: Void
fricas
testcase "SI"
All user variables and function definitions have been cleared.
Type: Void
fricas
[m,kg,s,A,K,mol,cd]:=baseUnits()$SI
fricas
force1:=%kg(1) * %m(1) * %s(-2)
fricas
force2:=kg * m / s^2
fricas
force3:=newton()$SI
fricas
area1:=%m(2)
fricas
area2:=m^2
fricas
area3:=metre()^2
fricas
pressure1:=force1/area1
fricas
pressure2:=pascal()$SI
fricas
testEquals("(force1=force2)$SI","true")
Type: Void
fricas
testEquals("(force2=force3)$SI","true")
Type: Void
fricas
testEquals("(pressure1=pressure2)$SI","true")
Type: Void
fricas
testEquals("dim force1","[1,1,- 2,0,0,0,0]")
Type: Void
fricas
testEquals("dim pressure2","[- 1,1,- 2,0,0,0,0]")
Type: Void
fricas
-- Test Suite
testsuite "PQTY"
All user variables and function definitions have been cleared.
Type: Void
fricas
testcase "PQTY(SI)"
All user variables and function definitions have been cleared.
Type: Void
fricas
-- from codata.spad (package CODATA)
CT(v,e,u) ==> (interval(v-e,v+e)$Interval(Float)) u
Type: Void
fricas
-- speed of light in vacuum
-- Value 299 792 458 m s-1
-- Standard uncertainty (exact)
-- Relative standard uncertainty (exact)
-- Concise form 299 792 458 m s-1
c := CT(299792458.0, 0.0, %m(1)*%s(-1))
fricas
-- Planck constant over 2 pi
-- Value 1.054 571 800 x 10-34 J s
-- Standard uncertainty 0.000 000 013 x 10-34 J s
-- Relative standard uncertainty 1.2 x 10-8
-- Concise form 1.054 571 800(13) x 10-34 J s
hbar := CT(1.054571800E-34, 0.000000013E-34,%m(2)*%kg(1)*%s(-1))
fricas
-- elementary charge
-- $e$
-- Value 1.602 176 6208 x 10-19 C
-- Standard uncertainty 0.000 000 0098 x 10-19 C
-- Relative standard uncertainty 6.1 x 10-9
-- Concise form 1.602 176 6208(98) x 10-19 C
e := CT(1.6021766208E-19, 0.0000000098E-19, %A(1)*%s(1))
fricas
-- electron mass
-- $m_{\rm e}$
-- Value 9.109 383 56 x 10-31 kg
-- Standard uncertainty 0.000 000 11 x 10-31 kg
-- Relative standard uncertainty 1.2 x 10-8
-- Concise form 9.109 383 56(11) x 10-31 kg
m_e := CT(9.10938356E-31, 0.00000011E-31, %kg(1))
fricas
-- fine-structure constant
-- Value 7.297 352 5664 x 10-3
-- Standard uncertainty 0.000 000 0017 x 10-3
-- Relative standard uncertainty 2.3 x 10-10
-- Concise form 7.297 352 5664(17) x 10-3
alpha := CT(7.2973525664E-3, 0.0000000017E-3,%m(0)$SI)
fricas
-- electric constant
-- $\varepsilon_0$
-- Value 8.854 187 817... x 10-12 F m-1
-- Standard uncertainty (exact)
-- Relative standard uncertainty (exact)
-- Concise form 8.854 187 817... x 10-12 F m-1
eps_0 := CT(8.854187817E-12,0, %m(-3)*%kg(-1)*%s(4)*%A(2))
fricas
r1:=ival e
Type: Interval(Float)
fricas
r2:=unit e
fricas
r3:=magnitude e
Type: Float
fricas
r4:=uncertainty e
Type: Float
fricas
testEquals("(unit e = %s(1)*%A(1))$SI","true")
Type: Void
fricas
testEquals("(unit(m_e*c^2)/joule()$SI=one()$SI)$SI","true")
Type: Void
fricas
-- fine structure
myalpha:=(1/(4*%pi))::Float * eps_0^(-1)*e^2/hbar/c
fricas
testEquals("abs(magnitude(myalpha-alpha))<1.0E-10","true")
Type: Void
fricas
f:=2 newton()$SI
fricas
l:=3.6 metre()$SI
fricas
a:=l^2
fricas
p:=f/a
fricas
testEquals("test(magnitude(7.2 joule()$SI / (f*l))=1$Float)","true")
Type: Void
fricas
testEquals("uncertainty(m_e*c^2)<1.0E-20","true")
Type: Void
fricas
setOutputMode(1)$PQTY(SI)
fricas
hbar
fricas
m_e
fricas
c
fricas
setOutputMode(3)$PQTY(SI)
fricas
alpha
fricas
eps_0
fricas
setOutputMode(2)$PQTY(SI)
fricas
m_e
fricas
hbar
fricas
-- Test Suite
testsuite "DIMAN"
All user variables and function definitions have been cleared.
Type: Void
fricas
testcase "DIMAN(SI)"
All user variables and function definitions have been cleared.
Type: Void
fricas
-- Dimensional analysis
-- Buckingham Pi theorem
D==> DIMAN(SI)
Type: Void
fricas
t:Table(Symbol,SI):=table()
Type: Table(Symbol,
SIunit
?)
fricas
t.L:=%m(1)$SI ; t.M:=%kg(1)$SI; t.T:=%s(1)$SI; t.g:=%m(1)$SI/%s(2)$SI
fricas
bt:=buckingham(t)
Type: List(Expression(Integer))
fricas
res1:=solve(bt.1=1,'T).1
Type: Equation(Expression(Integer))
fricas
s:Table(Symbol,SI):=table()
Type: Table(Symbol,
SIunit
?)
fricas
s.v:=%m(1)$SI/%s(1)$SI; s.rho:=%kg(1)$SI/%m(3)$SI; s.p:=pascal()$SI
fricas
bs:=buckingham(s)
Type: List(Expression(Integer))
fricas
res2:=solve(bs.1=1,'v).1
Type: Equation(Expression(Integer))
fricas
-- https://en.wikipedia.org/w/index.php?title=Dimensional_analysis
-- Example section 26
vb:Table(Symbol,SI):=table()
Type: Table(Symbol,
SIunit
?)
fricas
vb.'l:=%m(1)$SI; vb.A:=%m(1)$SI; vb.rho:=%kg(1)$SI/%m(1)$SI;
fricas
vb.'s:=%kg(1)$SI*%m(1)$SI/%s(2)$SI; vb.E:=%kg(1)$SI*%m(2)$SI/%s(2)$SI
fricas
bvb:=buckingham vb
Type: List(Expression(Integer))
fricas
testEquals("res1","T=sqrt(L/g)")
Type: Void
fricas
testEquals("res2","v=sqrt(p/rho)")
Type: Void
fricas
F:=operator 'F
fricas
res3:=F(bvb.2,bvb.1)=0
Type: Equation(Expression(Integer))
fricas
testEquals("res3","F('l*'s/'E,'A*'s/'E)=0")
Type: Void
fricas
-- Results/Statistics
fricas
)set output algebra on
fricas
)version
"FriCAS 1.3.10 compiled at Wed 10 Jan 02:19:45 CET 2024"
fricas
)lisp (lisp-implementation-type)
Your user access level is compiler and this command is therefore not
available. See the )set userlevel command for more information.
fricas
)lisp (lisp-implementation-version)
Your user access level is compiler and this command is therefore not
available. See the )set userlevel command for more information.
statistics()
=============================================================================
General WARNINGS:
* do not use ')clear completely' before having used 'statistics()'
It clears the statistics without warning!
* do not forget to pass the arguments of the testXxxx functions as Strings!
Otherwise, the test will fail and statistics() will not notice!
=============================================================================
WARNINGS:
Testsuite: PUSYS
Testcase: cgs
test: 7
testing in a domain without InputForm!
=============================================================================
Testsuite: PUSYS
failed (total): 0 (2)
=============================================================================
Testsuite: PQTY
failed (total): 0 (1)
=============================================================================
Testsuite: DIMAN
failed (total): 0 (1)
=============================================================================
testsuite | testcases: failed (total) | tests: failed (total)
PUSYS 0 (2) 0 (15)
PQTY 0 (1) 0 (5)
DIMAN 0 (1) 0 (3)
=============================================================================
File summary.
unexpected failures: 0
expected failures: 0
unexpected passes: 0
total tests: 23
Type: Void