Skip to content

Commit

Permalink
CR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gampleman committed Sep 6, 2023
1 parent f4cea30 commit 07b1d06
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
30 changes: 20 additions & 10 deletions src/Float/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ toSignificantBaseNonScientific precision x =


cutUnnecessaryDecimalZeroes : Int -> String -> String
cutUnnecessaryDecimalZeroes num =
String.toList >> List.reverse >> cutUnnecessaryDecimalZeroesHelp num >> List.reverse >> String.fromList
cutUnnecessaryDecimalZeroes num value =
value
|> String.toList
|> List.reverse
|> cutUnnecessaryDecimalZeroesHelp num
|> List.reverse
|> String.fromList


cutUnnecessaryDecimalZeroesHelp : Int -> List Char -> List Char
Expand All @@ -152,12 +157,13 @@ cutUnnecessaryDecimalZeroesHelp toCut lst =
_ ->
lst

else if List.head lst == Just '.' then
List.tail lst
|> Maybe.withDefault []

else
lst
case lst of
'.' :: tail ->
tail

_ ->
lst


sign : Float -> String
Expand Down Expand Up @@ -240,9 +246,9 @@ roundAsFloat places strNum =


roundToDecimal : Int -> Float -> Float
roundToDecimal places =
roundToDecimal places value =
if places < 0 then
identity
value

else
let
Expand All @@ -258,7 +264,11 @@ roundToDecimal places =
divByExp v =
v / exp
in
multiplyByExp >> round >> toFloat >> divByExp
value
|> multiplyByExp
|> round
|> toFloat
|> divByExp



Expand Down
25 changes: 24 additions & 1 deletion tests/FloatTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module FloatTests exposing (testAboutEqual, testBoundaryValuesAsUnicode, testRan

import Expect
import Float.Extra exposing (aboutEqual)
import Fuzz
import Fuzz exposing (Fuzzer)
import List.Extra exposing (Step(..))
import Test exposing (Test, describe, fuzz, fuzz2, test)
import Utils exposing (expectAll)
Expand Down Expand Up @@ -272,4 +272,27 @@ testRange =
, Float.Extra.range 2.0e300 1.0e300 -3.0e299
|> Expect.equal [ 2.0e300, 2.0e300 - 3.0e299, 2.0e300 - 3.0e299 * 2, 2.0e300 - 3.0e299 * 3 ]
]
, fuzz fuzzRangeArgs "First element is always start" <|
\( start, end, step ) ->
case Float.Extra.range start end step |> List.head of
Just v ->
Expect.within (Expect.AbsoluteOrRelative 1.0e-8 1.0e-5) start v

Nothing ->
Expect.pass
]


fuzzRangeArgs : Fuzzer ( Float, Float, Float )
fuzzRangeArgs =
-- Float.Extra.range can generate some REALLY big lists very easily
-- this fuzzer makes sure that it generates inputs that lead to
-- ranges with about 10 elements
Fuzz.map4
(\start step count extra ->
( start, start + (toFloat count + extra) * step, step )
)
Fuzz.float
Fuzz.float
(Fuzz.intRange -10 10)
(Fuzz.floatRange 0 1)

0 comments on commit 07b1d06

Please sign in to comment.