Skip to content

Commit

Permalink
Fix ratios for liters and milliliters (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpurgin authored Nov 29, 2023
1 parent fc21bda commit e037af8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/scalr/named_quantity/volume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ struct cubic_meters {

struct liters {
using dimension = volume_dimension;
using ratio = std::ratio<100>;
using ratio = std::milli;
};

struct milliliters {
using dimension = volume_dimension;
using ratio = std::ratio<10000>;
using ratio = std::micro;
};

template <typename Ratio>
Expand All @@ -69,20 +69,20 @@ struct make<volume_dimension, std::ratio<1>> {
};

template <>
struct make<volume_dimension, std::ratio<1, 1000>> {
struct make<volume_dimension, std::milli> {
using type = liters;
};

template <>
struct make<volume_dimension, std::ratio<1, 1000000>> {
struct make<volume_dimension, std::micro> {
using type = milliliters;
};

} // namespace unit

using cubic_meters = volume<double, std::ratio<1>>;
using liters = volume<double, std::ratio<1, 1000>>;
using milliliters = volume<double, std::ratio<1, 1000000>>;
using liters = volume<double, std::milli>;
using milliliters = volume<double, std::micro>;

namespace literals {

Expand Down
6 changes: 6 additions & 0 deletions tests/scalr_core.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ TEST_CASE("Named Quantities") {
CHECK(80_kg * 9.81_mps2 * 3_m / 5_s == 470.88_W);
}

SECTION("Volume") {
CHECK(1_l == 1000_ml);
CHECK(1000_l == 1_m3);
CHECK(0.5_l + 250_ml == 0.75_l);
}

SECTION("Quantity Conversion") {
scalr::seconds secs{12};
scalr::minutes mins{4};
Expand Down

0 comments on commit e037af8

Please sign in to comment.