[svn:parrot] r42966 - in trunk: runtime/parrot/library/Test t/library

coke at svn.parrot.org coke at svn.parrot.org
Wed Dec 9 22:01:50 UTC 2009


Author: coke
Date: Wed Dec  9 22:01:49 2009
New Revision: 42966
URL: https://trac.parrot.org/parrot/changeset/42966

Log:
Slight cleanup to Float-with precision is()
(Also: tests)

Modified:
   trunk/runtime/parrot/library/Test/More.pir
   trunk/t/library/test_more.t

Modified: trunk/runtime/parrot/library/Test/More.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/More.pir	Wed Dec  9 21:42:29 2009	(r42965)
+++ trunk/runtime/parrot/library/Test/More.pir	Wed Dec  9 22:01:49 2009	(r42966)
@@ -179,31 +179,28 @@
   done:
 .end
 
-.sub is :multi(PMC, Float)
-    .param pmc left
-    .param pmc right
-    .param pmc description :optional
-    .param int have_desc   :opt_flag
-    .param pmc precision   :optional
-    .param int have_prec   :opt_flag
+.sub is :multi(_, Float)
+    .param num    left
+    .param num    right
+    .param string description :optional
+    .param int    have_desc   :opt_flag
+    .param num    precision   :optional
+    .param int    have_prec   :opt_flag
 
     .local pmc test
     get_hll_global test, [ 'Test'; 'More' ], '_test'
 
-    .local num l, r
-    .local int pass
-    l    = left
-    r    = right
-    pass = iseq l, r
+    if have_prec goto check_precision
 
-    if     pass      goto report
-    unless have_prec goto report
+    .local int pass
+    pass = iseq left, right
+    goto report
 
-    .local num diff, prec_num
-    prec_num = precision
-    diff     = l - r
-    diff     = abs diff
-    pass     = isle diff, prec_num
+  check_precision:
+    .local num diff
+    diff = left - right
+    diff = abs diff
+    pass = isle diff, precision
 
   report:
     test.'ok'( pass, description )
@@ -216,7 +213,7 @@
     l_string    = left
     r_string    = right
 
-    diagnostic = _make_diagnostic( l_string, r_string )
+    diagnostic = _make_diagnostic( left, right )
     test.'diag'( diagnostic )
   done:
 .end

Modified: trunk/t/library/test_more.t
==============================================================================
--- trunk/t/library/test_more.t	Wed Dec  9 21:42:29 2009	(r42965)
+++ trunk/t/library/test_more.t	Wed Dec  9 22:01:49 2009	(r42966)
@@ -22,7 +22,7 @@
     exports = split " ", "plan test_out test_diag test_fail test_pass test_test"
     test_namespace.'export_to'(curr_namespace, exports)
 
-    plan( 102 )
+    plan( 104 )
 
     test_skip()
     test_todo()
@@ -278,6 +278,16 @@
     test_diag( 'Want: 888.8' )
     test_test( 'failing test is() for floats with description')
 
+    test_fail( 'comparing two floats with precision, failure' )
+    is( 777.1, 888.8, 'comparing two floats with precision, failure', 1e-6)
+    test_diag( 'Have: 777.1' )
+    test_diag( 'Want: 888.8' )
+    test_test( 'failing test is() for floats with precision')
+
+    test_pass( 'comparing two floats with precision, success' )
+    is( 666.222, 666.223, 'comparing two floats with precision, success', 1e-2)
+    test_test( 'passing test is() for floats with precision')
+
     test_pass()
     is( 'bob', 'bob' )
     test_test( 'passing test is() for strings')


More information about the parrot-commits mailing list