Scalactic User Guide

Custom equality

Default equality

Constrained equality



The Explicitly DSL

Or and Every





The Tolerance trait contains an implicit conversion that adds a +- method to Numeric types, which, combined with one of the TripleEquals traits, enables you to determine whether the numeric value is with a tolerance.

For example, the TripleEquals trait (and its type-checking siblings TypeCheckedTripleEquals and ConversionCheckedTripleEquals) enable you to write:

result === 10.0 +- 0.5

Here are some examples in the Scala REPL:

scala> import org.scalactic._
import org.scalactic._

scala> import TripleEquals._
import TripleEquals._

scala> import Tolerance._
import Tolerance._

scala> val result = 2.000001
result: Double = 2.000001

scala> result === 2.0 +- .001
res0: Boolean = true

scala> result === 2.0 +- .000000001
res1: Boolean = false

Next, learn about Normalization.

Scalactic is brought to you by Bill Venners, with contributions from several other folks. It is sponsored by Artima, Inc.
ScalaTest is free, open-source software released under the Apache 2.0 license.

Copyright © 2009-2024 Artima, Inc. All Rights Reserved.