mirror of
https://github.com/sigmasternchen/gleam-community-maths
synced 2025-03-15 07:59:01 +00:00
Change module name: tests -> predicates
This commit is contained in:
parent
1fe5d7c789
commit
24cf6faf2a
9 changed files with 154 additions and 154 deletions
|
@ -40,7 +40,7 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/piecewise
|
||||
import gleam_community/maths/arithmetics
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleam_community/maths/conversion
|
||||
import gleam/list
|
||||
import gleam/pair
|
||||
|
@ -66,19 +66,19 @@ import gleam/float
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/metrics
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
///
|
||||
/// [1.0, 1.0, 1.0]
|
||||
/// |> metrics.norm(1.0)
|
||||
/// |> tests.is_close(3.0, 0.0, tol)
|
||||
/// |> predicates.is_close(3.0, 0.0, tol)
|
||||
/// |> should.be_true()
|
||||
///
|
||||
/// [1.0, 1.0, 1.0]
|
||||
/// |> metrics.norm(-1.0)
|
||||
/// |> tests.is_close(0.3333333333333333, 0.0, tol)
|
||||
/// |> predicates.is_close(0.3333333333333333, 0.0, tol)
|
||||
/// |> should.be_true()
|
||||
/// }
|
||||
/// </details>
|
||||
|
@ -129,7 +129,7 @@ pub fn norm(arr: List(Float), p: Float) -> Float {
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/metrics
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
|
@ -144,7 +144,7 @@ pub fn norm(arr: List(Float), p: Float) -> Float {
|
|||
///
|
||||
/// let assert Ok(result) = metrics.manhatten_distance([0.0, 0.0], [1.0, 2.0])
|
||||
/// result
|
||||
/// |> tests.is_close(3.0, 0.0, tol)
|
||||
/// |> predicates.is_close(3.0, 0.0, tol)
|
||||
/// |> should.be_true()
|
||||
/// }
|
||||
/// </details>
|
||||
|
@ -184,7 +184,7 @@ pub fn manhatten_distance(
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/metrics
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
|
@ -203,7 +203,7 @@ pub fn manhatten_distance(
|
|||
///
|
||||
/// let assert Ok(result) = metrics.minkowski_distance([0.0, 0.0], [1.0, 2.0], 1.0)
|
||||
/// result
|
||||
/// |> tests.is_close(3.0, 0.0, tol)
|
||||
/// |> predicates.is_close(3.0, 0.0, tol)
|
||||
/// |> should.be_true()
|
||||
/// }
|
||||
/// </details>
|
||||
|
@ -261,7 +261,7 @@ pub fn minkowski_distance(
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/metrics
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
|
@ -276,7 +276,7 @@ pub fn minkowski_distance(
|
|||
///
|
||||
/// let assert Ok(result) = metrics.euclidean_distance([0.0, 0.0], [1.0, 2.0])
|
||||
/// result
|
||||
/// |> tests.is_close(2.23606797749979, 0.0, tol)
|
||||
/// |> predicates.is_close(2.23606797749979, 0.0, tol)
|
||||
/// |> should.be_true()
|
||||
/// }
|
||||
/// </details>
|
||||
|
@ -395,7 +395,7 @@ pub fn median(arr: List(Float)) -> Result(Float, String) {
|
|||
let count: Int = list.length(arr)
|
||||
let mid: Int = list.length(arr) / 2
|
||||
let sorted: List(Float) = list.sort(arr, float.compare)
|
||||
case tests.is_odd(count) {
|
||||
case predicates.is_odd(count) {
|
||||
// If there is an odd number of elements in the list, then the median
|
||||
// is just the middle value
|
||||
True -> {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
////
|
||||
//// ---
|
||||
////
|
||||
//// Tests: A module containing functions for testing various mathematical properties of numbers.
|
||||
//// Predicates: A module containing functions for testing various mathematical properties of numbers.
|
||||
////
|
||||
//// * **Tests**
|
||||
//// * [`is_close`](#is_close)
|
|
@ -106,13 +106,13 @@ pub fn arange(start: Float, stop: Float, step: Float) -> List(Float) {
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/sequences
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
/// let assert Ok(linspace) = sequences.linear_space(10.0, 50.0, 5, True)
|
||||
/// let assert Ok(result) =
|
||||
/// tests.all_close(linspace, [10.0, 20.0, 30.0, 40.0, 50.0], 0.0, tol)
|
||||
/// predicates.all_close(linspace, [10.0, 20.0, 30.0, 40.0, 50.0], 0.0, tol)
|
||||
/// result
|
||||
/// |> list.all(fn(x) { x == True })
|
||||
/// |> should.be_true()
|
||||
|
@ -186,13 +186,13 @@ pub fn linear_space(
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/sequences
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
/// let assert Ok(logspace) = sequences.logarithmic_space(1.0, 3.0, 3, True, 10.0)
|
||||
/// let assert Ok(result) =
|
||||
/// tests.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
/// predicates.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
/// result
|
||||
/// |> list.all(fn(x) { x == True })
|
||||
/// |> should.be_true()
|
||||
|
@ -247,13 +247,13 @@ pub fn logarithmic_space(
|
|||
/// import gleeunit/should
|
||||
/// import gleam_community/maths/elementary
|
||||
/// import gleam_community/maths/sequences
|
||||
/// import gleam_community/maths/tests
|
||||
/// import gleam_community/maths/predicates
|
||||
///
|
||||
/// pub fn example () {
|
||||
/// let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
/// let assert Ok(logspace) = sequences.geometric_space(10.0, 1000.0, 3, True)
|
||||
/// let assert Ok(result) =
|
||||
/// tests.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
/// predicates.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
/// result
|
||||
/// |> list.all(fn(x) { x == True })
|
||||
/// |> should.be_true()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleam_community/maths/conversion
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
@ -11,22 +11,22 @@ pub fn main() {
|
|||
pub fn float_to_degree_test() {
|
||||
let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
conversion.radians_to_degrees(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
conversion.radians_to_degrees(2.0 *. elementary.pi())
|
||||
|> tests.is_close(360.0, 0.0, tol)
|
||||
|> predicates.is_close(360.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
pub fn float_to_radian_test() {
|
||||
let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
conversion.degrees_to_radians(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
conversion.degrees_to_radians(360.0)
|
||||
|> tests.is_close(2.0 *. elementary.pi(), 0.0, tol)
|
||||
|> predicates.is_close(2.0 *. elementary.pi(), 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
import gleam/option
|
||||
|
@ -14,12 +14,12 @@ pub fn float_acos_test() {
|
|||
// points, with known function values
|
||||
let assert Ok(result) = elementary.acos(1.0)
|
||||
result
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) = elementary.acos(0.5)
|
||||
result
|
||||
|> tests.is_close(1.047197, 0.0, tol)
|
||||
|> predicates.is_close(1.047197, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -37,7 +37,7 @@ pub fn float_acosh_test() {
|
|||
// points, with known function values
|
||||
let assert Ok(result) = elementary.acosh(1.0)
|
||||
result
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -55,7 +55,7 @@ pub fn float_asin_test() {
|
|||
let assert Ok(tol) = elementary.power(-10.0, -6.0)
|
||||
let assert Ok(result) = elementary.asin(0.5)
|
||||
result
|
||||
|> tests.is_close(0.523598, 0.0, tol)
|
||||
|> predicates.is_close(0.523598, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -72,11 +72,11 @@ pub fn float_asinh_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.asinh(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.asinh(0.5)
|
||||
|> tests.is_close(0.481211, 0.0, tol)
|
||||
|> predicates.is_close(0.481211, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -85,11 +85,11 @@ pub fn float_atan_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.atan(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.atan(0.5)
|
||||
|> tests.is_close(0.463647, 0.0, tol)
|
||||
|> predicates.is_close(0.463647, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -98,46 +98,46 @@ pub fn math_atan2_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.atan2(0.0, 0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.atan2(0.0, 1.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check atan2(y=1.0, x=0.5)
|
||||
// Should be equal to atan(y / x) for any x > 0 and any y
|
||||
let result = elementary.atan(1.0 /. 0.5)
|
||||
elementary.atan2(1.0, 0.5)
|
||||
|> tests.is_close(result, 0.0, tol)
|
||||
|> predicates.is_close(result, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check atan2(y=2.0, x=-1.5)
|
||||
// Should be equal to pi + atan(y / x) for any x < 0 and y >= 0
|
||||
let result = elementary.pi() +. elementary.atan(2.0 /. -1.5)
|
||||
elementary.atan2(2.0, -1.5)
|
||||
|> tests.is_close(result, 0.0, tol)
|
||||
|> predicates.is_close(result, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check atan2(y=-2.0, x=-1.5)
|
||||
// Should be equal to atan(y / x) - pi for any x < 0 and y < 0
|
||||
let result = elementary.atan(-2.0 /. -1.5) -. elementary.pi()
|
||||
elementary.atan2(-2.0, -1.5)
|
||||
|> tests.is_close(result, 0.0, tol)
|
||||
|> predicates.is_close(result, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check atan2(y=1.5, x=0.0)
|
||||
// Should be equal to pi/2 for x = 0 and any y > 0
|
||||
let result = elementary.pi() /. 2.0
|
||||
elementary.atan2(1.5, 0.0)
|
||||
|> tests.is_close(result, 0.0, tol)
|
||||
|> predicates.is_close(result, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check atan2(y=-1.5, x=0.0)
|
||||
// Should be equal to -pi/2 for x = 0 and any y < 0
|
||||
let result = -1.0 *. elementary.pi() /. 2.0
|
||||
elementary.atan2(-1.5, 0.0)
|
||||
|> tests.is_close(result, 0.0, tol)
|
||||
|> predicates.is_close(result, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -147,12 +147,12 @@ pub fn float_atanh_test() {
|
|||
// points, with known function values
|
||||
let assert Ok(result) = elementary.atanh(0.0)
|
||||
result
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) = elementary.atanh(0.5)
|
||||
result
|
||||
|> tests.is_close(0.549306, 0.0, tol)
|
||||
|> predicates.is_close(0.549306, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -175,15 +175,15 @@ pub fn float_cos_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.cos(0.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.cos(elementary.pi())
|
||||
|> tests.is_close(-1.0, 0.0, tol)
|
||||
|> predicates.is_close(-1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.cos(0.5)
|
||||
|> tests.is_close(0.877582, 0.0, tol)
|
||||
|> predicates.is_close(0.877582, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -192,11 +192,11 @@ pub fn float_cosh_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.cosh(0.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.cosh(0.5)
|
||||
|> tests.is_close(1.127625, 0.0, tol)
|
||||
|> predicates.is_close(1.127625, 0.0, tol)
|
||||
|> should.be_true()
|
||||
// An (overflow) error might occur when given an input
|
||||
// value that will result in a too large output value
|
||||
|
@ -209,15 +209,15 @@ pub fn float_sin_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.sin(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.sin(0.5 *. elementary.pi())
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.sin(0.5)
|
||||
|> tests.is_close(0.479425, 0.0, tol)
|
||||
|> predicates.is_close(0.479425, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -226,11 +226,11 @@ pub fn float_sinh_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.sinh(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.sinh(0.5)
|
||||
|> tests.is_close(0.521095, 0.0, tol)
|
||||
|> predicates.is_close(0.521095, 0.0, tol)
|
||||
|> should.be_true()
|
||||
// An (overflow) error might occur when given an input
|
||||
// value that will result in a too large output value
|
||||
|
@ -243,11 +243,11 @@ pub fn math_tan_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.tan(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.tan(0.5)
|
||||
|> tests.is_close(0.546302, 0.0, tol)
|
||||
|> predicates.is_close(0.546302, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -256,19 +256,19 @@ pub fn math_tanh_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.tanh(0.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.tanh(25.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.tanh(-25.0)
|
||||
|> tests.is_close(-1.0, 0.0, tol)
|
||||
|> predicates.is_close(-1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.tanh(0.5)
|
||||
|> tests.is_close(0.462117, 0.0, tol)
|
||||
|> predicates.is_close(0.462117, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -277,11 +277,11 @@ pub fn float_exponential_test() {
|
|||
// Check that the function agrees, at some arbitrary input
|
||||
// points, with known function values
|
||||
elementary.exponential(0.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.exponential(0.5)
|
||||
|> tests.is_close(1.648721, 0.0, tol)
|
||||
|> predicates.is_close(1.648721, 0.0, tol)
|
||||
|> should.be_true()
|
||||
// An (overflow) error might occur when given an input
|
||||
// value that will result in a too large output value
|
||||
|
@ -298,7 +298,7 @@ pub fn float_natural_logarithm_test() {
|
|||
|
||||
let assert Ok(result) = elementary.natural_logarithm(0.5)
|
||||
result
|
||||
|> tests.is_close(-0.693147, 0.0, tol)
|
||||
|> predicates.is_close(-0.693147, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -352,7 +352,7 @@ pub fn float_logarithm_2_test() {
|
|||
|
||||
let assert Ok(result) = elementary.logarithm_2(5.0)
|
||||
result
|
||||
|> tests.is_close(2.321928, 0.0, tol)
|
||||
|> predicates.is_close(2.321928, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -367,17 +367,17 @@ pub fn float_logarithm_10_test() {
|
|||
// points, with known function values
|
||||
let assert Ok(result) = elementary.logarithm_10(1.0)
|
||||
result
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) = elementary.logarithm_10(10.0)
|
||||
result
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) = elementary.logarithm_10(50.0)
|
||||
result
|
||||
|> tests.is_close(1.69897, 0.0, tol)
|
||||
|> predicates.is_close(1.69897, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Check that we get an error when the function is evaluated
|
||||
|
@ -473,10 +473,10 @@ pub fn float_nth_root_test() {
|
|||
|
||||
pub fn float_constants_test() {
|
||||
elementary.e()
|
||||
|> tests.is_close(2.71828, 0.0, 0.00001)
|
||||
|> predicates.is_close(2.71828, 0.0, 0.00001)
|
||||
|> should.be_true()
|
||||
|
||||
elementary.pi()
|
||||
|> tests.is_close(3.14159, 0.0, 0.00001)
|
||||
|> predicates.is_close(3.14159, 0.0, 0.00001)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/metrics
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
|
@ -20,37 +20,37 @@ pub fn float_list_norm_test() {
|
|||
// points, with known function values
|
||||
[1.0, 1.0, 1.0]
|
||||
|> metrics.norm(1.0)
|
||||
|> tests.is_close(3.0, 0.0, tol)
|
||||
|> predicates.is_close(3.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[1.0, 1.0, 1.0]
|
||||
|> metrics.norm(-1.0)
|
||||
|> tests.is_close(0.3333333333333333, 0.0, tol)
|
||||
|> predicates.is_close(0.3333333333333333, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[-1.0, -1.0, -1.0]
|
||||
|> metrics.norm(-1.0)
|
||||
|> tests.is_close(0.3333333333333333, 0.0, tol)
|
||||
|> predicates.is_close(0.3333333333333333, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[-1.0, -1.0, -1.0]
|
||||
|> metrics.norm(1.0)
|
||||
|> tests.is_close(3.0, 0.0, tol)
|
||||
|> predicates.is_close(3.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[-1.0, -2.0, -3.0]
|
||||
|> metrics.norm(-10.0)
|
||||
|> tests.is_close(0.9999007044905545, 0.0, tol)
|
||||
|> predicates.is_close(0.9999007044905545, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[-1.0, -2.0, -3.0]
|
||||
|> metrics.norm(-100.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
[-1.0, -2.0, -3.0]
|
||||
|> metrics.norm(2.0)
|
||||
|> tests.is_close(3.7416573867739413, 0.0, tol)
|
||||
|> predicates.is_close(3.7416573867739413, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ pub fn float_list_manhatten_test() {
|
|||
// Manhatten distance (p = 1)
|
||||
let assert Ok(result) = metrics.manhatten_distance([0.0, 0.0], [1.0, 2.0])
|
||||
result
|
||||
|> tests.is_close(3.0, 0.0, tol)
|
||||
|> predicates.is_close(3.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -106,39 +106,39 @@ pub fn float_list_minkowski_test() {
|
|||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([1.0, 1.0], [1.0, 1.0], 1.0)
|
||||
result
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([0.0, 0.0], [1.0, 1.0], 10.0)
|
||||
result
|
||||
|> tests.is_close(1.0717734625362931, 0.0, tol)
|
||||
|> predicates.is_close(1.0717734625362931, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([0.0, 0.0], [1.0, 1.0], 100.0)
|
||||
result
|
||||
|> tests.is_close(1.0069555500567189, 0.0, tol)
|
||||
|> predicates.is_close(1.0069555500567189, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([0.0, 0.0], [1.0, 1.0], 10.0)
|
||||
result
|
||||
|> tests.is_close(1.0717734625362931, 0.0, tol)
|
||||
|> predicates.is_close(1.0717734625362931, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Euclidean distance (p = 2)
|
||||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([0.0, 0.0], [1.0, 2.0], 2.0)
|
||||
result
|
||||
|> tests.is_close(2.23606797749979, 0.0, tol)
|
||||
|> predicates.is_close(2.23606797749979, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
// Manhatten distance (p = 1)
|
||||
let assert Ok(result) =
|
||||
metrics.minkowski_distance([0.0, 0.0], [1.0, 2.0], 1.0)
|
||||
result
|
||||
|> tests.is_close(3.0, 0.0, tol)
|
||||
|> predicates.is_close(3.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ pub fn float_list_euclidean_test() {
|
|||
// Euclidean distance (p = 2)
|
||||
let assert Ok(result) = metrics.euclidean_distance([0.0, 0.0], [1.0, 2.0])
|
||||
result
|
||||
|> tests.is_close(2.23606797749979, 0.0, tol)
|
||||
|> predicates.is_close(2.23606797749979, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/sequences
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleam/list
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
@ -17,14 +17,14 @@ pub fn float_list_linear_space_test() {
|
|||
// ---> With endpoint included
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, 50.0, 5, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, 20.0, 30.0, 40.0, 50.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, 20.0, 30.0, 40.0, 50.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, 20.0, 5, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, 12.5, 15.0, 17.5, 20.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, 12.5, 15.0, 17.5, 20.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -34,7 +34,7 @@ pub fn float_list_linear_space_test() {
|
|||
// ----> Without endpoint included
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, 50.0, 5, False)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, 18.0, 26.0, 34.0, 42.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, 18.0, 26.0, 34.0, 42.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -42,7 +42,7 @@ pub fn float_list_linear_space_test() {
|
|||
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, 20.0, 5, False)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, 12.0, 14.0, 16.0, 18.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, 12.0, 14.0, 16.0, 18.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -51,7 +51,7 @@ pub fn float_list_linear_space_test() {
|
|||
// Try with negative stop
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, -50.0, 5, False)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, -2.0, -14.0, -26.0, -38.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, -2.0, -14.0, -26.0, -38.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -59,7 +59,7 @@ pub fn float_list_linear_space_test() {
|
|||
|
||||
let assert Ok(linspace) = sequences.linear_space(10.0, -20.0, 5, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [10.0, 2.5, -5.0, -12.5, -20.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [10.0, 2.5, -5.0, -12.5, -20.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -68,7 +68,7 @@ pub fn float_list_linear_space_test() {
|
|||
// Try with negative start
|
||||
let assert Ok(linspace) = sequences.linear_space(-10.0, 50.0, 5, False)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [-10.0, 2.0, 14.0, 26.0, 38.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [-10.0, 2.0, 14.0, 26.0, 38.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -76,7 +76,7 @@ pub fn float_list_linear_space_test() {
|
|||
|
||||
let assert Ok(linspace) = sequences.linear_space(-10.0, 20.0, 5, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(linspace, [-10.0, -2.5, 5.0, 12.5, 20.0], 0.0, tol)
|
||||
predicates.all_close(linspace, [-10.0, -2.5, 5.0, 12.5, 20.0], 0.0, tol)
|
||||
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|
@ -95,7 +95,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
// - Positive start, stop, base
|
||||
let assert Ok(logspace) = sequences.logarithmic_space(1.0, 3.0, 3, True, 10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -104,7 +104,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
let assert Ok(logspace) =
|
||||
sequences.logarithmic_space(1.0, 3.0, 3, True, -10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [-10.0, 100.0, -1000.0], 0.0, tol)
|
||||
predicates.all_close(logspace, [-10.0, 100.0, -1000.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -113,7 +113,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
let assert Ok(logspace) =
|
||||
sequences.logarithmic_space(1.0, -3.0, 3, True, -10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [-10.0, -0.1, -0.001], 0.0, tol)
|
||||
predicates.all_close(logspace, [-10.0, -0.1, -0.001], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -122,7 +122,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
let assert Ok(logspace) =
|
||||
sequences.logarithmic_space(1.0, -3.0, 3, True, 10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 0.1, 0.001], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 0.1, 0.001], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -131,7 +131,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
let assert Ok(logspace) =
|
||||
sequences.logarithmic_space(-1.0, 3.0, 3, True, 10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [0.1, 10.0, 1000.0], 0.0, tol)
|
||||
predicates.all_close(logspace, [0.1, 10.0, 1000.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -141,7 +141,7 @@ pub fn float_list_logarithmic_space_test() {
|
|||
let assert Ok(logspace) =
|
||||
sequences.logarithmic_space(1.0, 3.0, 3, False, 10.0)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 46.41588834, 215.443469], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 46.41588834, 215.443469], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -159,7 +159,7 @@ pub fn float_list_geometric_space_test() {
|
|||
// - Positive start, stop
|
||||
let assert Ok(logspace) = sequences.geometric_space(10.0, 1000.0, 3, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -167,7 +167,7 @@ pub fn float_list_geometric_space_test() {
|
|||
// - Positive start, negative stop
|
||||
let assert Ok(logspace) = sequences.geometric_space(10.0, 0.001, 3, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 0.1, 0.001], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 0.1, 0.001], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -175,7 +175,7 @@ pub fn float_list_geometric_space_test() {
|
|||
// - Positive stop, negative start
|
||||
let assert Ok(logspace) = sequences.geometric_space(0.1, 1000.0, 3, True)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [0.1, 10.0, 1000.0], 0.0, tol)
|
||||
predicates.all_close(logspace, [0.1, 10.0, 1000.0], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
@ -184,7 +184,7 @@ pub fn float_list_geometric_space_test() {
|
|||
// - Positive start, stop
|
||||
let assert Ok(logspace) = sequences.geometric_space(10.0, 1000.0, 3, False)
|
||||
let assert Ok(result) =
|
||||
tests.all_close(logspace, [10.0, 46.41588834, 215.443469], 0.0, tol)
|
||||
predicates.all_close(logspace, [10.0, 46.41588834, 215.443469], 0.0, tol)
|
||||
result
|
||||
|> list.all(fn(x) { x == True })
|
||||
|> should.be_true()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import gleam_community/maths/elementary
|
||||
import gleam_community/maths/special
|
||||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
import gleam/result
|
||||
|
@ -14,19 +14,19 @@ pub fn float_beta_function_test() {
|
|||
|
||||
// Valid input returns a result
|
||||
special.beta(-0.5, 0.5)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.beta(0.5, 0.5)
|
||||
|> tests.is_close(3.1415926535897927, 0.0, tol)
|
||||
|> predicates.is_close(3.1415926535897927, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.beta(0.5, -0.5)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.beta(5.0, 5.0)
|
||||
|> tests.is_close(0.0015873015873015873, 0.0, tol)
|
||||
|> predicates.is_close(0.0015873015873015873, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -35,23 +35,23 @@ pub fn float_error_function_test() {
|
|||
|
||||
// Valid input returns a result
|
||||
special.erf(-0.5)
|
||||
|> tests.is_close(-0.5204998778130465, 0.0, tol)
|
||||
|> predicates.is_close(-0.5204998778130465, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.erf(0.5)
|
||||
|> tests.is_close(0.5204998778130465, 0.0, tol)
|
||||
|> predicates.is_close(0.5204998778130465, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.erf(1.0)
|
||||
|> tests.is_close(0.8427007929497148, 0.0, tol)
|
||||
|> predicates.is_close(0.8427007929497148, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.erf(2.0)
|
||||
|> tests.is_close(0.9953222650189527, 0.0, tol)
|
||||
|> predicates.is_close(0.9953222650189527, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.erf(10.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -60,27 +60,27 @@ pub fn float_gamma_function_test() {
|
|||
|
||||
// Valid input returns a result
|
||||
special.gamma(-0.5)
|
||||
|> tests.is_close(-3.5449077018110318, 0.0, tol)
|
||||
|> predicates.is_close(-3.5449077018110318, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.gamma(0.5)
|
||||
|> tests.is_close(1.7724538509055159, 0.0, tol)
|
||||
|> predicates.is_close(1.7724538509055159, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.gamma(1.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.gamma(2.0)
|
||||
|> tests.is_close(1.0, 0.0, tol)
|
||||
|> predicates.is_close(1.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.gamma(3.0)
|
||||
|> tests.is_close(2.0, 0.0, tol)
|
||||
|> predicates.is_close(2.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.gamma(10.0)
|
||||
|> tests.is_close(362_880.0, 0.0, tol)
|
||||
|> predicates.is_close(362_880.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -99,21 +99,21 @@ pub fn float_incomplete_gamma_function_test() {
|
|||
// Valid input returns a result
|
||||
special.incomplete_gamma(1.0, 0.0)
|
||||
|> result.unwrap(-999.0)
|
||||
|> tests.is_close(0.0, 0.0, tol)
|
||||
|> predicates.is_close(0.0, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.incomplete_gamma(1.0, 2.0)
|
||||
|> result.unwrap(-999.0)
|
||||
|> tests.is_close(0.864664716763387308106, 0.0, tol)
|
||||
|> predicates.is_close(0.864664716763387308106, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.incomplete_gamma(2.0, 3.0)
|
||||
|> result.unwrap(-999.0)
|
||||
|> tests.is_close(0.8008517265285442280826, 0.0, tol)
|
||||
|> predicates.is_close(0.8008517265285442280826, 0.0, tol)
|
||||
|> should.be_true()
|
||||
|
||||
special.incomplete_gamma(3.0, 4.0)
|
||||
|> result.unwrap(-999.0)
|
||||
|> tests.is_close(1.523793388892911312363, 0.0, tol)
|
||||
|> predicates.is_close(1.523793388892911312363, 0.0, tol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import gleam_community/maths/tests
|
||||
import gleam_community/maths/predicates
|
||||
import gleam/list
|
||||
import gleeunit/should
|
||||
import gleeunit
|
||||
|
@ -14,7 +14,7 @@ pub fn float_is_close_test() {
|
|||
// if 'val' is within 1 percent of 'ref_val' +/- 0.1
|
||||
let rtol: Float = 0.01
|
||||
let atol: Float = 0.1
|
||||
tests.is_close(val, ref_val, rtol, atol)
|
||||
predicates.is_close(val, ref_val, rtol, atol)
|
||||
|> should.be_true()
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub fn float_list_all_close_test() {
|
|||
// if 'val' is within 1 percent of 'ref_val' +/- 0.1
|
||||
let rtol: Float = 0.01
|
||||
let atol: Float = 0.1
|
||||
tests.all_close(xarr, yarr, rtol, atol)
|
||||
predicates.all_close(xarr, yarr, rtol, atol)
|
||||
|> fn(zarr: Result(List(Bool), String)) -> Result(Bool, Nil) {
|
||||
case zarr {
|
||||
Ok(arr) ->
|
||||
|
@ -43,101 +43,101 @@ pub fn float_list_all_close_test() {
|
|||
}
|
||||
|
||||
pub fn float_is_fractional_test() {
|
||||
tests.is_fractional(1.5)
|
||||
predicates.is_fractional(1.5)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_fractional(0.5)
|
||||
predicates.is_fractional(0.5)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_fractional(0.3333)
|
||||
predicates.is_fractional(0.3333)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_fractional(0.9999)
|
||||
predicates.is_fractional(0.9999)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_fractional(1.0)
|
||||
predicates.is_fractional(1.0)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_fractional(999.0)
|
||||
predicates.is_fractional(999.0)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn int_is_power_test() {
|
||||
tests.is_power(10, 10)
|
||||
predicates.is_power(10, 10)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_power(11, 10)
|
||||
predicates.is_power(11, 10)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_power(4, 2)
|
||||
predicates.is_power(4, 2)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_power(5, 2)
|
||||
predicates.is_power(5, 2)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_power(27, 3)
|
||||
predicates.is_power(27, 3)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_power(28, 3)
|
||||
predicates.is_power(28, 3)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn int_is_even_test() {
|
||||
tests.is_even(0)
|
||||
predicates.is_even(0)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_even(2)
|
||||
predicates.is_even(2)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_even(12)
|
||||
predicates.is_even(12)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_even(5)
|
||||
predicates.is_even(5)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_even(-3)
|
||||
predicates.is_even(-3)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_even(-4)
|
||||
predicates.is_even(-4)
|
||||
|> should.equal(True)
|
||||
}
|
||||
|
||||
pub fn int_is_odd_test() {
|
||||
tests.is_odd(0)
|
||||
predicates.is_odd(0)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_odd(3)
|
||||
predicates.is_odd(3)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_odd(13)
|
||||
predicates.is_odd(13)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_odd(4)
|
||||
predicates.is_odd(4)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_odd(-3)
|
||||
predicates.is_odd(-3)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_odd(-4)
|
||||
predicates.is_odd(-4)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
||||
pub fn int_is_perfect_test() {
|
||||
tests.is_perfect(6)
|
||||
predicates.is_perfect(6)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_perfect(28)
|
||||
predicates.is_perfect(28)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_perfect(496)
|
||||
predicates.is_perfect(496)
|
||||
|> should.equal(True)
|
||||
|
||||
tests.is_perfect(1)
|
||||
predicates.is_perfect(1)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_perfect(3)
|
||||
predicates.is_perfect(3)
|
||||
|> should.equal(False)
|
||||
|
||||
tests.is_perfect(13)
|
||||
predicates.is_perfect(13)
|
||||
|> should.equal(False)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue