[gcalctool] Test basic mp functions



commit 447d9b7a23eea83d1418346396bc4debc529cda7
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon Mar 1 10:40:14 2010 +1100

    Test basic mp functions

 src/unittest.c |  119 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 77 insertions(+), 42 deletions(-)
---
diff --git a/src/unittest.c b/src/unittest.c
index f872069..7bd0146 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -493,60 +493,95 @@ try(const char *string, bool result, bool expected)
 
 
 static void
-test_comparison()
+test_mp()
 {
     MPNumber zero, one, minus_one;
   
     mp_set_from_integer(0, &zero);
     mp_set_from_integer(1, &one);
     mp_set_from_integer(-1, &minus_one);
-
-    try("0 > -1", mp_is_greater_than (&zero, &minus_one), true);  
-    try("0 > 0", mp_is_greater_than (&zero, &zero), false);
-    try("0 > 1", mp_is_greater_than (&zero, &one), false);
-    try("0 >= -1", mp_is_greater_equal (&zero, &minus_one), true);  
-    try("0 >= 0", mp_is_greater_equal (&zero, &zero), true);
-    try("0 >= 1", mp_is_greater_equal (&zero, &one), false);
-    try("0 < -1", mp_is_less_than (&zero, &minus_one), false);  
-    try("0 < 0", mp_is_less_than (&zero, &zero), false);
-    try("0 < 1", mp_is_less_than (&zero, &one), true);
-    try("0 <= -1", mp_is_less_equal (&zero, &minus_one), false);  
-    try("0 <= 0", mp_is_less_equal (&zero, &zero), true);
-    try("0 <= 1", mp_is_less_equal (&zero, &one), true);
-
-    try("1 > -1", mp_is_greater_than (&one, &minus_one), true);  
-    try("1 > 0", mp_is_greater_than (&one, &zero), true);
-    try("1 > 1", mp_is_greater_than (&one, &one), false);
-    try("1 >= -1", mp_is_greater_equal (&one, &minus_one), true);
-    try("1 >= 0", mp_is_greater_equal (&one, &zero), true);
-    try("1 >= 1", mp_is_greater_equal (&one, &one), true);
-    try("1 < -1", mp_is_less_than (&one, &minus_one), false);  
-    try("1 < 0", mp_is_less_than (&one, &zero), false);
-    try("1 < 1", mp_is_less_than (&one, &one), false);
-    try("1 <= -1", mp_is_less_equal (&one, &minus_one), false);  
-    try("1 <= 0", mp_is_less_equal (&one, &zero), false);
-    try("1 <= 1", mp_is_less_equal (&one, &one), true);
-
-    try("-1 > -1", mp_is_greater_than (&minus_one, &minus_one), false);  
-    try("-1 > 0", mp_is_greater_than (&minus_one, &zero), false);
-    try("-1 > 1", mp_is_greater_than (&minus_one, &one), false);
-    try("-1 >= -1", mp_is_greater_equal (&minus_one, &minus_one), true);
-    try("-1 >= 0", mp_is_greater_equal (&minus_one, &zero), false);
-    try("-1 >= 1", mp_is_greater_equal (&minus_one, &one), false);
-    try("-1 < -1", mp_is_less_than (&minus_one, &minus_one), false);  
-    try("-1 < 0", mp_is_less_than (&minus_one, &zero), true);
-    try("-1 < 1", mp_is_less_than (&minus_one, &one), true);
-    try("-1 <= -1", mp_is_less_equal (&minus_one, &minus_one), true);  
-    try("-1 <= 0", mp_is_less_equal (&minus_one, &zero), true);
-    try("-1 <= 1", mp_is_less_equal (&minus_one, &one), true);
+  
+    try("mp_is_zero(-1)", mp_is_zero(&minus_one), false);
+    try("mp_is_zero(0)", mp_is_zero(&zero), true);
+    try("mp_is_zero(1)", mp_is_zero(&one), false);
+
+    try("mp_is_negative(-1)", mp_is_negative(&minus_one), true);
+    try("mp_is_negative(0)", mp_is_negative(&zero), false);
+    try("mp_is_negative(1)", mp_is_negative(&one), false);
+
+    try("mp_is_integer(-1)", mp_is_integer(&minus_one), true);
+    try("mp_is_integer(0)", mp_is_integer(&zero), true);
+    try("mp_is_integer(1)", mp_is_integer(&one), true);
+
+    try("mp_is_positive_integer(-1)", mp_is_positive_integer(&minus_one), false);
+    try("mp_is_positive_integer(0)", mp_is_positive_integer(&zero), true);
+    try("mp_is_positive_integer(1)", mp_is_positive_integer(&one), true);
+
+    try("mp_is_natural(-1)", mp_is_natural(&minus_one), false);
+    try("mp_is_natural(0)", mp_is_natural(&zero), false);
+    try("mp_is_natural(1)", mp_is_natural(&one), true);
+
+    try("mp_is_complex(-1)", mp_is_complex(&minus_one), false);
+    try("mp_is_complex(0)", mp_is_complex(&zero), false);
+    try("mp_is_complex(1)", mp_is_complex(&one), false);
+
+    try("mp_is_equal(-1, -1)", mp_is_equal(&minus_one, &minus_one), true);
+    try("mp_is_equal(-1, 0)", mp_is_equal(&minus_one, &zero), false);
+    try("mp_is_equal(-1, 1)", mp_is_equal(&minus_one, &one), false);
+    try("mp_is_equal(0, -1)", mp_is_equal(&zero, &minus_one), false);
+    try("mp_is_equal(0, 0)", mp_is_equal(&zero, &zero), true);
+    try("mp_is_equal(0, 1)", mp_is_equal(&zero, &one), false);
+    try("mp_is_equal(1, -1)", mp_is_equal(&one, &minus_one), false);
+    try("mp_is_equal(1, 0)", mp_is_equal(&one, &zero), false);
+    try("mp_is_equal(1, 1)", mp_is_equal(&one, &one), true);
+
+    try("mp_is_greater_than(0, -1)", mp_is_greater_than (&zero, &minus_one), true);  
+    try("mp_is_greater_than(0, 0)", mp_is_greater_than (&zero, &zero), false);
+    try("mp_is_greater_than(0, 1)", mp_is_greater_than (&zero, &one), false);
+    try("mp_is_greater_than(1, -1)", mp_is_greater_than (&one, &minus_one), true);  
+    try("mp_is_greater_than(1, 0)", mp_is_greater_than (&one, &zero), true);
+    try("mp_is_greater_than(1, 1)", mp_is_greater_than (&one, &one), false);
+    try("mp_is_greater_than(-1, -1)", mp_is_greater_than (&minus_one, &minus_one), false);  
+    try("mp_is_greater_than(-1, 0)", mp_is_greater_than (&minus_one, &zero), false);
+    try("mp_is_greater_than(-1, 1)", mp_is_greater_than (&minus_one, &one), false);
+
+    try("mp_is_greater_equal(0, -1)", mp_is_greater_equal (&zero, &minus_one), true);  
+    try("mp_is_greater_equal(0, 0)", mp_is_greater_equal (&zero, &zero), true);
+    try("mp_is_greater_equal(0, 1)", mp_is_greater_equal (&zero, &one), false);
+    try("mp_is_greater_equal(1, -1)", mp_is_greater_equal (&one, &minus_one), true);
+    try("mp_is_greater_equal(1, 0)", mp_is_greater_equal (&one, &zero), true);
+    try("mp_is_greater_equal(1, 1)", mp_is_greater_equal (&one, &one), true);
+    try("mp_is_greater_equal(-1, -1)", mp_is_greater_equal (&minus_one, &minus_one), true);
+    try("mp_is_greater_equal(-1, 0)", mp_is_greater_equal (&minus_one, &zero), false);
+    try("mp_is_greater_equal(-1, 1)", mp_is_greater_equal (&minus_one, &one), false);
+
+    try("mp_is_less_than(0, -1)", mp_is_less_than (&zero, &minus_one), false);  
+    try("mp_is_less_than(0, 0)", mp_is_less_than (&zero, &zero), false);
+    try("mp_is_less_than(0, 1)", mp_is_less_than (&zero, &one), true);
+    try("mp_is_less_than(1, -1)", mp_is_less_than (&one, &minus_one), false);  
+    try("mp_is_less_than(1, 0)", mp_is_less_than (&one, &zero), false);
+    try("mp_is_less_than(1, 1)", mp_is_less_than (&one, &one), false);
+    try("mp_is_less_than(-1, -1)", mp_is_less_than (&minus_one, &minus_one), false);  
+    try("mp_is_less_than(-1, 0)", mp_is_less_than (&minus_one, &zero), true);
+    try("mp_is_less_than(-1, 1)", mp_is_less_than (&minus_one, &one), true);
+
+    try("mp_is_less_equal(0, -1)", mp_is_less_equal (&zero, &minus_one), false);  
+    try("mp_is_less_equal(0, 0)", mp_is_less_equal (&zero, &zero), true);
+    try("mp_is_less_equal(0, 1)", mp_is_less_equal (&zero, &one), true);
+    try("mp_is_less_equal(1, -1)", mp_is_less_equal (&one, &minus_one), false);  
+    try("mp_is_less_equal(1, 0)", mp_is_less_equal (&one, &zero), false);
+    try("mp_is_less_equal(1, 1)", mp_is_less_equal (&one, &one), true);
+    try("mp_is_less_equal(-1, -1)", mp_is_less_equal (&minus_one, &minus_one), true);  
+    try("mp_is_less_equal(-1, 0)", mp_is_less_equal (&minus_one, &zero), true);
+    try("mp_is_less_equal(-1, 1)", mp_is_less_equal (&minus_one, &one), true);
 }
 
 
 void
 unittest()
 {
-    test_parser();
-    test_comparison();
+    test_mp();
     test_numbers();
+    test_parser();
     exit(fails > 0 ? 1 : 0);
 }



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