Skip to content

Assert.IsAlmost

Name - Description Default Type
<input> The input can be of any number type or a sequence of such types. FloatFloat2Float3Float4IntInt2Int3Int4Int8Int16[ Any ]
<output> The output will be the input (passthrough). Any
Value The value to test against for almost equality. None FloatFloat2Float3Float4IntInt2Int3Int4Int8Int16[ Any ]
Abort If we should abort the process on failure. false Bool
Threshold The smallest difference to be considered equal. Should be greater than zero. 1.19209e-07 FloatInt

This assertion is used to check whether the input is almost equal to a given value.

Details

For non-decimal values (e.g. Int), :Epsilon is ignored and this shard acts as Assert.Is.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
;; :Abort = `true`, assertion true
;; => log no errors and don't abort program
8
(Assert.IsAlmost
 ;:Value
 7
 ;:Abort
 true
 ;:Epsilon
 1)

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
;; :Abort = `true`, assertion false
;; => abort the program
7.0
(Maybe
 (Assert.IsAlmost
  ;:Value
  8.0
  ;:Abort
  ;; uncomment next line to abort program on run
  ;true
  ))
[error] Failed assertion IsAlmost, input: 7 expected: 8
[error] Shard activation error, failed shard: Assert.IsAlmost, error: Assert failed - IsAlmost
[warning] Maybe shard Ignored an error: Assert failed - IsAlmost

 

1
2
3
4
5
6
7
8
;; :Abort = `false`, assertion true
;; => log no errors and don't abort program
8.0
(Assert.IsAlmost
 ;:Value
 8.0
 ;:Abort
 false)

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
;; :Abort = `false`, assertion false
;; => log assertion error but don't abort program
8.0
(Maybe
 (Assert.IsAlmost
  ;:Value
  7.999
  ;:Abort
  false
  ;:Epsilon
  0.0001))
[error] Failed assertion IsAlmost, input: 8 expected: 7.999
[error] Shard activation error, failed shard: Assert.IsAlmost, error: Assert failed - IsAlmost
[warning] Maybe shard Ignored an error: Assert failed - IsAlmost