From e01373c0bfd3aa831d0df66c50f8e93acaea681d Mon Sep 17 00:00:00 2001 From: NicklasXYZ <18580183+NicklasXYZ@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:40:33 +0100 Subject: [PATCH] Rename functions. Fix FFI --- src/gleam_community/maths.gleam | 99 +++++++++------------ test/gleam_community/arithmetics_test.gleam | 56 ++++++------ test/gleam_community/conversion_test.gleam | 8 +- test/gleam_community/elementary_test.gleam | 34 +++---- test/gleam_community/metrics_test.gleam | 10 +-- test/gleam_community/piecewise_test.gleam | 70 +++++++-------- test/gleam_community/sequences_test.gleam | 12 +-- 7 files changed, 138 insertions(+), 151 deletions(-) diff --git a/src/gleam_community/maths.gleam b/src/gleam_community/maths.gleam index b5a76a4..b102195 100644 --- a/src/gleam_community/maths.gleam +++ b/src/gleam_community/maths.gleam @@ -110,13 +110,13 @@ fn do_gcd(x: Int, y: Int) -> Int { /// import gleam_community/maths /// /// pub fn example() { -/// maths.int_euclidean_modulo(15, 4) +/// maths.euclidean_modulo(15, 4) /// |> should.equal(3) /// -/// maths.int_euclidean_modulo(-3, -2) +/// maths.euclidean_modulo(-3, -2) /// |> should.equal(1) /// -/// maths.int_euclidean_modulo(5, 0) +/// maths.euclidean_modulo(5, 0) /// |> should.equal(0) /// } /// @@ -127,7 +127,7 @@ fn do_gcd(x: Int, y: Int) -> Int { /// /// /// -pub fn int_euclidean_modulo(x: Int, y: Int) -> Int { +pub fn euclidean_modulo(x: Int, y: Int) -> Int { case x % y, x, y { _, 0, _ -> 0 _, _, 0 -> 0 @@ -302,15 +302,15 @@ pub fn proper_divisors(n: Int) -> List(Int) { /// /// pub fn example () { /// [] -/// |> maths.float_weighted_sum() +/// |> maths.weighted_sum() /// |> should.equal(Ok(0.0)) /// /// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)] -/// |> maths.float_weighted_sum() +/// |> maths.weighted_sum() /// |> should.equal(Ok(6.0)) /// /// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)] -/// |> maths.float_weighted_sum() +/// |> maths.weighted_sum() /// |> should.equal(Ok(14.5)) /// } /// @@ -321,7 +321,7 @@ pub fn proper_divisors(n: Int) -> List(Int) { /// /// /// -pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) { +pub fn weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) { case arr { [] -> Ok(0.0) _ -> { @@ -364,17 +364,17 @@ pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) { /// /// pub fn example () { /// [] -/// |> maths.float_weighted_product() +/// |> maths.weighted_product() /// |> should.equal(Ok(1.0)) /// /// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)] -/// |> maths.float_weighted_product() +/// |> maths.weighted_product() /// |> should.equal(Ok(6.0)) /// /// let assert Ok(tolerance) = float.power(10.0, -6.0) /// let assert Ok(result) = /// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)] -/// |> maths.float_weighted_product() +/// |> maths.weighted_product() /// result /// |> maths.is_close(30.0, 0.0, tolerance) /// |> should.be_true() @@ -387,7 +387,7 @@ pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) { /// /// /// -pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) { +pub fn weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) { case arr { [] -> Ok(1.0) _ -> { @@ -435,11 +435,11 @@ pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) /// /// pub fn example () { /// [] -/// |> maths.float_cumulative_sum() +/// |> maths.cumulative_sum() /// |> should.equal([]) /// /// [1.0, 2.0, 3.0] -/// |> maths.float_cumulative_sum() +/// |> maths.cumulative_sum() /// |> should.equal([1.0, 3.0, 6.0]) /// } /// @@ -450,7 +450,7 @@ pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) /// /// /// -pub fn float_cumulative_sum(arr: List(Float)) -> List(Float) { +pub fn cumulative_sum(arr: List(Float)) -> List(Float) { case arr { [] -> [] _ -> list.scan(arr, 0.0, fn(acc, a) { a +. acc }) @@ -530,11 +530,11 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) { /// /// pub fn example () { /// [] -/// |> maths.float_cumulative_product() +/// |> maths.cumulative_product() /// |> should.equal([]) /// /// [1.0, 2.0, 3.0] -/// |> maths.float_cumulative_product() +/// |> maths.cumulative_product() /// |> should.equal([1.0, 2.0, 6.0]) /// } /// @@ -545,7 +545,7 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) { /// /// /// -pub fn float_cumulative_product(arr: List(Float)) -> List(Float) { +pub fn cumulative_product(arr: List(Float)) -> List(Float) { case arr { [] -> [] _ -> list.scan(arr, 1.0, fn(acc, a) { a *. acc }) @@ -1792,15 +1792,15 @@ pub fn round_to_nearest(x: Float, p: Int) -> Float { let xabs_truncated = truncate_float(xabs) let remainder = xabs -. xabs_truncated case remainder { - _ if remainder >. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p + _ if remainder >. 0.5 -> sign(x) *. truncate_float(xabs +. 1.0) /. p _ if remainder == 0.5 -> { let assert Ok(is_even) = int.modulo(float.truncate(xabs), 2) case is_even == 0 { - True -> float_sign(x) *. xabs_truncated /. p - False -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p + True -> sign(x) *. xabs_truncated /. p + False -> sign(x) *. truncate_float(xabs +. 1.0) /. p } } - _ -> float_sign(x) *. xabs_truncated /. p + _ -> sign(x) *. xabs_truncated /. p } } @@ -1855,8 +1855,8 @@ pub fn round_ties_away(x: Float, p: Int) -> Float { let xabs = float.absolute_value(x) *. p let remainder = xabs -. truncate_float(xabs) case remainder { - _ if remainder >=. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p - _ -> float_sign(x) *. truncate_float(xabs) /. p + _ if remainder >=. 0.5 -> sign(x) *. truncate_float(xabs +. 1.0) /. p + _ -> sign(x) *. truncate_float(xabs) /. p } } @@ -1913,8 +1913,8 @@ pub fn round_ties_up(x: Float, p: Int) -> Float { let remainder = xabs -. xabs_truncated case remainder { _ if remainder >=. 0.5 && x >=. 0.0 -> - float_sign(x) *. truncate_float(xabs +. 1.0) /. p - _ -> float_sign(x) *. xabs_truncated /. p + sign(x) *. truncate_float(xabs +. 1.0) /. p + _ -> sign(x) *. xabs_truncated /. p } } @@ -2109,10 +2109,10 @@ fn do_ceiling(a: Float) -> Float /// import gleam_community/maths /// /// pub fn example() { -/// maths.float_absolute_difference(-10.0, 10.0) +/// maths.absolute_difference(-10.0, 10.0) /// |> should.equal(20.0) /// -/// maths.float_absolute_difference(0.0, -2.0) +/// maths.absolute_difference(0.0, -2.0) /// |> should.equal(2.0) /// } /// @@ -2123,9 +2123,8 @@ fn do_ceiling(a: Float) -> Float /// /// /// -pub fn float_absolute_difference(a: Float, b: Float) -> Float { - a -. b - |> float.absolute_value() +pub fn absolute_difference(a: Float, b: Float) -> Float { + float.absolute_value(a -. b) } ///
@@ -2165,8 +2164,7 @@ pub fn float_absolute_difference(a: Float, b: Float) -> Float { ///
/// pub fn int_absolute_difference(a: Int, b: Int) -> Int { - a - b - |> int.absolute_value() + int.absolute_value(a - b) } ///
@@ -2185,12 +2183,12 @@ pub fn int_absolute_difference(a: Int, b: Int) -> Int { /// ///
/// -pub fn float_sign(x: Float) -> Float { - do_float_sign(x) +pub fn sign(x: Float) -> Float { + do_sign(x) } -@target(erlang) -fn do_float_sign(x: Float) -> Float { +@external(javascript, "../maths.mjs", "sign") +fn do_sign(x: Float) -> Float { case x { _ if x <. 0.0 -> -1.0 _ if x >. 0.0 -> 1.0 @@ -2198,10 +2196,6 @@ fn do_float_sign(x: Float) -> Float { } } -@target(javascript) -@external(javascript, "../maths.mjs", "sign") -fn do_float_sign(a: Float) -> Float - ///
/// /// Spot a typo? Open an issue! @@ -2222,7 +2216,7 @@ pub fn int_sign(x: Int) -> Int { do_int_sign(x) } -@target(erlang) +@external(javascript, "../maths.mjs", "sign") fn do_int_sign(x: Int) -> Int { case x { _ if x < 0 -> -1 @@ -2231,10 +2225,6 @@ fn do_int_sign(x: Int) -> Int { } } -@target(javascript) -@external(javascript, "../maths.mjs", "sign") -fn do_int_sign(a: Int) -> Int - ///
/// /// Spot a typo? Open an issue! @@ -2250,14 +2240,14 @@ fn do_int_sign(a: Int) -> Int /// ///
/// -pub fn float_copy_sign(x: Float, y: Float) -> Float { - case float_sign(x) == float_sign(y) { +pub fn copy_sign(x: Float, y: Float) -> Float { + case sign(x) == sign(y) { // x and y have the same sign, just return x True -> x // x and y have different signs: // - x is positive and y is negative, then flip sign of x // - x is negative and y is positive, then flip sign of x - False -> float_flip_sign(x) + False -> flip_sign(x) } } @@ -2301,7 +2291,7 @@ pub fn int_copy_sign(x: Int, y: Int) -> Int { /// ///
/// -pub fn float_flip_sign(x: Float) -> Float { +pub fn flip_sign(x: Float) -> Float { -1.0 *. x } @@ -4734,12 +4724,9 @@ pub fn braycurtis_distance_with_weights( /// /// pub fn is_close(x: Float, y: Float, rtol: Float, atol: Float) -> Bool { - let x = float_absolute_difference(x, y) + let x = absolute_difference(x, y) let y = atol +. rtol *. float.absolute_value(y) - case x <=. y { - True -> True - False -> False - } + x <=. y } ///
@@ -5196,7 +5183,7 @@ pub fn erf(x: Float) -> Float { ] let p = 0.3275911 - let sign = float_sign(x) + let sign = sign(x) let x = float.absolute_value(x) // Formula 7.1.26 given in Abramowitz and Stegun. diff --git a/test/gleam_community/arithmetics_test.gleam b/test/gleam_community/arithmetics_test.gleam index 6cbc9ec..626682f 100644 --- a/test/gleam_community/arithmetics_test.gleam +++ b/test/gleam_community/arithmetics_test.gleam @@ -22,35 +22,35 @@ pub fn int_gcd_test() { |> should.equal(6) } -pub fn int_euclidean_modulo_test() { +pub fn euclidean_modulo_test() { // Base Case: Positive x, Positive y // Note that the truncated, floored, and euclidean // definitions should agree for this base case - maths.int_euclidean_modulo(15, 4) + maths.euclidean_modulo(15, 4) |> should.equal(3) // Case: Positive x, Negative y - maths.int_euclidean_modulo(15, -4) + maths.euclidean_modulo(15, -4) |> should.equal(3) // Case: Negative x, Positive y - maths.int_euclidean_modulo(-15, 4) + maths.euclidean_modulo(-15, 4) |> should.equal(1) // Case: Negative x, Negative y - maths.int_euclidean_modulo(-15, -4) + maths.euclidean_modulo(-15, -4) |> should.equal(1) // Case: Positive x, Zero y - maths.int_euclidean_modulo(5, 0) + maths.euclidean_modulo(5, 0) |> should.equal(0) // Case: Zero x, Negative y - maths.int_euclidean_modulo(0, 5) + maths.euclidean_modulo(0, 5) |> should.equal(0) } -pub fn int_lcm_test() { +pub fn lcm_test() { maths.lcm(1, 1) |> should.equal(1) @@ -70,7 +70,7 @@ pub fn int_lcm_test() { |> should.equal(210) } -pub fn int_proper_divisors_test() { +pub fn proper_divisors_test() { maths.proper_divisors(2) |> should.equal([1]) @@ -84,7 +84,7 @@ pub fn int_proper_divisors_test() { |> should.equal([1, 2, 3, 6, 9]) } -pub fn int_divisors_test() { +pub fn divisors_test() { maths.divisors(2) |> should.equal([1, 2]) @@ -98,19 +98,19 @@ pub fn int_divisors_test() { |> should.equal([1, 2, 3, 6, 9, 18]) } -pub fn float_list_cumulative_sum_test() { +pub fn list_cumulative_sum_test() { // An empty lists returns an empty list [] - |> maths.float_cumulative_sum() + |> maths.cumulative_sum() |> should.equal([]) // Valid input returns a result [1.0, 2.0, 3.0] - |> maths.float_cumulative_sum() + |> maths.cumulative_sum() |> should.equal([1.0, 3.0, 6.0]) [-2.0, 4.0, 6.0] - |> maths.float_cumulative_sum() + |> maths.cumulative_sum() |> should.equal([-2.0, 2.0, 8.0]) } @@ -130,19 +130,19 @@ pub fn int_list_cumulative_sum_test() { |> should.equal([-2, 2, 8]) } -pub fn float_list_cumulative_product_test() { +pub fn list_cumulative_product_test() { // An empty lists returns an empty list [] - |> maths.float_cumulative_product() + |> maths.cumulative_product() |> should.equal([]) // Valid input returns a result [1.0, 2.0, 3.0] - |> maths.float_cumulative_product() + |> maths.cumulative_product() |> should.equal([1.0, 2.0, 6.0]) [-2.0, 4.0, 6.0] - |> maths.float_cumulative_product() + |> maths.cumulative_product() |> should.equal([-2.0, -8.0, -48.0]) } @@ -162,42 +162,42 @@ pub fn int_list_cumulative_product_test() { |> should.equal([-2, -8, -48]) } -pub fn float_weighted_product_test() { +pub fn weighted_product_test() { [] - |> maths.float_weighted_product() + |> maths.weighted_product() |> should.equal(Ok(1.0)) [#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)] - |> maths.float_weighted_product() + |> maths.weighted_product() |> should.equal(Ok(1.0)) [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)] - |> maths.float_weighted_product() + |> maths.weighted_product() |> should.equal(Ok(6.0)) let assert Ok(tolerance) = float.power(10.0, -6.0) let assert Ok(result) = [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)] - |> maths.float_weighted_product() + |> maths.weighted_product() result |> maths.is_close(30.0, 0.0, tolerance) |> should.be_true() } -pub fn float_weighted_sum_test() { +pub fn weighted_sum_test() { [] - |> maths.float_weighted_sum() + |> maths.weighted_sum() |> should.equal(Ok(0.0)) [#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)] - |> maths.float_weighted_sum() + |> maths.weighted_sum() |> should.equal(Ok(0.0)) [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)] - |> maths.float_weighted_sum() + |> maths.weighted_sum() |> should.equal(Ok(6.0)) [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)] - |> maths.float_weighted_sum() + |> maths.weighted_sum() |> should.equal(Ok(14.5)) } diff --git a/test/gleam_community/conversion_test.gleam b/test/gleam_community/conversion_test.gleam index 081089c..9b03f13 100644 --- a/test/gleam_community/conversion_test.gleam +++ b/test/gleam_community/conversion_test.gleam @@ -2,7 +2,7 @@ import gleam/float import gleam_community/maths import gleeunit/should -pub fn float_to_degree_test() { +pub fn to_degree_test() { let assert Ok(tol) = float.power(10.0, -6.0) maths.radians_to_degrees(0.0) |> maths.is_close(0.0, 0.0, tol) @@ -13,7 +13,7 @@ pub fn float_to_degree_test() { |> should.be_true() } -pub fn float_to_radian_test() { +pub fn to_radian_test() { let assert Ok(tol) = float.power(10.0, -6.0) maths.degrees_to_radians(0.0) |> maths.is_close(0.0, 0.0, tol) @@ -24,7 +24,7 @@ pub fn float_to_radian_test() { |> should.be_true() } -pub fn float_cartesian_to_polar_test() { +pub fn cartesian_to_polar_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Test: Cartesian (1, 0) -> Polar (1, 0) @@ -68,7 +68,7 @@ pub fn float_cartesian_to_polar_test() { |> should.be_true() } -pub fn float_polar_to_cartesian_test() { +pub fn polar_to_cartesian_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Test: Polar (1, 0) -> Cartesian (1, 0) diff --git a/test/gleam_community/elementary_test.gleam b/test/gleam_community/elementary_test.gleam index ed833f2..9f49106 100644 --- a/test/gleam_community/elementary_test.gleam +++ b/test/gleam_community/elementary_test.gleam @@ -2,7 +2,7 @@ import gleam/float import gleam_community/maths import gleeunit/should -pub fn float_acos_test() { +pub fn acos_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -25,7 +25,7 @@ pub fn float_acos_test() { |> should.be_error() } -pub fn float_acosh_test() { +pub fn acosh_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -40,7 +40,7 @@ pub fn float_acosh_test() { |> should.be_error() } -pub fn float_asin_test() { +pub fn asin_test() { // Check that the function agrees, at some arbitrary input // points, with known function values maths.asin(0.0) @@ -61,7 +61,7 @@ pub fn float_asin_test() { |> should.be_error() } -pub fn float_asinh_test() { +pub fn asinh_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -74,7 +74,7 @@ pub fn float_asinh_test() { |> should.be_true() } -pub fn float_atan_test() { +pub fn atan_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -135,7 +135,7 @@ pub fn math_atan2_test() { |> should.be_true() } -pub fn float_atanh_test() { +pub fn atanh_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -164,7 +164,7 @@ pub fn float_atanh_test() { |> should.be_error() } -pub fn float_cos_test() { +pub fn cos_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -181,7 +181,7 @@ pub fn float_cos_test() { |> should.be_true() } -pub fn float_cosh_test() { +pub fn cosh_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -198,7 +198,7 @@ pub fn float_cosh_test() { // runtime. } -pub fn float_sin_test() { +pub fn sin_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -215,7 +215,7 @@ pub fn float_sin_test() { |> should.be_true() } -pub fn float_sinh_test() { +pub fn sinh_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -266,7 +266,7 @@ pub fn math_tanh_test() { |> should.be_true() } -pub fn float_exponential_test() { +pub fn exponential_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -283,7 +283,7 @@ pub fn float_exponential_test() { // runtime. } -pub fn float_natural_logarithm_test() { +pub fn natural_logarithm_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -301,7 +301,7 @@ pub fn float_natural_logarithm_test() { |> should.be_error() } -pub fn float_logarithm_test() { +pub fn logarithm_test() { // Check that the function agrees, at some arbitrary input // points, with known function values maths.logarithm(10.0, 10.0) @@ -334,7 +334,7 @@ pub fn float_logarithm_test() { |> should.be_error() } -pub fn float_logarithm_2_test() { +pub fn logarithm_2_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -355,7 +355,7 @@ pub fn float_logarithm_2_test() { |> should.be_error() } -pub fn float_logarithm_10_test() { +pub fn logarithm_10_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -380,7 +380,7 @@ pub fn float_logarithm_10_test() { |> should.be_error() } -pub fn float_nth_root_test() { +pub fn nth_root_test() { maths.nth_root(9.0, 2) |> should.equal(Ok(3.0)) @@ -399,7 +399,7 @@ pub fn float_nth_root_test() { |> should.be_error() } -pub fn float_constants_test() { +pub fn constants_test() { let assert Ok(tolerance) = float.power(10.0, -12.0) // Test that the constant is approximately equal to 2.7128... diff --git a/test/gleam_community/metrics_test.gleam b/test/gleam_community/metrics_test.gleam index f799692..83e66a9 100644 --- a/test/gleam_community/metrics_test.gleam +++ b/test/gleam_community/metrics_test.gleam @@ -3,7 +3,7 @@ import gleam/set import gleam_community/maths import gleeunit/should -pub fn float_list_norm_test() { +pub fn list_norm_test() { let assert Ok(tol) = float.power(10.0, -6.0) // An empty lists returns 0.0 @@ -63,7 +63,7 @@ pub fn float_list_norm_test() { |> should.be_true() } -pub fn float_list_norm_with_weights_test() { +pub fn list_norm_with_weights_test() { let assert Ok(tol) = float.power(10.0, -6.0) // An empty lists returns 0.0 @@ -95,7 +95,7 @@ pub fn float_list_norm_with_weights_test() { |> should.be_true() } -pub fn float_list_manhattan_test() { +pub fn list_manhattan_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Try with valid input (same as Minkowski distance with p = 1) @@ -135,7 +135,7 @@ pub fn float_list_manhattan_test() { |> should.be_error() } -pub fn float_list_minkowski_test() { +pub fn list_minkowski_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Test order < 1 @@ -209,7 +209,7 @@ pub fn float_list_minkowski_test() { |> should.be_error() } -pub fn float_list_euclidean_test() { +pub fn list_euclidean_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Empty lists returns an error diff --git a/test/gleam_community/piecewise_test.gleam b/test/gleam_community/piecewise_test.gleam index f74a84f..9a6907f 100644 --- a/test/gleam_community/piecewise_test.gleam +++ b/test/gleam_community/piecewise_test.gleam @@ -3,7 +3,7 @@ import gleam/int import gleam_community/maths import gleeunit/should -pub fn float_ceiling_test() { +pub fn ceiling_test() { // Round 3. digit AFTER decimal point maths.round_up(12.0654, 3) |> should.equal(12.066) @@ -33,7 +33,7 @@ pub fn float_ceiling_test() { |> should.equal(1000.0) } -pub fn float_floor_test() { +pub fn floor_test() { // Round 3. digit AFTER decimal point maths.round_down(12.0654, 3) |> should.equal(12.065) @@ -63,7 +63,7 @@ pub fn float_floor_test() { |> should.equal(0.0) } -pub fn float_truncate_test() { +pub fn truncate_test() { // Round 3. digit AFTER decimal point maths.round_to_zero(12.0654, 3) |> should.equal(12.065) @@ -373,41 +373,41 @@ pub fn math_round_ties_up_test() { |> should.equal(0.0) } -pub fn float_absolute_difference_test() { - maths.float_absolute_difference(20.0, 15.0) +pub fn absolute_difference_test() { + maths.absolute_difference(20.0, 15.0) |> should.equal(5.0) - maths.float_absolute_difference(-20.0, -15.0) + maths.absolute_difference(-20.0, -15.0) |> should.equal(5.0) - maths.float_absolute_difference(20.0, -15.0) + maths.absolute_difference(20.0, -15.0) |> should.equal(35.0) - maths.float_absolute_difference(-20.0, 15.0) + maths.absolute_difference(-20.0, 15.0) |> should.equal(35.0) - maths.float_absolute_difference(0.0, 0.0) + maths.absolute_difference(0.0, 0.0) |> should.equal(0.0) - maths.float_absolute_difference(1.0, 2.0) + maths.absolute_difference(1.0, 2.0) |> should.equal(1.0) - maths.float_absolute_difference(2.0, 1.0) + maths.absolute_difference(2.0, 1.0) |> should.equal(1.0) - maths.float_absolute_difference(-1.0, 0.0) + maths.absolute_difference(-1.0, 0.0) |> should.equal(1.0) - maths.float_absolute_difference(0.0, -1.0) + maths.absolute_difference(0.0, -1.0) |> should.equal(1.0) - maths.float_absolute_difference(10.0, 20.0) + maths.absolute_difference(10.0, 20.0) |> should.equal(10.0) - maths.float_absolute_difference(-10.0, -20.0) + maths.absolute_difference(-10.0, -20.0) |> should.equal(10.0) - maths.float_absolute_difference(-10.5, 10.5) + maths.absolute_difference(-10.5, 10.5) |> should.equal(21.0) } @@ -425,39 +425,39 @@ pub fn int_absolute_difference_test() { |> should.equal(35) } -pub fn float_sign_test() { - maths.float_sign(100.0) +pub fn sign_test() { + maths.sign(100.0) |> should.equal(1.0) - maths.float_sign(0.0) + maths.sign(0.0) |> should.equal(0.0) - maths.float_sign(-100.0) + maths.sign(-100.0) |> should.equal(-1.0) } -pub fn float_flip_sign_test() { - maths.float_flip_sign(100.0) +pub fn flip_sign_test() { + maths.flip_sign(100.0) |> should.equal(-100.0) - maths.float_flip_sign(0.0) + maths.flip_sign(0.0) |> should.equal(-0.0) - maths.float_flip_sign(-100.0) + maths.flip_sign(-100.0) |> should.equal(100.0) } -pub fn float_copy_sign_test() { - maths.float_copy_sign(100.0, 10.0) +pub fn copy_sign_test() { + maths.copy_sign(100.0, 10.0) |> should.equal(100.0) - maths.float_copy_sign(-100.0, 10.0) + maths.copy_sign(-100.0, 10.0) |> should.equal(100.0) - maths.float_copy_sign(100.0, -10.0) + maths.copy_sign(100.0, -10.0) |> should.equal(-100.0) - maths.float_copy_sign(-100.0, -10.0) + maths.copy_sign(-100.0, -10.0) |> should.equal(-100.0) } @@ -497,7 +497,7 @@ pub fn int_copy_sign_test() { |> should.equal(-100) } -pub fn float_minmax_test() { +pub fn minmax_test() { maths.minmax(0.75, 0.5, float.compare) |> should.equal(#(0.5, 0.75)) @@ -525,7 +525,7 @@ pub fn int_minmax_test() { |> should.equal(#(-75, 50)) } -pub fn float_list_minimum_test() { +pub fn list_minimum_test() { // An empty lists returns an error [] |> maths.list_minimum(float.compare) @@ -549,7 +549,7 @@ pub fn int_list_minimum_test() { |> should.equal(Ok(1)) } -pub fn float_list_maximum_test() { +pub fn list_maximum_test() { // An empty lists returns an error [] |> maths.list_maximum(float.compare) @@ -573,7 +573,7 @@ pub fn int_list_maximum_test() { |> should.equal(Ok(4)) } -pub fn float_list_arg_maximum_test() { +pub fn list_arg_maximum_test() { // An empty lists returns an error [] |> maths.arg_maximum(float.compare) @@ -597,7 +597,7 @@ pub fn int_list_arg_maximum_test() { |> should.equal(Ok([0, 1])) } -pub fn float_list_arg_minimum_test() { +pub fn list_arg_minimum_test() { // An empty lists returns an error [] |> maths.arg_minimum(float.compare) @@ -621,7 +621,7 @@ pub fn int_list_arg_minimum_test() { |> should.equal(Ok([4])) } -pub fn float_list_extrema_test() { +pub fn list_extrema_test() { // An empty lists returns an error [] |> maths.extrema(float.compare) diff --git a/test/gleam_community/sequences_test.gleam b/test/gleam_community/sequences_test.gleam index ef8b68f..3fd83e1 100644 --- a/test/gleam_community/sequences_test.gleam +++ b/test/gleam_community/sequences_test.gleam @@ -4,7 +4,7 @@ import gleam/yielder import gleam_community/maths import gleeunit/should -pub fn float_list_linear_space_test() { +pub fn list_linear_space_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input @@ -118,7 +118,7 @@ pub fn float_list_linear_space_test() { |> should.be_error() } -pub fn float_list_logarithmic_space_test() { +pub fn list_logarithmic_space_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -203,7 +203,7 @@ pub fn float_list_logarithmic_space_test() { |> should.be_error() } -pub fn float_list_geometric_space_test() { +pub fn list_geometric_space_test() { let assert Ok(tol) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input // points, with known function values @@ -271,7 +271,7 @@ pub fn float_list_geometric_space_test() { |> should.be_error() } -pub fn float_list_arange_test() { +pub fn list_arange_test() { // Positive start, stop, step maths.arange(1.0, 5.0, 1.0) |> yielder.to_list() @@ -311,7 +311,7 @@ pub fn float_list_arange_test() { |> should.equal([-5.0, -4.0, -3.0, -2.0]) } -pub fn float_list_exponential_space_test() { +pub fn list_exponential_space_test() { let assert Ok(tolerance) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input @@ -349,7 +349,7 @@ pub fn float_list_exponential_space_test() { |> should.be_error() } -pub fn float_list_symmetric_space_test() { +pub fn list_symmetric_space_test() { let assert Ok(tolerance) = float.power(10.0, -6.0) // Check that the function agrees, at some arbitrary input