Skip to content

Commit

Permalink
Add build float tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Nov 16, 2024
1 parent 0b84984 commit 587b1c5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lenient_parse/internal/build.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub fn float_value(
is_positive is_positive: Bool,
whole_digits whole_digits: Queue(Int),
fractional_digits fractional_digits: Queue(Int),
exponent exponent: Int,
scale_factor scale_factor: Int,
) -> Float {
let #(whole_digits, fractional_digits) =
scale.queues(whole_digits, fractional_digits, exponent)
scale.queues(whole_digits, fractional_digits, scale_factor)
let fractional_digits_length = fractional_digits |> queue.length
let #(all_digits, _) =
scale.queues(whole_digits, fractional_digits, fractional_digits_length)
Expand Down
2 changes: 1 addition & 1 deletion src/lenient_parse/internal/parser.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn parse_float(tokens tokens: List(Token)) -> Result(Float, ParseError) {
is_positive: is_positive,
whole_digits: whole_digits,
fractional_digits: fractional_digits,
exponent: exponent,
scale_factor: exponent,
))
}
}
Expand Down
43 changes: 43 additions & 0 deletions test/build_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import gleam/queue
import lenient_parse/internal/build
import startest/expect

pub fn build_float_empty_fractional_test() {
build.float_value(
is_positive: True,
whole_digits: queue.from_list([1]),
fractional_digits: queue.from_list([]),
scale_factor: 0,
)
|> expect.to_equal(1.0)
}

pub fn build_float_explicit_0_fractional_test() {
build.float_value(
is_positive: True,
whole_digits: queue.from_list([1]),
fractional_digits: queue.from_list([0]),
scale_factor: 0,
)
|> expect.to_equal(1.0)
}

pub fn build_float_empty_whole_test() {
build.float_value(
is_positive: True,
whole_digits: queue.from_list([]),
fractional_digits: queue.from_list([1]),
scale_factor: 0,
)
|> expect.to_equal(0.1)
}

pub fn build_float_explicit_0_whole_test() {
build.float_value(
is_positive: True,
whole_digits: queue.from_list([0]),
fractional_digits: queue.from_list([1]),
scale_factor: 0,
)
|> expect.to_equal(0.1)
}

0 comments on commit 587b1c5

Please sign in to comment.