f1bf76e1be
Co-authored-by: Zachary Levy <zachary@sunforge.is> Reviewed-on: #41
775 lines
22 KiB
Odin
775 lines
22 KiB
Odin
package quantity
|
|
|
|
import "base:intrinsics"
|
|
|
|
GRAMS_PER_POUND :: 453.59237
|
|
OUNCES_PER_POUND :: 16
|
|
GRAMS_PER_OUNCE :: GRAMS_PER_POUND / OUNCES_PER_POUND
|
|
|
|
KILO_GRAMS_PER_POUND :: GRAMS_PER_POUND / KILO
|
|
MILLI_GRAMS_PER_POUND :: GRAMS_PER_POUND * MILLI
|
|
MICRO_GRAMS_PER_POUND :: GRAMS_PER_POUND * MICRO
|
|
NANO_GRAMS_PER_POUND :: GRAMS_PER_POUND * NANO
|
|
|
|
KILO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE / KILO
|
|
MILLI_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MILLI
|
|
MICRO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MICRO
|
|
NANO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * NANO
|
|
|
|
//----- Grams ----------------------------------
|
|
Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
grams_to_kilo_grams :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Kilo_Grams(V){grams.v / KILO}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
grams_to_milli_grams :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Milli_Grams(V){grams.v * MILLI}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
grams_to_micro_grams :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Micro_Grams(V){grams.v * MICRO}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
grams_to_nano_grams :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Nano_Grams(V){grams.v * NANO}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
grams_to_pounds :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
|
return Pounds(V){grams.v / GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
grams_to_ounces :: #force_inline proc "contextless" (
|
|
grams: Grams($V),
|
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
|
return Ounces(V){grams.v / GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
//----- Kilograms ----------------------------------
|
|
Kilo_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
kilo_grams_to_grams :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Grams(V){kilo_grams.v * KILO}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
kilo_grams_to_milli_grams :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Milli_Grams(V){kilo_grams.v * (KILO * MILLI)}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
kilo_grams_to_micro_grams :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Micro_Grams(V){kilo_grams.v * (KILO * MICRO)}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
kilo_grams_to_nano_grams :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Nano_Grams(V){kilo_grams.v * (KILO * NANO)}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
kilo_grams_to_pounds :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
|
return Pounds(V){kilo_grams.v / KILO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
kilo_grams_to_ounces :: #force_inline proc "contextless" (
|
|
kilo_grams: Kilo_Grams($V),
|
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
|
return Ounces(V){kilo_grams.v / KILO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
//----- Milligrams ----------------------------------
|
|
Milli_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
milli_grams_to_grams :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Grams(V){milli_grams.v / MILLI}
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
milli_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Kilo_Grams(V){milli_grams.v / (KILO * MILLI)}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
milli_grams_to_micro_grams :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Micro_Grams(V){milli_grams.v * (MICRO / MILLI)}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
milli_grams_to_nano_grams :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Nano_Grams(V){milli_grams.v * (NANO / MILLI)}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
milli_grams_to_pounds :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
|
return Pounds(V){milli_grams.v / MILLI_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
milli_grams_to_ounces :: #force_inline proc "contextless" (
|
|
milli_grams: Milli_Grams($V),
|
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
|
return Ounces(V){milli_grams.v / MILLI_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
//----- Micrograms ----------------------------------
|
|
Micro_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
micro_grams_to_grams :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Grams(V){micro_grams.v / MICRO}
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
micro_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Kilo_Grams(V){micro_grams.v / (KILO * MICRO)}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
micro_grams_to_milli_grams :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Milli_Grams(V){micro_grams.v / (MICRO / MILLI)}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
micro_grams_to_nano_grams :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Nano_Grams(V){micro_grams.v * (NANO / MICRO)}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
micro_grams_to_pounds :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
|
return Pounds(V){micro_grams.v / MICRO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
micro_grams_to_ounces :: #force_inline proc "contextless" (
|
|
micro_grams: Micro_Grams($V),
|
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
|
return Ounces(V){micro_grams.v / MICRO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
//----- Nanograms ----------------------------------
|
|
Nano_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_grams :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Grams(V){nano_grams.v / NANO}
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Kilo_Grams(V){nano_grams.v / (KILO * NANO)}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_milli_grams :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Milli_Grams(V){nano_grams.v / (NANO / MILLI)}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_micro_grams :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
|
return Micro_Grams(V){nano_grams.v / (NANO / MICRO)}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_pounds :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
|
return Pounds(V){nano_grams.v / NANO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
nano_grams_to_ounces :: #force_inline proc "contextless" (
|
|
nano_grams: Nano_Grams($V),
|
|
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
|
return Ounces(V){nano_grams.v / NANO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
//----- Pounds ----------------------------------
|
|
Pounds :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
pounds_to_grams :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Grams(V) where intrinsics.type_is_float(V) {
|
|
return Grams(V){pounds.v * GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
pounds_to_kilo_grams :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Kilo_Grams(V){pounds.v * KILO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
pounds_to_milli_grams :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Milli_Grams(V){pounds.v * MILLI_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
pounds_to_micro_grams :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Micro_Grams(V){pounds.v * MICRO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
pounds_to_nano_grams :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Nano_Grams(V){pounds.v * NANO_GRAMS_PER_POUND}
|
|
}
|
|
|
|
// Prefer the to_ounces procedure group.
|
|
pounds_to_ounces :: #force_inline proc "contextless" (
|
|
pounds: Pounds($V),
|
|
) -> Ounces(V) where intrinsics.type_is_numeric(V) {
|
|
return Ounces(V){pounds.v * OUNCES_PER_POUND}
|
|
}
|
|
|
|
//----- Ounces ----------------------------------
|
|
Ounces :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
// Prefer the to_grams procedure group.
|
|
ounces_to_grams :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Grams(V) where intrinsics.type_is_float(V) {
|
|
return Grams(V){ounces.v * GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
// Prefer the to_kilo_grams procedure group.
|
|
ounces_to_kilo_grams :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Kilo_Grams(V){ounces.v * KILO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
// Prefer the to_milli_grams procedure group.
|
|
ounces_to_milli_grams :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Milli_Grams(V){ounces.v * MILLI_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
// Prefer the to_micro_grams procedure group.
|
|
ounces_to_micro_grams :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Micro_Grams(V){ounces.v * MICRO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
// Prefer the to_nano_grams procedure group.
|
|
ounces_to_nano_grams :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
|
return Nano_Grams(V){ounces.v * NANO_GRAMS_PER_OUNCE}
|
|
}
|
|
|
|
// Prefer the to_pounds procedure group.
|
|
@(fast_math = {.Allow_Reciprocal})
|
|
ounces_to_pounds :: #force_inline proc "contextless" (
|
|
ounces: Ounces($V),
|
|
) -> Pounds(V) where intrinsics.type_is_numeric(V) {
|
|
return Pounds(V){ounces.v / OUNCES_PER_POUND}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ----- Conversion Overloads ------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
to_grams :: proc {
|
|
kilo_grams_to_grams,
|
|
milli_grams_to_grams,
|
|
micro_grams_to_grams,
|
|
nano_grams_to_grams,
|
|
pounds_to_grams,
|
|
ounces_to_grams,
|
|
}
|
|
|
|
to_kilo_grams :: proc {
|
|
grams_to_kilo_grams,
|
|
milli_grams_to_kilo_grams,
|
|
micro_grams_to_kilo_grams,
|
|
nano_grams_to_kilo_grams,
|
|
pounds_to_kilo_grams,
|
|
ounces_to_kilo_grams,
|
|
}
|
|
|
|
to_milli_grams :: proc {
|
|
grams_to_milli_grams,
|
|
kilo_grams_to_milli_grams,
|
|
micro_grams_to_milli_grams,
|
|
nano_grams_to_milli_grams,
|
|
pounds_to_milli_grams,
|
|
ounces_to_milli_grams,
|
|
}
|
|
|
|
to_micro_grams :: proc {
|
|
grams_to_micro_grams,
|
|
kilo_grams_to_micro_grams,
|
|
milli_grams_to_micro_grams,
|
|
nano_grams_to_micro_grams,
|
|
pounds_to_micro_grams,
|
|
ounces_to_micro_grams,
|
|
}
|
|
|
|
to_nano_grams :: proc {
|
|
grams_to_nano_grams,
|
|
kilo_grams_to_nano_grams,
|
|
milli_grams_to_nano_grams,
|
|
micro_grams_to_nano_grams,
|
|
pounds_to_nano_grams,
|
|
ounces_to_nano_grams,
|
|
}
|
|
|
|
to_pounds :: proc {
|
|
grams_to_pounds,
|
|
kilo_grams_to_pounds,
|
|
milli_grams_to_pounds,
|
|
micro_grams_to_pounds,
|
|
nano_grams_to_pounds,
|
|
ounces_to_pounds,
|
|
}
|
|
|
|
to_ounces :: proc {
|
|
grams_to_ounces,
|
|
kilo_grams_to_ounces,
|
|
milli_grams_to_ounces,
|
|
micro_grams_to_ounces,
|
|
nano_grams_to_ounces,
|
|
pounds_to_ounces,
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ----- Tests ------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
import "core:testing"
|
|
|
|
@(test)
|
|
test_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
|
grams := Grams(int){12_000}
|
|
kilo_grams := to_kilo_grams(grams)
|
|
|
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){12})
|
|
}
|
|
|
|
@(test)
|
|
test_grams_to_milli_grams :: proc(t: ^testing.T) {
|
|
grams := Grams(int){12}
|
|
milli_grams := to_milli_grams(grams)
|
|
|
|
testing.expect_value(t, milli_grams, Milli_Grams(int){12_000})
|
|
}
|
|
|
|
@(test)
|
|
test_grams_to_micro_grams :: proc(t: ^testing.T) {
|
|
grams := Grams(int){12}
|
|
micro_grams := to_micro_grams(grams)
|
|
|
|
testing.expect_value(t, micro_grams, Micro_Grams(int){12_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_grams_to_nano_grams :: proc(t: ^testing.T) {
|
|
grams := Grams(int){12}
|
|
nano_grams := to_nano_grams(grams)
|
|
|
|
testing.expect_value(t, nano_grams, Nano_Grams(int){12_000_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_grams_to_pounds :: proc(t: ^testing.T) {
|
|
grams := Grams(f32){453.59237}
|
|
pounds := to_pounds(grams)
|
|
|
|
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
|
}
|
|
|
|
@(test)
|
|
test_grams_to_ounces :: proc(t: ^testing.T) {
|
|
grams := Grams(f32){28.349523125}
|
|
ounces := to_ounces(grams)
|
|
|
|
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_grams :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(int){12}
|
|
grams := to_grams(kilo_grams)
|
|
|
|
testing.expect_value(t, grams, Grams(int){12_000})
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_milli_grams :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(int){5}
|
|
milli_grams := to_milli_grams(kilo_grams)
|
|
|
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_micro_grams :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(int){5}
|
|
micro_grams := to_micro_grams(kilo_grams)
|
|
|
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_nano_grams :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(int){5}
|
|
nano_grams := to_nano_grams(kilo_grams)
|
|
|
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_pounds :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(f32){0.45359237}
|
|
pounds := to_pounds(kilo_grams)
|
|
|
|
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
|
}
|
|
|
|
@(test)
|
|
test_kilo_grams_to_ounces :: proc(t: ^testing.T) {
|
|
kilo_grams := Kilo_Grams(f32){0.028349523125}
|
|
ounces := to_ounces(kilo_grams)
|
|
|
|
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_grams :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(int){12_000}
|
|
grams := to_grams(milli_grams)
|
|
|
|
testing.expect_value(t, grams, Grams(int){12})
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(int){5_000_000}
|
|
kilo_grams := to_kilo_grams(milli_grams)
|
|
|
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_micro_grams :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(int){5}
|
|
micro_grams := to_micro_grams(milli_grams)
|
|
|
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000})
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_nano_grams :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(int){5}
|
|
nano_grams := to_nano_grams(milli_grams)
|
|
|
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000})
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_pounds :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(f64){453_592.37}
|
|
pounds := to_pounds(milli_grams)
|
|
|
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_milli_grams_to_ounces :: proc(t: ^testing.T) {
|
|
milli_grams := Milli_Grams(f64){28_349.523125}
|
|
ounces := to_ounces(milli_grams)
|
|
|
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_grams :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(int){12_000_000}
|
|
grams := to_grams(micro_grams)
|
|
|
|
testing.expect_value(t, grams, Grams(int){12})
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(int){5_000_000_000}
|
|
kilo_grams := to_kilo_grams(micro_grams)
|
|
|
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_milli_grams :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(int){5_000}
|
|
milli_grams := to_milli_grams(micro_grams)
|
|
|
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_nano_grams :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(int){5}
|
|
nano_grams := to_nano_grams(micro_grams)
|
|
|
|
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000})
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_pounds :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(f64){453_592_370}
|
|
pounds := to_pounds(micro_grams)
|
|
|
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_micro_grams_to_ounces :: proc(t: ^testing.T) {
|
|
micro_grams := Micro_Grams(f64){28_349_523.125}
|
|
ounces := to_ounces(micro_grams)
|
|
|
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_grams :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(int){12_000_000_000}
|
|
grams := to_grams(nano_grams)
|
|
|
|
testing.expect_value(t, grams, Grams(int){12})
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(int){5_000_000_000_000}
|
|
kilo_grams := to_kilo_grams(nano_grams)
|
|
|
|
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_milli_grams :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(int){5_000_000}
|
|
milli_grams := to_milli_grams(nano_grams)
|
|
|
|
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_micro_grams :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(int){5_000}
|
|
micro_grams := to_micro_grams(nano_grams)
|
|
|
|
testing.expect_value(t, micro_grams, Micro_Grams(int){5})
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_pounds :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(f64){453_592_370_000}
|
|
pounds := to_pounds(nano_grams)
|
|
|
|
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_nano_grams_to_ounces :: proc(t: ^testing.T) {
|
|
nano_grams := Nano_Grams(f64){28_349_523_125}
|
|
ounces := to_ounces(nano_grams)
|
|
|
|
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_grams :: proc(t: ^testing.T) {
|
|
pounds := Pounds(f32){1}
|
|
grams := to_grams(pounds)
|
|
|
|
testing.expect(t, grams.v > 453.59 && grams.v < 453.6)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_kilo_grams :: proc(t: ^testing.T) {
|
|
pounds := Pounds(f32){1}
|
|
kilo_grams := to_kilo_grams(pounds)
|
|
|
|
testing.expect(t, kilo_grams.v > 0.4535 && kilo_grams.v < 0.4536)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_milli_grams :: proc(t: ^testing.T) {
|
|
pounds := Pounds(f64){1}
|
|
milli_grams := to_milli_grams(pounds)
|
|
|
|
testing.expect(t, milli_grams.v > 453_592.369 && milli_grams.v < 453_592.371)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_micro_grams :: proc(t: ^testing.T) {
|
|
pounds := Pounds(f64){1}
|
|
micro_grams := to_micro_grams(pounds)
|
|
|
|
testing.expect(t, micro_grams.v > 453_592_369.9 && micro_grams.v < 453_592_370.1)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_nano_grams :: proc(t: ^testing.T) {
|
|
pounds := Pounds(f64){1}
|
|
nano_grams := to_nano_grams(pounds)
|
|
|
|
testing.expect(t, nano_grams.v > 453_592_369_999.0 && nano_grams.v < 453_592_370_001.0)
|
|
}
|
|
|
|
@(test)
|
|
test_pounds_to_ounces :: proc(t: ^testing.T) {
|
|
pounds := Pounds(int){2}
|
|
ounces := to_ounces(pounds)
|
|
|
|
testing.expect_value(t, ounces, Ounces(int){32})
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_grams :: proc(t: ^testing.T) {
|
|
ounces := Ounces(f32){1}
|
|
grams := to_grams(ounces)
|
|
|
|
testing.expect(t, grams.v > 28.34 && grams.v < 28.35)
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_kilo_grams :: proc(t: ^testing.T) {
|
|
ounces := Ounces(f32){1}
|
|
kilo_grams := to_kilo_grams(ounces)
|
|
|
|
testing.expect(t, kilo_grams.v > 0.0283 && kilo_grams.v < 0.0284)
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_milli_grams :: proc(t: ^testing.T) {
|
|
ounces := Ounces(f64){1}
|
|
milli_grams := to_milli_grams(ounces)
|
|
|
|
testing.expect(t, milli_grams.v > 28_349.523 && milli_grams.v < 28_349.524)
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_micro_grams :: proc(t: ^testing.T) {
|
|
ounces := Ounces(f64){1}
|
|
micro_grams := to_micro_grams(ounces)
|
|
|
|
testing.expect(t, micro_grams.v > 28_349_523.124 && micro_grams.v < 28_349_523.126)
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_nano_grams :: proc(t: ^testing.T) {
|
|
ounces := Ounces(f64){1}
|
|
nano_grams := to_nano_grams(ounces)
|
|
|
|
testing.expect(t, nano_grams.v > 28_349_523_124.0 && nano_grams.v < 28_349_523_126.0)
|
|
}
|
|
|
|
@(test)
|
|
test_ounces_to_pounds :: proc(t: ^testing.T) {
|
|
ounces := Ounces(int){32}
|
|
pounds := to_pounds(ounces)
|
|
|
|
testing.expect_value(t, pounds, Pounds(int){2})
|
|
}
|