[gcalctool/vala] Test and or xor shift
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool/vala] Test and or xor shift
- Date: Fri, 12 Oct 2012 20:51:10 +0000 (UTC)
commit 4a597dce9e06690735d9eba06cac03aa42d2eef9
Author: Robert Ancell <robert ancell canonical com>
Date: Sat Oct 13 09:51:05 2012 +1300
Test and or xor shift
src/test-number.vala | 86 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 82 insertions(+), 4 deletions(-)
---
diff --git a/src/test-number.vala b/src/test-number.vala
index 5b73dd9..e09ffcf 100644
--- a/src/test-number.vala
+++ b/src/test-number.vala
@@ -922,6 +922,84 @@ static void test_cos ()
pass ();
}
+private void test_and ()
+{
+ for (var a = 0; a < 10; a++)
+ {
+ for (var b = 0; b < 10; b++)
+ {
+ var z = (new Number.integer (a)).and (new Number.integer (b));
+ var expected = a & b;
+ if (z.to_integer () != expected)
+ {
+ fail ("(%d).and (%d) -> %lli, expected %d".printf (a, b, z.to_integer (), expected));
+ return;
+ }
+ }
+ }
+
+ pass ();
+}
+
+private void test_or ()
+{
+ for (var a = 0; a < 10; a++)
+ {
+ for (var b = 0; b < 10; b++)
+ {
+ var z = (new Number.integer (a)).or (new Number.integer (b));
+ var expected = a | b;
+ if (z.to_integer () != expected)
+ {
+ fail ("(%d).or (%d) -> %lli, expected %d".printf (a, b, z.to_integer (), expected));
+ return;
+ }
+ }
+ }
+
+ pass ();
+}
+
+private void test_xor ()
+{
+ for (var a = 0; a < 10; a++)
+ {
+ for (var b = 0; b < 10; b++)
+ {
+ var z = (new Number.integer (a)).xor (new Number.integer (b));
+ var expected = a ^ b;
+ if (z.to_integer () != expected)
+ {
+ fail ("(%d).xor (%d) -> %lli, expected %d".printf (a, b, z.to_integer (), expected));
+ return;
+ }
+ }
+ }
+
+ pass ();
+}
+
+private void test_shift ()
+{
+ for (var a = 0; a < 10; a++)
+ {
+ for (var b = -10; b < 10; b++)
+ {
+ var z = (new Number.integer (a)).shift (b);
+ var expected = a << b;
+ if (b < 0)
+ expected = a >> -b;
+ if (z.to_integer () != expected)
+ {
+ fail ("(%d).shift (%d) -> %lli, expected %d".printf (a, b, z.to_integer (), expected));
+ return;
+ }
+ }
+ }
+
+ pass ();
+}
+
static int main (string[] args)
{
Intl.setlocale (LocaleCategory.ALL, "C");
@@ -986,12 +1064,12 @@ static int main (string[] args)
//test_asinh ();
//test_acosh ();
//test_atanh ();
- //test_and ();
- //test_or ();
- //test_xor ();
+ test_and ();
+ test_or ();
+ test_xor ();
//test_not ();
//test_mask ();
- //test_shift ();
+ test_shift ();
//test_ones_complement ();
//test_twos_complement ();
//test_factorize ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]