luv

Workshop wiki

tests.lisp

arithmetic/tests.lisp

system luv/test · 29 definitions · on GitHub

defpackage#:luv.tests
:use#:cl#:rove
:local-nicknames
#:lang#:luv.arithmetic.language
#:lisp#:luv.arithmetic.lisp
#:vec#:luv.arithmetic.lisp.vec3
#:lvk#:luv.vulkan
#:math#:luv.arithmetic
#+darwin (#:metal #:luv.metal)#+darwin (#:objc #:luv.objective-c)
#:records#:luv.arithmetic.records
#:vk#:luv.vk
:import-from#:luv.arithmetic#:dot#:clamp
:import-from#:luv.arithmetic.language#:quantity#:interpret#:convert-unit#:counted-fold
in-package#:luv.tests
math:define-quantity:position:kind:length:components
:position-x:position-y
math:define-quantity-constant+declared-test-distance+3.5d0:typedouble-float:quantity
:quantity:distance:unit:metre
deftestnamed-quantity-spaces-govern-addition
let
airspeed
math:make-quantity-specification:airspeed:dimension'
:length1
:duration-1
climb-rate
math:make-quantity-specification:climb-rate:dimension'
:length1
:duration-1
ok
eq:different-quantity-spaces
handler-case
prognnil
math:quantity-operation-error
condition
math:quantity-operation-error-reasoncondition
deftestexact-units-compose-without-implicit-conversion
let*
metres
math:make-quantity-specification:distance:dimension:length:unit:metre
kilometres
math:make-quantity-specification:distance:dimension:length:unit:kilometre
seconds
math:make-quantity-specification:duration:dimension:duration:unit:second
ok
eq:different-units
handler-case
prognnil
math:quantity-operation-error
condition
math:quantity-operation-error-reasoncondition
ok
math:unit-expression=
math:quantity-specification-unitspeed
'
:metre1
:second-1
deftestsemantic-units-own-dimensions-bases-and-scales
let*
metres
kilometres
math:make-quantity-specification:distance:unit:kilometre
percent-proportion
math:make-quantity-specification:proportion:unit:percent
ok
math:dimension=:length
math:quantity-specification-dimensionmetres
ok
math:dimensionless-p
math:quantity-specification-dimensionpercent-proportion
ok
=1000
ok
ok
=1/1000
ok
=1/1000000
math:unit-conversion-factor:parts-per-million:one
ok
math:dimension='
:duration-1
math:quantity-specification-dimension
multiple-value-bind
convertedfactor
ok
=factor1000
ok
eq:distance
math:quantity-specification-nameconverted
ok
math:unit-expression=:metre
math:quantity-specification-unitconverted
multiple-value-bind
convertedfactor
ok
=factor1/100
ok
eq:proportion
math:quantity-specification-nameconverted
ok
math:unitless-p
math:quantity-specification-unitconverted
ok
signals
math:make-quantity-specification:duration:dimension:duration:unit:metre
'math:quantity-operation-error
ok
signals
math:make-quantity-specification:unitless:dimensionnil:unit:metre
'math:quantity-operation-error
deftestunits-are-admissible-only-for-their-semantic-quantity-kinds
let
ok
eq:angular-measure
math:quantity-specification-kindangle
ok
eq:proportion
math:quantity-specification-kindproportion
multiple-value-bind
convertedfactor
ok
=1factor
ok
eq:angular-measure
math:quantity-specification-kindconverted
ok
signals
math:make-quantity-specification:proportion:unit'
:radian1
:second-1
'math:quantity-operation-error
ok
eq:undefined-quantity-definition
handler-case
progn
math:make-quantity-specification:unregistered-distance:unit:metre
nil
math:quantity-operation-error
condition
math:quantity-operation-error-reasoncondition
deftestextrema-require-exactly-compatible-quantities
let
left
math:make-quantity-specification:distance:dimension:length:unit:metre
right
math:make-quantity-specification:distance:dimension:length:unit:metre
other-unit
math:make-quantity-specification:distance:dimension:length:unit:kilometre
deftestquantity-definitions-own-their-homogeneous-components
let
ok
equal'
:position-x:position-y
math:quantity-definition-componentsposition
ok
equal
math:quantity-definition-componentsposition
ok
eq:length
math:quantity-definition-kindposition-x
deftestsemantic-layouts-distinguish-vectors-from-packed-tuples
let*
ok
ok
eq:position-x
math:quantity-specification-nameposition-x
ok
math:unit-expression=:metre
math:quantity-specification-unitposition-x
ok
zerop
math:quantity-specification-tensor-orderposition-x
deftestsource-declarations-share-one-quantity-option-parser
let
point
math:make-declared-quantity-specification'
:quantity:position:unit:metre:tensor-order1:character:point
anonymous-vector
math:make-declared-quantity-specification'
:unit:one
:default-tensor-order1
ok
eq:position
math:quantity-specification-namepoint
ok
eq:point
math:quantity-specification-characterpoint
ok
=1
math:quantity-specification-tensor-orderpoint
ok
null
math:quantity-specification-nameanonymous-vector
ok
=1
math:quantity-specification-tensor-orderanonymous-vector
deftestrepresented-value-compatibility-checks-meaning-and-representation
let*
expected
math:make-represented-value-declaration:representation-type'real:quantity-specificationdistance:source-form'
parameterdistance
actual
math:make-represented-value-declaration:representation-type'double-float:quantity-specificationdistance:source-form'
wrong-meaning
math:make-represented-value-declaration:representation-type'double-float:quantity-specificationheight:source-form'
slotheight
wrong-representation
math:make-represented-value-declaration:representation-type'string:quantity-specificationdistance:source-form'
slotlabel
ok

