[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1201] trunk



Revision: 1201
          http://svn.sourceforge.net/ledger-smb/?rev=1201&view=rev
Author:   tetragon
Date:     2007-05-16 16:22:22 -0700 (Wed, 16 May 2007)

Log Message:
-----------
More test coverage of LedgerSMB.pm and re-expression of round_amount

Modified Paths:
--------------
    trunk/LedgerSMB.pm
    trunk/t/02-number-handling.t
    trunk/t/11-ledgersmb.t

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2007-05-16 02:53:40 UTC (rev 1200)
+++ trunk/LedgerSMB.pm	2007-05-16 23:22:22 UTC (rev 1201)
@@ -410,12 +410,19 @@
 
     # These rounding rules follow from the previous implementation.
     # They should be changed to allow different rules for different accounts.
-    Math::BigFloat->round_mode('+inf') if $amount >= 0;
-    Math::BigFloat->round_mode('-inf') if $amount < 0;
+    if ($amount >= 0) {
+        Math::BigFloat->round_mode('+inf');
+    } 
+    else {
+        Math::BigFloat->round_mode('-inf');
+    } 
 
-    $amount = Math::BigFloat->new($amount)->ffround( -$places ) if $places >= 0;
-    $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) )
-      if $places < 0;
+    if ($places >= 0) {
+        $amount = Math::BigFloat->new($amount)->ffround( -$places );
+    } 
+    else {
+        $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) );
+    } 
 
     return $amount;
 }

Modified: trunk/t/02-number-handling.t
===================================================================
--- trunk/t/02-number-handling.t	2007-05-16 02:53:40 UTC (rev 1200)
+++ trunk/t/02-number-handling.t	2007-05-16 23:22:22 UTC (rev 1201)
@@ -156,11 +156,38 @@
 is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 
 	'amount' => '1.00', 'precision' => 2, 'neg_format' => 'x'), '1.00',
 	"lsmb: 1.00 with dash 'x'");
+
+# Triggers the $amount .= "\.$dec" if ($dec ne ""); check to false
 is($form->format_amount({'numberformat' => '1000.00'} , '1.00'), '1',
-	"form: 1.00 with no precision or dash");
+	"form: 1.00 with no precision or dash (1000.00)");
 is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 
 	'amount' => '1.00'), '1',
-	"lsmb: 1.00 with no precision or dash");
+	"lsmb: 1.00 with no precision or dash (1000.00)");
+is($form->format_amount({'numberformat' => '1,000.00'} , '1.00'), '1',
+	"form: 1.00 with no precision or dash (1,000.00)");
+is($lsmb->format_amount('user' => {'numberformat' => '1,000.00'}, 
+	'amount' => '1.00'), '1',
+	"lsmb: 1.00 with no precision or dash (1,000.00)");
+is($form->format_amount({'numberformat' => '1 000.00'} , '1.00'), '1',
+	"form: 1.00 with no precision or dash (1 000.00)");
+is($lsmb->format_amount('user' => {'numberformat' => '1 000.00'}, 
+	'amount' => '1.00'), '1',
+	"lsmb: 1.00 with no precision or dash (1 000.00)");
+is($form->format_amount({'numberformat' => '1\'000.00'} , '1.00'), '1',
+	"form: 1.00 with no precision or dash (1'000.00)");
+is($lsmb->format_amount('user' => {'numberformat' => '1\'000.00'}, 
+	'amount' => '1.00'), '1',
+	"lsmb: 1.00 with no precision or dash (1'000.00)");
+is($form->format_amount({'numberformat' => '1.000,00'} , '1,00'), '1',
+	"form: 1,00 with no precision or dash (1.000,00)");
+is($lsmb->format_amount('user' => {'numberformat' => '1.000,00'}, 
+	'amount' => '1,00'), '1',
+	"lsmb: 1,00 with no precision or dash (1.000,00)");
+is($form->format_amount({'numberformat' => '1000,00'} , '1,00'), '1',
+	"form: 1,00 with no precision or dash (1000,00)");
+is($lsmb->format_amount('user' => {'numberformat' => '1000,00'}, 
+	'amount' => '1,00'), '1',
+	"lsmb: 1,00 with no precision or dash (1000,00)");
 is($form->format_amount({'numberformat' => '1000.00'} , '1.50'), '1.5',
 	"form: 1.50 with no precision or dash");
 is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 

Modified: trunk/t/11-ledgersmb.t
===================================================================
--- trunk/t/11-ledgersmb.t	2007-05-16 02:53:40 UTC (rev 1200)
+++ trunk/t/11-ledgersmb.t	2007-05-16 23:22:22 UTC (rev 1201)
@@ -249,3 +249,28 @@
 is($lsmb->{pear}, 2, 'merge: No key, added pear');
 is($lsmb->{peach}, 3, 'merge: No key, added peach');
 like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: No key, left existing key');
+
+$lsmb = new LedgerSMB;
+$lsmb->merge({'apple' => 1, 'pear' => 2, 'peach' => 3}, 'index' => 1);
+is($lsmb->{apple_1}, 1, 'merge: Index 1, added apple as apple_1');
+is($lsmb->{pear_1}, 2, 'merge: Index 1, added pear as pear_1');
+is($lsmb->{peach_1}, 3, 'merge: Index 1, added peach as peach_1');
+like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: Index 1, left existing key');
+
+# $lsmb->is_allowed_role checks
+$lsmb = new LedgerSMB;
+$lsmb->{_roles} = ('apple', 'pear');
+is($lsmb->is_allowed_role('allowed_roles' => ['pear']), 1, 
+	'is_allowed_role: allowed role');
+
+TODO: {
+	local $TODO = 'role system unimplemented';
+	$lsmb->{_roles} = ['apple', 'pear'];
+	is($lsmb->is_allowed_role('allowed_roles' => ['peach']), 0, 
+		'is_allowed_role: disallowed role');
+	is($lsmb->is_allowed_role('allowed_roles' => []), 0, 
+		'is_allowed_role: no allowable roles');
+	delete $lsmb->{_roles};
+	is($lsmb->is_allowed_role('allowed_roles' => ['apple']), 0, 
+		'is_allowed_role: no roles for user');
+}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.