[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/007 1aeae253 03/10: Add a unit test for ledg
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/007 1aeae253 03/10: Add a unit test for ledger_format() |
Date: |
Tue, 19 Apr 2022 19:00:41 -0400 (EDT) |
branch: valyuta/007
commit 1aeae25339ed045c11f743a4aa39fecfe82de2f6
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add a unit test for ledger_format()
---
ledger_test.cpp | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/ledger_test.cpp b/ledger_test.cpp
index 23e220c8..d2c1df95 100644
--- a/ledger_test.cpp
+++ b/ledger_test.cpp
@@ -24,7 +24,9 @@
#include "ledger.hpp"
#include "ledger_evaluator.hpp"
#include "ledger_invariant.hpp"
+#include "ledger_text_formats.hpp" // ledger_format()
#include "ledger_variant.hpp"
+#include "oecumenic_enumerations.hpp"
#include "test_tools.hpp"
#include "timer.hpp"
@@ -40,12 +42,14 @@ class ledger_test
{
test_default_initialization();
test_evaluator();
+ test_ledger_format();
test_speed();
}
private:
static void test_default_initialization();
static void test_evaluator();
+ static void test_ledger_format();
static void test_speed();
};
@@ -75,6 +79,23 @@ void ledger_test::test_evaluator()
LMI_TEST(0 == std::remove("tsv_eraseme.values.tsv"));
}
+void ledger_test::test_ledger_format()
+{
+ constexpr double pi {3.14159265358979323851};
+ constexpr std::pair<int,oenum_format_style> f1(0, oe_format_normal);
+ constexpr std::pair<int,oenum_format_style> f2(2, oe_format_normal);
+ constexpr std::pair<int,oenum_format_style> f3(0, oe_format_percentage);
+ constexpr std::pair<int,oenum_format_style> f4(2, oe_format_percentage);
+ constexpr std::pair<int,oenum_format_style> g1(9, oe_format_normal);
+ constexpr std::pair<int,oenum_format_style> g2(4, oe_format_percentage);
+ LMI_TEST_EQUAL("3" , ledger_format(pi, f1));
+ LMI_TEST_EQUAL("3.14" , ledger_format(pi, f2));
+ LMI_TEST_EQUAL("314%" , ledger_format(pi, f3));
+ LMI_TEST_EQUAL("314.16%" , ledger_format(pi, f4));
+ LMI_TEST_EQUAL("3.141592654", ledger_format(pi, g1));
+ LMI_TEST_EQUAL("314.1593%" , ledger_format(pi, g2));
+}
+
void ledger_test::test_speed()
{
Ledger ledger(100, mce_finra, false, false, false);
- [lmi-commits] [lmi] valyuta/007 updated (4c404956 -> 0b887792), Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 18a91e63 01/10: Fix dblize()ation in commented-out code, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 efa7b7a8 02/10: Add a helper function with a deliberately ugly name, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 1aeae253 03/10: Add a unit test for ledger_format(),
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/007 c55ec8f6 04/10: Add an option to format cents as decimal dollars, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 6569915e 06/10: Reformat, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 0b887792 10/10: Change many more ledger fields to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 7b3debe3 07/10: Add a 'divisor' argument to LedgerBase::value_str(), Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 7535505d 09/10: Change several more ledger fields to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 1189d3ac 05/10: Change a ledger field to cents, Greg Chicares, 2022/04/19
- [lmi-commits] [lmi] valyuta/007 2d26a146 08/10: Change several more ledger fields to cents, Greg Chicares, 2022/04/19