Skip to content

Assert.IsAlmost

Name Mandatory 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 No The value to test against for almost equality. none FloatFloat2Float3Float4IntInt2Int3Int4Int8Int16[Any]Var(Float Float2 Float3 Float4 Int Int2 Int3 Int4 Int8 Int16 [Any])
Break No If we should trigger a debug breakpoint on failure. false Bool
Threshold No 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
; :Break = `true`, assertion true
; => log no errors and dont abort program
8 | Assert.IsAlmost(7 Break: true Threshold: 1)


 

1
2
3
4
5
; :Break = `true`, assertion false
; => abort the program
7.0 | Maybe({
  Assert.IsAlmost(8.0 Break: true)
})

[error] Failed assertion IsAlmost, input: 7 expected: 8
[error] Assert.IsAlmost -> Error: Assert failed - IsAlmost, Line: 4, Column: 3
[warning] Maybe shard Ignored an error: Assert failed - IsAlmost, line: 3, column: 7, wire: sample-wire
 

1
2
3
; :Break = `false`, assertion true
; => log no errors and dont abort program
8.0 | Assert.IsAlmost(8.0 Break: false)


 

1
2
3
4
5
; :Break = `false`, assertion false
; => log assertion error but dont abort program
8.0 | Maybe({
  Assert.IsAlmost(7.999 Break: false Threshold: 0.0001)
})

[error] Failed assertion IsAlmost, input: 8 expected: 7.999
[error] Assert.IsAlmost -> Error: Assert failed - IsAlmost, Line: 4, Column: 3
[warning] Maybe shard Ignored an error: Assert failed - IsAlmost, line: 3, column: 7, wire: sample-wire