From d33382c95d5c6c257173f5a61fb11728eb06f726 Mon Sep 17 00:00:00 2001 From: sidey79 Date: Fri, 20 Jan 2023 21:07:45 +0000 Subject: [PATCH] Math.pm: added unittest for round function git-svn-id: https://svn.fhem.de/fhem/trunk@27092 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/Core/Utils/00_func_Math.t | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 fhem/t/FHEM/Core/Utils/00_func_Math.t diff --git a/fhem/t/FHEM/Core/Utils/00_func_Math.t b/fhem/t/FHEM/Core/Utils/00_func_Math.t new file mode 100644 index 000000000..9b20121cb --- /dev/null +++ b/fhem/t/FHEM/Core/Utils/00_func_Math.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test2::V0; +use Test2::Tools::Compare qw{is}; + +use FHEM::Core::Utils::Math; + +subtest 'Round to three decimals after dot' => sub { + is (FHEM::Core::Utils::Math::round(100/3,3),33.333,'round returned three decimals after dot'); +}; + +subtest 'Round negative, to one decimals after dot' => sub { + is (FHEM::Core::Utils::Math::round(-100/3,1),-33.3,'round returned one decimals after dot'); +}; + +subtest 'Round negative, to no decimals after dot' => sub { + is (FHEM::Core::Utils::Math::round(100/3,0),33,'round returned zero decimals after dot'); +}; + +subtest 'No decimals specified' => sub { + is (FHEM::Core::Utils::Math::round(100/3),U(),'round returned undef'); +}; + + +subtest 'No value specified' => sub { + is (FHEM::Core::Utils::Math::round(),U(),'round returned undef'); +}; + +done_testing(); +exit(0); +1; \ No newline at end of file