This module contains functions that construct Expectations
for elm-geometry types. In general, all expectations use an
absolute-or-relative tolerance of 1e-12; for example,
actualPoint |> Expect.point2d expectedPointwill pass if the distance from actualPoint to expectedPoint is less than
1e-12 meters or if it is less than 1e-12 times the distance of actualPoint
from the origin (so that a larger absolute tolerance is used for points far from
the origin).
This module has been designed so that in most cases you can use
import Geometry.Expect as Expectto 'merge' it with the Expect module from elm-explorations/test, without
running into any naming conflicts; examples in this module assume the module has
been imported this way.
Check if a Maybe value is of the form Just x and x satisfies the given
expectation function. For example, since Vector2d.direction returns a Maybe
Direction2d, you might test it like
Vector2d.meters 2 2
|> Vector2d.direction
|> Expect.just
(Expect.direction2d (Direction2d.degrees 45))Note that if you want to verify that a function returns Nothing, you can
simply use Expect.equal:
Vector2d.meters 0 0
|> Vector2d.direction
|> Expect.equal NothingQuantity equalityCheck that one Quantity
value is approximately equal to another.
Check that some Quantity value is equal to another within a specified
absolute tolerance:
actualValue
|> Expect.quantityWithin givenTolerance
expectedValue
-- Passes:
Length.meters 1.05
|> Expect.quantityWithin (Length.centimeters 10)
(Length.meters 1)
-- Fails:
Length.meters 1.05
|> Expect.quantityWithin (Length.centimeters 1)
(Length.meters 1)Check that one Angle is approximately equal to another.
Note that this will consider angles in the geometric sense, not the numerical
sense; 0 degrees, 360 degrees, 720 degrees and -360 degrees are all considered
to be equal. However, since Angle values are also Quantity values, you can
use Expect.quantity if you do want a pure numerical comparison.
Check if two angles are equal within a given tolerance. Note that as with
angle, this will properly handle angles that 'wrap around':
-- Passes because geometrically speaking, there's only
-- a 4 degree difference between 358 degrees and 2
-- degrees:
Angle.degrees 358
|> Expect.angleWithin (Angle.degrees 5)
(Angle.degrees 2)Quantity comparisonThese functions all behave just like the corresponding ones in
elm-explorations/test.
Unlike most other functions in this module, they do not implicitly include a
tolerance.
Check that two Point2d values are approximately equal.
Check that two Point2d values are equal to within the given tolerance
(the distance between the two points is less than that tolerance).
Check that a Point2d is approximately contained in a given
BoundingBox2d.
Check that two Point3d values are approximately equal.
Check that two Point3d values are equal to within the given tolerance
(the distance between the two points is less than that tolerance).
Check that a Point3d is approximately contained in a given
BoundingBox3d.
Check that two Vector2d values are approximately equal.
Check that two Vector2d values are equal to within the given tolerance
(the difference between the two vectors has magnitude less than that tolerance).
Check that two Vector3d values are approximately equal.
Check that two Vector3d values are equal to within the given tolerance
(the difference between the two vectors has magnitude less than that tolerance).
Check that two Direction2d values are approximately equal.
Check that two Direction2d values are equal to within the given angular
tolerance.
Check that one Direction2d is approximately perpendicular to another.
Check that two Direction3d values are approximately equal.
Check that two Direction3d values are equal to within the given angular
tolerance.
Check that one Direction3d is approximately perpendicular to another.
Check that two BoundingBox2d values are approximately equal (have the same
min/max values).
Check that two BoundingBox2d values are equal within the given tolerance
(every min/max value of the first box is equal, to within the given tolerance,
of the corresponding min/max value of the second box).
Check that two BoundingBox3d values are approximately equal (have the same
min/max values).
Check that two BoundingBox3d values are equal within the given tolerance
(every min/max value of the first box is equal, to within the given tolerance,
of the corresponding min/max value of the second box).
Check that two LineSegment2d values are approximately equal (have the same
endpoints).
Check that two LineSegment2d values are equal within the given tolerance
(the endpoints of one are equal to the endpoints of the other, within the given
tolerance).
Check that two LineSegment3d values are approximately equal (have the same
endpoints).
Check that two LineSegment3d values are equal within the given tolerance
(the endpoints of one are equal to the endpoints of the other, within the given
tolerance).
Check that two Triangle2d values are approximately equal (have the same
vertices).
Check that two Triangle2d values are equal within the given tolerance
(each vertex of the first triangle is equal to the corresponding vertex of the
second triangle, within the given tolerance).
Check that two Triangle3d values are approximately equal (have the same
vertices).
Check that two Triangle3d values are equal within the given tolerance
(each vertex of the first triangle is equal to the corresponding vertex of the
second triangle, within the given tolerance).
Check that two Polyline2d values are approximately equal (have the same
vertices).
Check that two Polyline2d values are equal within the given tolerance
(have the same number of vertices, and each vertex of the first polyline is
equal to the corresponding vertex of the second polyline within the given
tolerance).
Check that two Polyline3d values are approximately equal (have the same
vertices).
Check that two Polyline3d values are equal within the given tolerance
(have the same number of vertices, and each vertex of the first polyline is
equal to the corresponding vertex of the second polyline within the given
tolerance).
Check that two Polygon2d values are approximately equal (have the same
vertices).
Check that two Polygon2d values are equal within the given tolerance (have
the same number of vertices, and each vertex of the first polygon is equal to
the corresponding vertex of the second polygon within the given tolerance).
Check that two Arc2d values are approximately equal (have the same
start point, end point and swept angle).
Check that two Arc3d values are approximately equal (have the same
start point, end point, swept angle and axial direction).
Check that two Circle2d values are approximately equal (have the same
center point and radius).
Check that two Circle3d values are approximately equal (have the same
center point, axial direction and radius).
Check that two CubicSpline2d values are approximately equal (have the
same control points).
Check that two CubicSpline3d values are approximately equal (have the
same control points).
Check that two Cylinder3d values are approximately equal (have the same
center point, axial direction, radius and length).
Check that two QuadraticSpline2d values are approximately equal (have the
same control points).
Check that two QuadraticSpline3d values are approximately equal (have the
same control points).
Check that two Sphere3d values are approximately equal (have the same
center point and radius).
Check that two Axis2d values are approximately equal (have the same
origin point and direction).
Check that two Axis3d values are approximately equal (have the same
origin point and direction).
Check that two Frame2d values are approximately equal (have the same
origin point and X/Y directions).
Check that two Frame3d values are approximately equal (have the same
origin point and X/Y/Z directions).
Check that two Plane3d values are approximately equal (have the same
origin point and normal direction).
Check that two SketchPlane3d values are approximately equal (have the same
origin point and X/Y directions).
These functions check for things like "directions have length 1", "bounding box
min and max values are in the correct order", and "frame basis directions are
mutually perpendicular". Since these properties are generally guaranteed by
elm-geometry, it should only be necessary to use these expectation functions
if you have some low-level code that calls functions such as
Direction2d.unsafe or Frame3d.unsafe.
Check if one
Floatvalue is exactly equal to another.Note that this is usually only desirable in low-level numeric code and most tests should use
Expect.float.