In the beginning...
This commit is contained in:
59
quantity/volume.odin
Normal file
59
quantity/volume.odin
Normal file
@@ -0,0 +1,59 @@
|
||||
package quantity
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
//----- Liters ----------------------------------
|
||||
Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
liters_to_milli_liters :: #force_inline proc "contextless" (
|
||||
liters: Liters($V),
|
||||
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Liters(V){liters.v * MILLI}
|
||||
}
|
||||
|
||||
//----- Milliliters ----------------------------------
|
||||
Milli_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
milli_liters_to_liters :: #force_inline proc "contextless" (
|
||||
milli_liters: Milli_Liters($V),
|
||||
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Liters(V){milli_liters.v / MILLI}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// ----- Conversion Overloads ------------------------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
to_liters :: proc {
|
||||
milli_liters_to_liters,
|
||||
}
|
||||
|
||||
to_milli_liters :: proc {
|
||||
liters_to_milli_liters,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// ----- Tests ------------------------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_liters_to_milli_liters :: proc(t: ^testing.T) {
|
||||
liters := Liters(int){12}
|
||||
milli_liters := to_milli_liters(liters)
|
||||
|
||||
testing.expect_value(t, milli_liters, Milli_Liters(int){12_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_liters_to_liters :: proc(t: ^testing.T) {
|
||||
milli_liters := Milli_Liters(int){12_000}
|
||||
liters := to_liters(milli_liters)
|
||||
|
||||
testing.expect_value(t, liters, Liters(int){12})
|
||||
}
|
||||
Reference in New Issue
Block a user