The three-way affine character: point, absolute, difference. These are the executable claims of the V3 operation table in wiki figure #LNRY72.

math:define-quantity:light-level:kind:proportion:non-negative-pt
math:define-quantity:altitude:kind:length:character:point
defunoperation-reason
operator&restspecifications
handler-case
progn
apply#'math:derive-quantity-specificationoperatorspecifications
nil
math:quantity-operation-error
condition
math:quantity-operation-error-reasoncondition
deftestnon-negative-definitions-default-to-absolute-character
let
level
plain
ok
eq:absolute
math:quantity-specification-characterlevel
ok
eq:point
math:quantity-specification-characteraltitude
ok
eq:difference
math:quantity-specification-characterplain

The historical :affine-p spelling still means point, and an explicit :affine-p nil on a declared point yields a difference of that quantity.

ok
eq:point
math:quantity-specification-character
math:make-quantity-specification:distance:unit:metre:affine-pt
ok
eq:difference
math:quantity-specification-character
math:make-quantity-specification:altitude:unit:metre:affine-pnil
ok
signals
math:make-quantity-specification:distance:unit:metre:affine-pt:character:absolute
'error
deftestabsolute-and-difference-addition-follows-the-cone-rules
let*
ok
eq:absolute
math:quantity-specification-charactersum
ok
eq:absolute
math:quantity-specification-charactershifted
ok
eq:difference
math:quantity-specification-charactergap
ok
eq:absolute
math:quantity-specification-characterreduced
ok
eq:difference
math:quantity-specification-charactersigned

A derived difference is anonymous-in-character but named, so it no longer promises non-negativity.

deftestpoints-mix-with-amounts-and-differences-asymmetrically
let*
ok
eq:point
math:quantity-specification-characterraised
ok
eq:point
math:quantity-specification-characterlowered
ok
eq:difference
math:quantity-specification-characterspan
ok
ok
eq:cannot-subtract-point-from-amount
ok
eq:cannot-scale-affine-point
ok
eq:cannot-negate-point
deftestproducts-keep-absoluteness-only-when-every-factor-has-it
let*
level
delta
math:make-quantity-specification:light-level:unit:one:character:difference
metres
math:make-quantity-specification:distance:unit:metre:character:absolute
scaled-delta
ok
eq:absolute
math:quantity-specification-characterproduct
ok
eq:absolute
math:quantity-specification-characterratio
ok
eq:difference
math:quantity-specification-charactermixed
ok
eq:difference
math:quantity-specification-characterrate

A bare number is a scale factor and preserves the other character.

ok
eq:absolute
math:quantity-specification-characterscaled
ok
eq:difference
math:quantity-specification-characterscaled-delta
deftestnegating-an-amount-is-never-an-amount
let
level
delta
math:make-quantity-specification:light-level:unit:one:character:difference
ok
eq:cannot-negate-amount
ok
eq:difference
math:quantity-specification-character