Skip to content

Commit

Permalink
Merge GH-17: tests reporting
Browse files Browse the repository at this point in the history
Signed-off-by: 35V LG84 <35vlg84-x4e6b92@e257.fi>
  • Loading branch information
35VLG84 committed Dec 1, 2024
2 parents 74b08dd + 658f20d commit c55ece7
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 22 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ New features:

==== Fixes

Fixes in this release: none
Fixes in this release:

* Register report: Tackler-mkI compatible output


==== Development
Expand Down
10 changes: 4 additions & 6 deletions examples/tackler.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### Configuration settings for Tackler-NG
### The main configuration file for Tackler-NG
###
### The format of this file is TOML (https://toml.io/en/)
### The format is TOML (https://toml.io/en/)
[kernel]
### Stric mode
###
### When this is true, then all accounts, commodities and tags
### must be predefined. If there is an undefined item,
### it's fatal halting error.
### must be predefined. It's fatal halting error,
### if there is an undefined item in the transaction data.
###
### Valid options are: true | false
### CLI: --strict.mode
Expand Down Expand Up @@ -71,8 +71,6 @@ hash = "SHA-256"
### CLI: --audit.mode
mode = true



### Transaction Input Configuration
[kernel.input]
### Type of input storage system
Expand Down
2 changes: 1 addition & 1 deletion suite
Submodule suite updated 65 files
+10 −0 reporting/equity/equity-acc-01-ng.ref.bal.txt
+19 −0 reporting/equity/equity-acc-01-ng.ref.balgrp.txt
+6 −0 reporting/equity/equity-acc-01-ng.ref.equity.txn
+18 −0 reporting/equity/equity-acc-01-ng.ref.identity.txn
+20 −0 reporting/equity/equity-acc-01-ng.ref.reg.txt
+7 −4 reporting/equity/equity-acc-01.ref.balgrp.txt
+7 −4 reporting/equity/equity-acc-01.ref.reg.txt
+15 −0 reporting/equity/equity-tep1014-01-ng.ref.bal.txt
+12 −0 reporting/equity/equity-tep1014-01-ng.ref.equity.txn
+51 −0 reporting/equity/equity-tep1014-as-input-ng.ref.identity.txn
+3 −2 reporting/group-by/date.conf
+15 −6 reporting/group-by/date.ref.balgrp.json
+15 −12 reporting/group-by/date.ref.balgrp.txt
+35 −0 reporting/group-by/date.toml
+5 −0 reporting/group-by/group-by-accounts.toml
+3 −2 reporting/group-by/iso-week-date.conf
+15 −6 reporting/group-by/iso-week-date.ref.balgrp.json
+15 −12 reporting/group-by/iso-week-date.ref.balgrp.txt
+35 −0 reporting/group-by/iso-week-date.toml
+3 −2 reporting/group-by/iso-week.conf
+13 −4 reporting/group-by/iso-week.ref.balgrp.json
+11 −8 reporting/group-by/iso-week.ref.balgrp.txt
+35 −0 reporting/group-by/iso-week.toml
+3 −2 reporting/group-by/month.conf
+13 −4 reporting/group-by/month.ref.balgrp.json
+11 −8 reporting/group-by/month.ref.balgrp.txt
+35 −0 reporting/group-by/month.toml
+0 −0 reporting/group-by/txns/plain/ts-plain-group-by.txn
+4 −4 reporting/group-by/txns/zoned/ts-zoned-group-by.txn
+3 −2 reporting/group-by/year.conf
+11 −2 reporting/group-by/year.ref.balgrp.json
+7 −4 reporting/group-by/year.ref.balgrp.txt
+35 −0 reporting/group-by/year.toml
+1 −1 reporting/group-by/zoned-date.exec
+16 −7 reporting/group-by/zoned-date.ref.balgrp.json
+17 −14 reporting/group-by/zoned-date.ref.balgrp.txt
+1 −1 reporting/group-by/zoned-iso-week-date.exec
+16 −7 reporting/group-by/zoned-iso-week-date.ref.balgrp.json
+48 −0 reporting/group-by/zoned-iso-week-date.ref.balgrp.txt
+1 −1 reporting/group-by/zoned-iso-week.exec
+7 −0 reporting/group-by/zoned-iso-week.ref.bal.txt
+21 −52 reporting/group-by/zoned-iso-week.ref.balgrp.json
+15 −24 reporting/group-by/zoned-iso-week.ref.balgrp.txt
+1 −1 reporting/group-by/zoned-month.exec
+7 −0 reporting/group-by/zoned-month.ref.bal.txt
+18 −29 reporting/group-by/zoned-month.ref.balgrp.json
+36 −0 reporting/group-by/zoned-month.ref.balgrp.txt
+1 −1 reporting/group-by/zoned-year.exec
+20 −51 reporting/group-by/zoned-year.ref.balgrp.json
+13 −22 reporting/group-by/zoned-year.ref.balgrp.txt
+39 −0 reporting/ok-accounts.toml
+9 −0 reporting/ok-commodities.toml
+1 −0 reporting/ok.equity-acc.conf
+35 −0 reporting/ok.equity-acc.toml
+35 −0 reporting/ok.equity-tep1014.toml
+38 −0 reporting/time-and-zones/date-ng.ref.balgrp.txt
+26 −0 reporting/time-and-zones/date-ng.ref.reg.txt
+35 −0 reporting/time-and-zones/date.toml
+35 −0 reporting/time-and-zones/iso-week-date.toml
+35 −0 reporting/time-and-zones/iso-week.toml
+35 −0 reporting/time-and-zones/month.toml
+5 −0 reporting/time-and-zones/tz-accounts.toml
+30 −0 reporting/time-and-zones/year-ng.ref.balgrp.txt
+26 −0 reporting/time-and-zones/year-ng.ref.reg.txt
+35 −0 reporting/time-and-zones/year.toml
35 changes: 22 additions & 13 deletions tackler-core/src/model/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::config::Scale;
use crate::model::{Posting, Transaction};
use rust_decimal::{Decimal, RoundingStrategy};
use std::cmp::{max, Ordering};
use std::fmt::Write;
use std::fmt::{Display, Formatter};
use tackler_api::txn_ts;
use time::OffsetDateTime;
Expand Down Expand Up @@ -73,35 +74,43 @@ impl<'a> RegisterEntry<'a> {
tz: &'static Tz,
scale: &Scale,
) -> String {
fn amount_to_string(amount: &Decimal, scale: &Scale, width: usize) -> String {
let prec = scale.get_precision(amount);
let amount_txt = format!(
"{:.prec$}",
amount.round_dp_with_strategy(prec as u32, RoundingStrategy::MidpointAwayFromZero)
);

if amount.is_sign_positive() && amount_txt.chars().count() >= width {
format!(" {}", amount_txt)
} else {
amount_txt
}
}

let indent = " ".repeat(12);
let mut line_len = 0;
let mut s = self.txn.header.to_string_with_indent(&indent, ts_fmtr, tz);
let mut reg_entry_txt = self.txn.header.to_string_with_indent(&indent, ts_fmtr, tz);

for p in &self.posts {
let comm = &p.post.acctn.comm;

let prec_1 = scale.get_precision(&p.post.amount);
let prec_2 = scale.get_precision(&p.amount);

let line = format!(
"{}{:<33}{:>18.prec_1$} {:>18.prec_2$}{}",
"{}{:<33}{:>18} {:>18}{}",
indent,
p.post.acctn.atn.account,
p.post
.amount
.round_dp_with_strategy(prec_1 as u32, RoundingStrategy::MidpointAwayFromZero),
p.amount
.round_dp_with_strategy(prec_2 as u32, RoundingStrategy::MidpointAwayFromZero),
amount_to_string(&p.post.amount, scale, 18),
amount_to_string(&p.amount, scale, 18),
match &comm.is_some() {
true => format!(" {}", comm.name),
false => String::new(),
},
);
line_len = max(line_len, line.chars().count());
s += &line;
s += "\n";
let _ = writeln!(reg_entry_txt, "{}", line);
}
format!("{s}{}\n", "-".repeat(line_len))
let _ = writeln!(reg_entry_txt, "{}", "-".repeat(line_len));
reg_entry_txt
}
}
impl<'a> Display for RegisterEntry<'a> {
Expand Down
8 changes: 7 additions & 1 deletion tests/sh/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ cmp_result () {
local test_name=$2
local suffix=$3
local target=$4
local ok_path="$5"

ref=$SUITE_PATH/$module/ok/$test_name.ref.$target.$suffix
if [ "x$ok_path" == "x" ]; then
ok="ok"
else
ok=$ok_path
fi
ref=$SUITE_PATH/$module/$ok/$test_name.ref.$target.$suffix
out=$OUTPUT_DIR/$test_name.$target.$suffix

cmp $ref $out || {
Expand Down
123 changes: 123 additions & 0 deletions tests/sh/reporting-equity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#
# Copyright 2024 E257.FI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -e

source $TEST_DIR/lib/utils.sh


###
### REPORTING / EQUITY
###
module=reporting/equity

#####################################################################
#
# equity-acc-01
#
# test: 29d24d2e-702f-4c27-b5de-82ac88ca68ca
rm -f $OUTPUT_DIR/*
test_name=equity-acc-01-ng
echo "test: $module/$test_name: "

$TACKLER_SH \
--input.file $SUITE_PATH/$module/../ok/reporting.txn \
--output.dir $OUTPUT_DIR \
--output.prefix $test_name \
--config $SUITE_PATH/$module/../ok.equity-acc.toml

echo -n "check:"
cmp_result $module $test_name txt bal "."
cmp_result $module $test_name txt balgrp "."
cmp_result $module $test_name txt reg "."
cmp_result $module $test_name txn equity "."
cmp_result $module $test_name txn identity "."
echo ": ok"

#####################################################################
#
# equity-tep1014-02
#
# This is variant of c0b34ebb-a5d2-4b09-96cb-2594b3635650 with
# maximum precision points of rust-decimal
#
# test: 8542680a-2e94-437f-b0a5-cdef46ef8521
rm -f $OUTPUT_DIR/*
test_name=equity-tep1014-01-ng
echo "test: $module/$test_name: "

$TACKLER_SH \
--input.file $SUITE_PATH/$module/../big-and-small.txn \
--output.dir $OUTPUT_DIR \
--output.prefix $test_name \
--config $SUITE_PATH/$module/../ok.equity-tep1014.toml

echo -n "check:"
cmp_result $module $test_name txt bal "."
cmp_result $module $test_name txn equity "."
echo ": ok"


#####################################################################
#
# equity-tep1014-as-input
#
# This is variant of 78982e06-4f11-4f52-8689-df400b8c3a93 with
# maximum precision points of rust-decimal
#
# test: c2e27940-a141-41ed-adc2-da294d519804
rm -f $OUTPUT_DIR/*
test_name=equity-tep1014-as-input
echo "test: $module/$test_name: "

mkdir -p $OUTPUT_DIR/txnsout

$TACKLER_SH \
--config $SUITE_PATH/$module/../ok.equity-tep1014.toml \
--input.file $SUITE_PATH/$module/../big-and-small.txn \
--output.dir $OUTPUT_DIR/txnsout \
--output.prefix equity-tep1014-input-01 \

$TACKLER_SH \
--config $SUITE_PATH/$module/../ok.equity-tep1014.toml \
--input.file $SUITE_PATH/$module/equity-tep1014-as-input.txn \
--output.dir $OUTPUT_DIR/txnsout \
--output.prefix equity-tep1014-input-02 \
--accounts 'a(:.*)?' \

$TACKLER_SH \
--config $SUITE_PATH/$module/../ok.equity-tep1014.toml \
--input.file $SUITE_PATH/$module/equity-tep1014-as-input2.txn \
--output.dir $OUTPUT_DIR/txnsout \
--output.prefix equity-tep1014-input-03 \
--accounts 'a(:.*)?' 'e(:.*)?' \

$TACKLER_SH \
--config $SUITE_PATH/$module/../ok.equity-tep1014.toml \
--input.fs.dir $OUTPUT_DIR/txnsout \
--input.fs.ext "txn" \
--output.dir $OUTPUT_DIR \
--output.prefix $test_name-ng \
--accounts 'a(:.*)?' 'e(:.*)?' \
--exports "identity" \


echo -n "check:"
cmp_result $module $test_name-ng txn identity "."
echo ": ok"



Loading

0 comments on commit c55ece7

Please sign in to comment.