From a33653bee1def5d74cd6c595decc5141166537cf Mon Sep 17 00:00:00 2001 From: "Ryan M. Moore" Date: Sat, 1 Mar 2025 13:19:16 -0500 Subject: [PATCH] Use qcheck 1.0.0 --- gleam.toml | 2 +- manifest.toml | 10 ++--- test/gleam/time/duration_test.gleam | 48 ++++++++++++---------- test/gleam/time/generators.gleam | 60 ++++++++++++++-------------- test/gleam/time/timestamp_test.gleam | 43 ++++++++++---------- 5 files changed, 85 insertions(+), 78 deletions(-) diff --git a/gleam.toml b/gleam.toml index 723a0d4..84a3a9f 100644 --- a/gleam.toml +++ b/gleam.toml @@ -13,7 +13,7 @@ gleam_stdlib = ">= 0.44.0 and < 2.0.0" [dev-dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" -qcheck = ">= 0.0.7 and < 1.0.0" +qcheck = ">= 1.0.0 and < 2.0.0" simplifile = ">= 2.2.0 and < 3.0.0" gleam_regexp = ">= 1.0.0 and < 2.0.0" prng = ">= 4.0.1 and < 5.0.0" diff --git a/manifest.toml b/manifest.toml index cd6b51b..45b4d73 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,12 +5,12 @@ packages = [ { name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" }, { name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" }, { name = "gleam_bitwise", version = "1.3.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "B36E1D3188D7F594C7FD4F43D0D2CE17561DE896202017548578B16FE1FE9EFC" }, - { name = "gleam_regexp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "A3655FDD288571E90EE9C4009B719FEF59FA16AFCDF3952A76A125AF23CF1592" }, - { name = "gleam_stdlib", version = "0.51.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "14AFA8D3DDD7045203D422715DBB822D1725992A31DF35A08D97389014B74B68" }, + { name = "gleam_regexp", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "7F5E0C0BBEB3C58E57C9CB05FA9002F970C85AD4A63BA1E55CBCB35C15809179" }, + { name = "gleam_stdlib", version = "0.55.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "32D8F4AE03771516950047813A9E359249BD9FBA5C33463FDB7B953D6F8E896B" }, { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, - { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, + { name = "gleeunit", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "0E6C83834BA65EDCAAF4FE4FB94AC697D9262D83E6F58A750D63C9F6C8A9D9FF" }, { name = "prng", version = "4.0.1", build_tools = ["gleam"], requirements = ["gleam_bitwise", "gleam_stdlib", "gleam_yielder"], otp_app = "prng", source = "hex", outer_checksum = "695AB70E4BE713042062E901975FC08D1EC725B85B808D4786A14C406ADFBCF1" }, - { name = "qcheck", version = "0.0.7", build_tools = ["gleam"], requirements = ["exception", "gleam_regexp", "gleam_stdlib", "gleam_yielder", "prng"], otp_app = "qcheck", source = "hex", outer_checksum = "2363A970BB2E82623023154ED09EE48E3005229A869DA423B18468EA066A4CA9" }, + { name = "qcheck", version = "1.0.0", build_tools = ["gleam"], requirements = ["exception", "gleam_regexp", "gleam_stdlib", "gleam_yielder", "prng"], otp_app = "qcheck", source = "hex", outer_checksum = "6DAE7925E350480CE813F80D07AC4B9BAB25360F0D63EC98C5742D8456C9A9A1" }, { name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" }, ] @@ -19,5 +19,5 @@ gleam_regexp = { version = ">= 1.0.0 and < 2.0.0" } gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } prng = { version = ">= 4.0.1 and < 5.0.0" } -qcheck = { version = ">= 0.0.7 and < 1.0.0" } +qcheck = { version = ">= 1.0.0 and < 2.0.0" } simplifile = { version = ">= 2.2.0 and < 3.0.0" } diff --git a/test/gleam/time/duration_test.gleam b/test/gleam/time/duration_test.gleam index d2612cd..641094f 100644 --- a/test/gleam/time/duration_test.gleam +++ b/test/gleam/time/duration_test.gleam @@ -6,22 +6,22 @@ import qcheck pub fn add_property_0_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform(), - qcheck.int_uniform(), + qcheck.uniform_int(), + qcheck.uniform_int(), )) let expected = duration.nanoseconds(x + y) let actual = duration.nanoseconds(x) |> duration.add(duration.nanoseconds(y)) - expected == actual + should.equal(expected, actual) } pub fn add_property_1_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform(), - qcheck.int_uniform(), + qcheck.uniform_int(), + qcheck.uniform_int(), )) let expected = duration.seconds(x + y) let actual = duration.seconds(x) |> duration.add(duration.seconds(y)) - expected == actual + should.equal(expected, actual) } pub fn add_0_test() { @@ -122,58 +122,62 @@ pub fn to_seconds_4_test() { pub fn compare_property_0_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform_inclusive(0, 999_999), - qcheck.int_uniform_inclusive(0, 999_999), + qcheck.bounded_int(0, 999_999), + qcheck.bounded_int(0, 999_999), )) // Durations of seconds let tx = duration.seconds(x) let ty = duration.seconds(y) - duration.compare(tx, ty) == int.compare(x, y) + should.equal(duration.compare(tx, ty), int.compare(x, y)) } pub fn compare_property_1_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform_inclusive(0, 999_999), - qcheck.int_uniform_inclusive(0, 999_999), + qcheck.bounded_int(0, 999_999), + qcheck.bounded_int(0, 999_999), )) // Durations of nanoseconds let tx = duration.nanoseconds(x) let ty = duration.nanoseconds(y) - duration.compare(tx, ty) == int.compare(x, y) + should.equal(duration.compare(tx, ty), int.compare(x, y)) } pub fn compare_property_2_test() { - use x <- qcheck.given(qcheck.int_uniform()) + use x <- qcheck.given(qcheck.uniform_int()) let tx = duration.nanoseconds(x) - duration.compare(tx, tx) == order.Eq + should.equal(duration.compare(tx, tx), order.Eq) } pub fn compare_property_3_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform_inclusive(0, 999_999), - qcheck.int_uniform_inclusive(0, 999_999), + qcheck.bounded_int(0, 999_999), + qcheck.bounded_int(0, 999_999), )) let tx = duration.nanoseconds(x) // It doesn't matter if a duration is positive or negative, it's the amount // of time spanned that matters. // // Second durations - duration.compare(tx, duration.seconds(y)) - == duration.compare(tx, duration.seconds(0 - y)) + should.equal( + duration.compare(tx, duration.seconds(y)), + duration.compare(tx, duration.seconds(0 - y)), + ) } pub fn compare_property_4_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform_inclusive(0, 999_999), - qcheck.int_uniform_inclusive(0, 999_999), + qcheck.bounded_int(0, 999_999), + qcheck.bounded_int(0, 999_999), )) let tx = duration.nanoseconds(x) // It doesn't matter if a duration is positive or negative, it's the amount // of time spanned that matters. // // Nanosecond durations - duration.compare(tx, duration.nanoseconds(y)) - == duration.compare(tx, duration.nanoseconds(y * -1)) + should.equal( + duration.compare(tx, duration.nanoseconds(y)), + duration.compare(tx, duration.nanoseconds(y * -1)), + ) } pub fn compare_0_test() { diff --git a/test/gleam/time/generators.gleam b/test/gleam/time/generators.gleam index fc1bcaf..2b41f86 100644 --- a/test/gleam/time/generators.gleam +++ b/test/gleam/time/generators.gleam @@ -5,15 +5,15 @@ import gleam/string import gleam/time/timestamp import qcheck -/// Generate timestamps representing instants in the range `0000-01-01T00:00:00Z` +/// Generate timestamps representing instants in the range `0000-01-01T00:00:00Z` /// to `9999-12-31T23:59:59.999999999Z`. -/// +/// pub fn timestamp() { - // prng can only generate good integers in the range + // prng can only generate good integers in the range // [-2_147_483_648, 2_147_483_647] - // + // // So we must get to the range we need by generating the values in parts, then - // adding them together. + // adding them together. // // The smallest number of milliseconds we need to generate: // > d=new Date("0000-01-01T00:00:00"); d.getTime() @@ -22,21 +22,21 @@ pub fn timestamp() { // // The largest number of milliseconds without leap second we need to generate: // > d=new Date("9999-12-31T23:59:59"); d.getTime() - // 253_402_318_799_000 ms + // 253_402_318_799_000 ms // 253_402_318_799 s // let megasecond_generator = { - use second <- qcheck.map(qcheck.int_uniform_inclusive(-62_167, 253_402)) + use second <- qcheck.map(qcheck.bounded_int(-62_167, 253_402)) second * 1_000_000 } - let second_generator = qcheck.int_uniform_inclusive(-201_438, 318_799) + let second_generator = qcheck.bounded_int(-201_438, 318_799) use megasecond, second, nanosecond <- qcheck.map3( - g1: megasecond_generator, - g2: second_generator, - g3: qcheck.int_uniform_inclusive(0, 999_999_999), + megasecond_generator, + second_generator, + qcheck.bounded_int(0, 999_999_999), ) let total_seconds = megasecond + second @@ -52,9 +52,9 @@ pub fn rfc3339( avoid_erlang_errors avoid_erlang_errors: Bool, ) -> qcheck.Generator(String) { use full_date, t, full_time <- qcheck.map3( - g1: full_date_generator(), - g2: t_generator(), - g3: full_time_generator(with_leap_second, second_fraction_spec), + full_date_generator(), + t_generator(), + full_time_generator(with_leap_second, second_fraction_spec), ) let date_time = full_date <> t <> full_time @@ -140,7 +140,7 @@ fn is_leap_year(year_input: String) -> Bool { } fn t_generator() { - qcheck.from_generators([qcheck.return("T"), qcheck.return("t")]) + qcheck.from_generators(qcheck.constant("T"), [qcheck.constant("t")]) } fn full_time_generator( @@ -148,8 +148,8 @@ fn full_time_generator( second_fraction_spec second_fraction_spec: SecondFractionSpec, ) -> qcheck.Generator(String) { use partial_time, time_offset <- qcheck.map2( - g1: partial_time_generator(with_leap_second, second_fraction_spec), - g2: time_offset_generator(), + partial_time_generator(with_leap_second, second_fraction_spec), + time_offset_generator(), ) partial_time <> time_offset } @@ -158,7 +158,7 @@ fn partial_time_generator( with_leap_second with_leap_second: Bool, second_fraction_spec second_fraction_spec: SecondFractionSpec, ) -> qcheck.Generator(String) { - qcheck.return({ + qcheck.constant({ use time_hour <- qcheck.parameter use time_minute <- qcheck.parameter use time_second <- qcheck.parameter @@ -174,7 +174,7 @@ fn partial_time_generator( |> qcheck.apply(time_minute_generator()) |> qcheck.apply(time_second_generator(with_leap_second)) |> qcheck.apply( - qcheck.option(time_second_fraction_generator(second_fraction_spec)), + qcheck.option_from(time_second_fraction_generator(second_fraction_spec)), ) } @@ -201,7 +201,7 @@ fn zero_padded_digits_generator( from min: Int, to max: Int, ) -> qcheck.Generator(String) { - use n <- qcheck.map(qcheck.int_uniform_inclusive(min, max)) + use n <- qcheck.map(qcheck.bounded_int(min, max)) int.to_string(n) |> string.pad_start(to: length, with: "0") } @@ -223,39 +223,39 @@ fn time_second_fraction_generator( } fn one_or_more_digits_generator() -> qcheck.Generator(String) { - qcheck.string_non_empty_from(qcheck.char_digit()) + qcheck.non_empty_string_from(qcheck.ascii_digit_codepoint()) } fn digits_generator( min_count min_count: Int, max_count max_count: Int, ) -> qcheck.Generator(String) { - qcheck.string_generic( - qcheck.char_digit(), - qcheck.int_uniform_inclusive(min_count, max_count), + qcheck.generic_string( + qcheck.ascii_digit_codepoint(), + qcheck.bounded_int(min_count, max_count), ) } fn time_offset_generator() -> qcheck.Generator(String) { - qcheck.from_generators([z_generator(), time_numoffset_generator()]) + qcheck.from_generators(z_generator(), [time_numoffset_generator()]) } fn z_generator() { - qcheck.from_generators([qcheck.return("Z"), qcheck.return("z")]) + qcheck.from_generators(qcheck.constant("Z"), [qcheck.constant("z")]) } fn time_numoffset_generator() -> qcheck.Generator(String) { use plus_or_minus, time_hour, time_minute <- qcheck.map3( - g1: plus_or_minus_generator(), - g2: time_hour_generator(), - g3: time_minute_generator(), + plus_or_minus_generator(), + time_hour_generator(), + time_minute_generator(), ) plus_or_minus <> time_hour <> ":" <> time_minute } fn plus_or_minus_generator() -> qcheck.Generator(String) { - qcheck.from_generators([qcheck.return("+"), qcheck.return("-")]) + qcheck.from_generators(qcheck.constant("+"), [qcheck.constant("-")]) } fn unwrap_optional_string(optional_string: option.Option(String)) -> String { diff --git a/test/gleam/time/timestamp_test.gleam b/test/gleam/time/timestamp_test.gleam index e2f3204..defe105 100644 --- a/test/gleam/time/timestamp_test.gleam +++ b/test/gleam/time/timestamp_test.gleam @@ -13,12 +13,12 @@ import simplifile pub fn compare_property_0_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform(), - qcheck.int_uniform(), + qcheck.uniform_int(), + qcheck.uniform_int(), )) let tx = timestamp.from_unix_seconds(x) let ty = timestamp.from_unix_seconds(y) - timestamp.compare(tx, ty) == int.compare(x, y) + should.equal(timestamp.compare(tx, ty), int.compare(x, y)) } pub fn compare_0_test() { @@ -71,26 +71,26 @@ pub fn difference_2_test() { pub fn add_property_0_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform(), - qcheck.int_uniform(), + qcheck.uniform_int(), + qcheck.uniform_int(), )) let expected = timestamp.from_unix_seconds_and_nanoseconds(0, x + y) let actual = timestamp.from_unix_seconds_and_nanoseconds(0, x) |> timestamp.add(duration.nanoseconds(y)) - expected == actual + should.equal(expected, actual) } pub fn add_property_1_test() { use #(x, y) <- qcheck.given(qcheck.tuple2( - qcheck.int_uniform(), - qcheck.int_uniform(), + qcheck.uniform_int(), + qcheck.uniform_int(), )) let expected = timestamp.from_unix_seconds_and_nanoseconds(x + y, 0) let actual = timestamp.from_unix_seconds_and_nanoseconds(x, 0) |> timestamp.add(duration.seconds(y)) - expected == actual + should.equal(expected, actual) } pub fn add_0_test() { @@ -336,7 +336,7 @@ pub fn timestamp_rfc3339_string_timestamp_roundtrip_property_test() { |> timestamp.to_rfc3339(calendar.utc_offset) |> timestamp.parse_rfc3339 - timestamp == parsed_timestamp + should.equal(timestamp, parsed_timestamp) } pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_property_test() { @@ -353,7 +353,7 @@ pub fn rfc3339_string_timestamp_rfc3339_string_roundtrip_property_test() { |> timestamp.to_rfc3339(calendar.utc_offset) |> timestamp.parse_rfc3339 - original_timestamp == roundtrip_timestamp + should.equal(original_timestamp, roundtrip_timestamp) } // Eastern US Timezone round trip tests @@ -543,25 +543,28 @@ pub fn parse_rfc3339_matches_oracle_property_test() { avoid_erlang_errors: True, )) - timestamp.parse_rfc3339(date_time) == parse_rfc3339_oracle(date_time) + should.equal( + timestamp.parse_rfc3339(date_time), + parse_rfc3339_oracle(date_time), + ) } pub fn parse_rfc3339_succeeds_for_valid_inputs_property_test() { - use date_time <- qcheck.given_result(generators.rfc3339( + use date_time <- qcheck.given(generators.rfc3339( with_leap_second: True, second_fraction_spec: generators.Default, avoid_erlang_errors: False, )) - timestamp.parse_rfc3339(date_time) + + let _ = timestamp.parse_rfc3339(date_time) |> should.be_ok + Nil } pub fn parse_rfc3339_fails_for_invalid_inputs_test() { // The chance of randomly generating a valid RFC 3339 string is quite low.... - use string <- qcheck.given_result(qcheck.string()) - case timestamp.parse_rfc3339(string) { - Error(Nil) -> Ok(Nil) - Ok(x) -> Error(x) - } + use string <- qcheck.given(qcheck.string()) + + timestamp.parse_rfc3339(string) |> should.be_error } pub fn parse_rfc3339_bad_leapyear_test() { @@ -792,5 +795,5 @@ pub fn calendar_roundtrip_test() { timestamp.to_calendar(timestamp1, calendar.utc_offset) let timestamp2 = timestamp.from_calendar(date, time_of_day, calendar.utc_offset) - timestamp1 == timestamp2 + should.equal(timestamp1, timestamp2) }