Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure test examples #488

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions examples/datetime_human_tests.nbt

This file was deleted.

170 changes: 0 additions & 170 deletions examples/prelude_tests.nbt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let length = 2 m
assert_eq(length, 1 m + 1 m)
assert_eq(1.0 m, 1.001 m, 0.01 m)

assert_eq(2 min + 30 s, 2.5 min, 0.01 s)
22 changes: 22 additions & 0 deletions examples/tests/base_conversion.nbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
assert_eq((0b0 -> bin), "0b0")
assert_eq((0b1 -> bin), "0b1")
assert_eq((0b10 -> bin), "0b10")
assert_eq((0b11 -> bin), "0b11")
assert_eq((0b10101010101010101010101010101010 -> bin), "0b10101010101010101010101010101010")
assert_eq((-0b11110000 -> bin), "-0b11110000")

assert_eq((0o0 -> oct), "0o0")
assert_eq((0o1 -> oct), "0o1")
assert_eq((0o7 -> oct), "0o7")
assert_eq((0o10 -> oct), "0o10")
assert_eq((0o77 -> oct), "0o77")
assert_eq((0o12345670 -> oct), "0o12345670")
assert_eq((-0o12345670 -> oct), "-0o12345670")

assert_eq((0x0 -> hex), "0x0")
assert_eq((0x1 -> hex), "0x1")
assert_eq((0x9 -> hex), "0x9")
assert_eq((0xa -> hex), "0xa")
assert_eq((0xf -> hex), "0xf")
assert_eq((0xabc1234567890 -> hex), "0xabc1234567890")
assert_eq((-0xc0ffee -> hex), "-0xc0ffee")
File renamed without changes.
12 changes: 6 additions & 6 deletions examples/chemistry_tests.nbt → examples/tests/chemistry.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# - https://en.wikipedia.org/wiki/Enthalpy_of_vaporization

let w = element("tungsten")
assert(w.symbol == "W")
assert(w.name == "Tungsten")
assert_eq(w.symbol, "W")
assert_eq(w.name, "Tungsten")
assert_eq(w.atomic_number, 74)
assert_eq(w.group, 6)
assert_eq(w.period, 6)
Expand All @@ -21,8 +21,8 @@ assert_eq(w.vaporization_heat, 807 kJ/mol, 20 kJ/mol)


let chl = element("chlorine")
assert(chl.symbol == "Cl")
assert(chl.name == "Chlorine")
assert_eq(chl.symbol, "Cl")
assert_eq(chl.name, "Chlorine")
assert_eq(chl.atomic_number, 17)
assert_eq(chl.group, 17)
assert_eq(chl.period, 3)
Expand All @@ -35,8 +35,8 @@ assert_eq(chl.vaporization_heat, 20.4 kJ/mol, 0.1 kJ/mol)


let rb = element("rubidium")
assert(rb.symbol == "Rb")
assert(rb.name == "Rubidium")
assert_eq(rb.symbol, "Rb")
assert_eq(rb.name, "Rubidium")
assert_eq(rb.atomic_number, 37)
assert_eq(rb.group, 1)
assert_eq(rb.period, 5)
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions examples/tests/core.nbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# unit_of

assert_eq(unit_of(0), 1)

assert_eq(unit_of(1), 1)
assert_eq(unit_of(1.2345), 1)

assert_eq(unit_of(1 m), m)
assert_eq(unit_of(1.2345 m), m)

assert_eq(unit_of(1 m^2/s), m^2/s)
assert_eq(unit_of(1.2345 m^2/s), m^2/s)

# value_of

assert_eq(value_of(0), 0)

assert_eq(value_of(1), 1)
assert_eq(value_of(1.2345), 1.2345)

assert_eq(value_of(1 m), 1)
assert_eq(value_of(1.2345 m), 1.2345)

assert_eq(value_of(1 m^2/s), 1)
assert_eq(value_of(1.2345 m^2/s), 1.2345)
6 changes: 3 additions & 3 deletions examples/datetime_tests.nbt → examples/tests/datetime.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ assert_eq(from_unixtime(1658346725) -> unixtime, 1658346725)

# 2020 was a leap year
let y = datetime("2020-02-28 20:00 UTC")
assert(format_datetime("%Y/%m/%d", y + 12 hours) == "2020/02/29")
assert_eq(format_datetime("%Y/%m/%d", y + 12 hours), "2020/02/29")
let z = datetime("2021-02-28 20:00 UTC")
assert(format_datetime("%Y/%m/%d", z + 12 hours) == "2021/03/01")
assert_eq(format_datetime("%Y/%m/%d", z + 12 hours), "2021/03/01")

# Regression test for #376
let dt_376 = datetime("Fri, 23 Feb 2024 14:01:54 -0800")
assert(format_datetime("%Y-%m-%dT%H:%M:%S%:z", dt_376) == "2024-02-23T14:01:54-08:00")
assert_eq(format_datetime("%Y-%m-%dT%H:%M:%S%:z", dt_376), "2024-02-23T14:01:54-08:00")
38 changes: 38 additions & 0 deletions examples/tests/human.nbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
assert_eq((0 second -> human), "0 seconds")
assert_eq((1 second -> human), "1 second")
assert_eq((5 second -> human), "5 seconds")
assert_eq((1.5 second -> human), "1.500 seconds")

assert_eq((60 seconds -> human), "1 minute")
assert_eq((73 seconds -> human), "1 minute + 13 seconds")
assert_eq((120 seconds -> human), "2 minutes")
assert_eq((60.1 seconds -> human), "1 minute + 0.100 seconds")
assert_eq((1 minute -> human), "1 minute")
assert_eq((1.25 minute -> human), "1 minute + 15 seconds")
assert_eq((2.5 minute -> human), "2 minutes + 30 seconds")

assert_eq((1 hour -> human), "1 hour")
assert_eq((1.5 hour -> human), "1 hour + 30 minutes")
assert_eq((2 hour -> human), "2 hours")
assert_eq((1 hour + 1 sec -> human), "1 hour + 1 second")

assert_eq((1 day -> human), "1 day")
assert_eq((1.37 day -> human), "1 day + 8 hours + 52 minutes + 48 seconds")

assert_eq((1 week -> human), "7 days")
assert_eq((1.5 weeks -> human), "10 days + 12 hours")
assert_eq((2 weeks -> human), "14 days")

assert_eq((1 sidereal_day -> human), "23 hours + 56 minutes + 4.090500 seconds")

assert_eq((10000 days -> human), "10000 days")
assert_eq((50 million days -> human), "50_000_000 days")

assert_eq((1e12 days -> human), "1_000_000_000_000 days")
assert_eq((1e15 days -> human), "1.0e+15 days")

assert_eq((1 ms -> human), "0.001 seconds")
assert_eq((1 µs -> human), "0.000001 seconds")
assert_eq((1 ns -> human), "0.000000001 seconds")
assert_eq((1234 ns -> human), "0.000001234 seconds")
assert_eq((1s + 1234 ns -> human), "1.000001234 seconds")
File renamed without changes.
Loading
Loading