Mercurial > hgweb.cgi > pecunia
changeset 165:dc7eb2be563d
Renamed the math functions to be descriptive.
Updated known issues.
author | John Schneiderman <JohnMS@member.fsf.org> |
---|---|
date | Tue, 19 Jan 2021 16:56:05 +0100 |
parents | 7ebc56fc3906 |
children | ba906381d991 |
files | INSTALL src/external/pecunia/Algorithm.hpp src/external/pecunia/Math.cpp src/external/pecunia/Math.h src/external/pecunia/Money.h src/unit-tests/math-unit-tests.cpp |
diffstat | 6 files changed, 42 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/INSTALL Tue Jan 19 16:38:28 2021 +0100 +++ b/INSTALL Tue Jan 19 16:56:05 2021 +0100 @@ -38,7 +38,7 @@ Build Options ============= -0) To enable the unit tests, set the CMake option Pecunia_ENABLE_TESTS to ON. +0) Optionally to enable the unit tests, set the CMake option Pecunia_ENABLE_TESTS to ON. How-To compile the program ========================== @@ -48,4 +48,5 @@ Known Issues ============ -0) None. +0) Stream insertion operator does not clean up afterwards. +1) Stream extraction operator does not clean up afterwards.
--- a/src/external/pecunia/Algorithm.hpp Tue Jan 19 16:38:28 2021 +0100 +++ b/src/external/pecunia/Algorithm.hpp Tue Jan 19 16:56:05 2021 +0100 @@ -33,7 +33,7 @@ * @brief Sorts the container using a less-than comparison operator. The sort is not stable. * * @tparam ContainerType The type of container holding the monetary values to sort. The container - * must have random access interator support. The contained type must support the operators + * must have random access iterator support. The contained type must support the operators * less-than, greater-than, and have a swap function. * * @param container The container holding the monetary values to sort.
--- a/src/external/pecunia/Math.cpp Tue Jan 19 16:38:28 2021 +0100 +++ b/src/external/pecunia/Math.cpp Tue Jan 19 16:56:05 2021 +0100 @@ -24,15 +24,15 @@ using pecunia::currency::Money; #include <cmath> -//using std::abs; +using std::abs; #include <numeric> using std::accumulate; -Money pecunia::math::abs(const Money& money) +Money pecunia::math::absoluteValue(const Money& money) { auto copy{money}; - copy.amount_ = std::abs(copy.amount_); + copy.amount_ = abs(copy.amount_); return copy; }
--- a/src/external/pecunia/Math.h Tue Jan 19 16:38:28 2021 +0100 +++ b/src/external/pecunia/Math.h Tue Jan 19 16:56:05 2021 +0100 @@ -41,7 +41,7 @@ * * @return The absolute value of the monetary amount. */ -PECUNIA_EXPORT currency::Money abs(const currency::Money& money); +PECUNIA_EXPORT currency::Money absoluteValue(const currency::Money& money); /** * @brief Accumulates the total of all the supplied monies with the fewest possible number of * conversions. @@ -58,7 +58,7 @@ * @return The sum of all the monies in the requested currency. */ template<template<typename, typename> class Container, typename ValueType, typename Allocator> -currency::Money accumulate( +currency::Money sum( const currency::Iso4217Codes& accumulateCurrency, const Container<ValueType, Allocator>& monies, const std::function< @@ -88,7 +88,7 @@ class Compare = std::less<KeyType>, class Allocator = std::allocator<std::pair<const KeyType, ValueType>> > -currency::Money accumulate( +currency::Money sum( const currency::Iso4217Codes& accumulateCurrency, const AssociativeContainer<KeyType, ValueType, Compare, Allocator>& monies, const std::function< @@ -114,7 +114,7 @@ }}} template<template<typename, typename> class Container, typename ValueType, typename Allocator> -pecunia::currency::Money pecunia::math::accumulate( +pecunia::currency::Money pecunia::math::sum( const pecunia::currency::Iso4217Codes& accumulateCurrency, const Container<ValueType, Allocator>& monies, const std::function< @@ -140,7 +140,7 @@ class Compare, class Allocator > -pecunia::currency::Money pecunia::math::accumulate( +pecunia::currency::Money pecunia::math::sum( const pecunia::currency::Iso4217Codes& accumulateCurrency, const AssociativeContainer<KeyType, ValueType, Compare, Allocator>& monies, const std::function<
--- a/src/external/pecunia/Money.h Tue Jan 19 16:38:28 2021 +0100 +++ b/src/external/pecunia/Money.h Tue Jan 19 16:56:05 2021 +0100 @@ -44,7 +44,7 @@ namespace math { -PECUNIA_EXPORT currency::Money abs(const currency::Money& money); +PECUNIA_EXPORT currency::Money absoluteValue(const currency::Money& money); } namespace currency @@ -56,7 +56,7 @@ */ class PECUNIA_EXPORT Money { - friend PECUNIA_EXPORT Money math::abs(const Money&); + friend PECUNIA_EXPORT Money math::absoluteValue(const Money&); friend PECUNIA_EXPORT Money operator*(const std::int8_t lhs, const Money& rhs); friend PECUNIA_EXPORT Money operator*(const std::int16_t lhs, const Money& rhs); friend PECUNIA_EXPORT Money operator*(const std::int32_t lhs, const Money& rhs);
--- a/src/unit-tests/math-unit-tests.cpp Tue Jan 19 16:38:28 2021 +0100 +++ b/src/unit-tests/math-unit-tests.cpp Tue Jan 19 16:56:05 2021 +0100 @@ -38,8 +38,8 @@ #include <pecunia/Codes.h> using pecunia::currency::Iso4217Codes; #include <pecunia/Math.h> -using pecunia::math::abs; -using pecunia::math::accumulate; +using pecunia::math::absoluteValue; +using pecunia::math::sum; #include <pecunia/Money.h> using pecunia::currency::Money; #include <pecunia/MoneyTypes.h> @@ -130,46 +130,46 @@ Q_OBJECT private slots: - //{ abs Tests + //{ absoluteValue Tests - void abs_Positive_ShouldBeSame() + void absoluteValue_Positive_ShouldBeSame() { const Money sm{100, 23u, Iso4217Codes::XXX}; - const auto actual{abs(sm)}; + const auto actual{absoluteValue(sm)}; const Money expected{100, 23u, Iso4217Codes::XXX}; QCOMPARE(actual, expected); } - void abs_Negative_ShouldBePositive() + void absoluteValue_Negative_ShouldBePositive() { const Money sm{-100, 23u, Iso4217Codes::XXX}; - const auto actual{abs(sm)}; + const auto actual{absoluteValue(sm)}; const Money expected{100, 23u, Iso4217Codes::XXX}; QCOMPARE(actual, expected); } //} - //{ accumulate Tests + //{ sum Tests - void accumulate_Empty_ShouldBeTotal() + void sum_Empty_ShouldBeTotal() { const vector<Money> monies{}; - const Money actual{accumulate(Iso4217Codes::XXX, monies)}; + const Money actual{sum(Iso4217Codes::XXX, monies)}; QCOMPARE(actual, Money(0, 0u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_SameCurrencies_ShouldBeTotal() + void sum_SameCurrencies_ShouldBeTotal() { const vector<Money> monies{ {100, 15u, Iso4217Codes::XXX}, {100, 15u, Iso4217Codes::XXX}, {100, 15u, Iso4217Codes::XXX} }; - const Money actual{accumulate(Iso4217Codes::XXX, monies)}; + const Money actual{sum(Iso4217Codes::XXX, monies)}; QCOMPARE(actual, Money(300, 45u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_SameCurrenciesWithFunctor_ShouldBeTotalDoubled() + void sum_SameCurrenciesWithDoublingFunctor_ShouldBeTotalDoubled() { const vector<Money> monies{ {100, 15u, Iso4217Codes::XXX}, @@ -177,12 +177,12 @@ {100, 15u, Iso4217Codes::XXX} }; const Money actual{ - accumulate(Iso4217Codes::XXX, monies, [] (const auto& money) { return money * 2; }) + sum(Iso4217Codes::XXX, monies, [] (const auto& money) { return money * 2; }) }; QCOMPARE(actual, Money(600, 90u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_DifferentCurrenciesSharedOneAccumulator_ShouldBeTotal() + void sum_DifferentCurrenciesSharedOneAccumulator_ShouldBeTotal() { pecunia::converter = testConverter; const vector<Money> monies{ @@ -190,44 +190,44 @@ {100, 1500u, Iso4217Codes::EUR}, {100, 1500u, Iso4217Codes::USD} }; - const Money actual{accumulate(Iso4217Codes::EUR, monies)}; + const Money actual{sum(Iso4217Codes::EUR, monies)}; // 200,30 USD -> 188,5145483 EUR // -> 100,1500 EUR QCOMPARE(actual, Money(288, 6645u, Iso4217Codes::EUR)); QCOMPARE(actual.code(), Iso4217Codes::EUR); } - void accumulate_DifferentCurrenciesDifferentAccumulator_ShouldBeTotal() + void sum_DifferentCurrenciesDifferentAccumulator_ShouldBeTotal() { const vector<Money> monies{ {100, 1500u, Iso4217Codes::USD}, {100, 1500u, Iso4217Codes::EUR}, {100, 1500u, Iso4217Codes::USD} }; - const Money actual{accumulate(Iso4217Codes::PLN, monies)}; + const Money actual{sum(Iso4217Codes::PLN, monies)}; // 200,30 USD -> 838,327608 PLN // 100,15 USD -> 445,369053 PLN QCOMPARE(actual, Money(1283, 6966u, Iso4217Codes::PLN)); QCOMPARE(actual.code(), Iso4217Codes::PLN); } - void accumulate_AssociativeContainerEmpty_ShouldBeTotal() + void sum_AssociativeContainerEmpty_ShouldBeTotal() { const map<qint32, Money> monies{}; - const Money actual{accumulate(Iso4217Codes::XXX, monies)}; + const Money actual{sum(Iso4217Codes::XXX, monies)}; QCOMPARE(actual, Money(0, 0u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_AssociativeContainerSameCurrencies_ShouldBeTotal() + void sum_AssociativeContainerSameCurrencies_ShouldBeTotal() { const map<qint32, Money> monies{ {1, {100, 15u, Iso4217Codes::XXX}}, {2, {100, 15u, Iso4217Codes::XXX}}, {3, {100, 15u, Iso4217Codes::XXX}} }; - const Money actual{accumulate(Iso4217Codes::XXX, monies)}; + const Money actual{sum(Iso4217Codes::XXX, monies)}; QCOMPARE(actual, Money(300, 45u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_AssociativeContainerSameCurrenciesWithFunctor_ShouldBeTotalDoubled() + void sum_AssociativeContainerSameCurrenciesWithFunctor_ShouldBeTotalDoubled() { const map<qint32, Money> monies{ {1, {100, 15u, Iso4217Codes::XXX}}, @@ -235,12 +235,12 @@ {3, {100, 15u, Iso4217Codes::XXX}} }; const Money actual{ - accumulate(Iso4217Codes::XXX, monies, [] (const auto& money) { return money * 2; }) + sum(Iso4217Codes::XXX, monies, [] (const auto& money) { return money * 2; }) }; QCOMPARE(actual, Money(600, 90u, Iso4217Codes::XXX)); QCOMPARE(actual.code(), Iso4217Codes::XXX); } - void accumulate_AssociativeContainerDifferentCurrenciesSharedOneAccumulator_ShouldBeTotal() + void sum_AssociativeContainerDifferentCurrenciesSharedOneAccumulator_ShouldBeTotal() { pecunia::converter = testConverter; const map<qint32, Money> monies{ @@ -248,20 +248,20 @@ {2, {100, 1500u, Iso4217Codes::EUR}}, {3, {100, 1500u, Iso4217Codes::USD}} }; - const Money actual{accumulate(Iso4217Codes::EUR, monies)}; + const Money actual{sum(Iso4217Codes::EUR, monies)}; // 200,30 USD -> 188,5145483 EUR // -> 100,1500 EUR QCOMPARE(actual, Money(288, 6645u, Iso4217Codes::EUR)); QCOMPARE(actual.code(), Iso4217Codes::EUR); } - void accumulate_AssociativeContainerDifferentCurrenciesDifferentAccumulator_ShouldBeTotal() + void sum_AssociativeContainerDifferentCurrenciesDifferentAccumulator_ShouldBeTotal() { const map<qint32, Money> monies{ {1, {100, 1500u, Iso4217Codes::USD}}, {2, {100, 1500u, Iso4217Codes::EUR}}, {3, {100, 1500u, Iso4217Codes::USD}} }; - const Money actual{accumulate(Iso4217Codes::PLN, monies)}; + const Money actual{sum(Iso4217Codes::PLN, monies)}; // 200,30 USD -> 838,327608 PLN // 100,15 USD -> 445,369053 PLN QCOMPARE(actual, Money(1283, 6966u, Iso4217Codes::PLN));