[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patch - tests in bitfcns
From: |
Robert T. Short |
Subject: |
patch - tests in bitfcns |
Date: |
Tue, 14 Jul 2009 10:32:16 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.22) Gecko/20090606 SeaMonkey/1.1.17 |
Attached is a patch that adds tests to src/bitfcns.cc.
Some notes.
MATLAB does not support the bit operations on signed types (int8, int16,
int32, int64) so the tests for those do not run in MATLAB.
The tests for the uint types all work in MATLAB. There are some
"xtests" for tests that pass in MATLAB but fail in octave. I assume
these are bugs.
Bob
# HG changeset patch
# User Robert T. Short <address@hidden>
# Date 1247591893 25200
# Node ID 6a27d951610059a571f9a19c5cec4647d8552555
# Parent 97c42a8caf7394e047fe2e80f9b34b44074e69b8
* bitfcns.cc: added tests
diff -r 97c42a8caf73 -r 6a27d9516100 src/ChangeLog
--- a/src/ChangeLog Tue Jun 02 16:57:22 2009 -0700
+++ b/src/ChangeLog Tue Jul 14 10:18:13 2009 -0700
@@ -1,3 +1,7 @@
+2009-07-14 Robert T. Short <address@hidden>
+
+ * bitfcns.cc: Added tests.
+
2009-07-09 John W. Eaton <address@hidden>
* data.cc (Fones, Fzeros, Ftrue, Ffalse): Update docstrings.
diff -r 97c42a8caf73 -r 6a27d9516100 src/bitfcns.cc
--- a/src/bitfcns.cc Tue Jun 02 16:57:22 2009 -0700
+++ b/src/bitfcns.cc Tue Jul 14 10:18:13 2009 -0700
@@ -272,6 +272,28 @@
BITOP (&, "bitand");
}
+/*
+%!assert(bitand(0:15,2),[0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2])
+%!assert(bitand(0:15,3),[0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3])
+%!assert(bitand(uint8(0:15),uint8(2)),uint8([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2]))
+%!assert(bitand(uint8(0:15),uint8(3)),uint8([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]))
+%!assert(bitand(uint16(0:15),uint16(2)),uint16([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2
2]))
+%!assert(bitand(uint16(0:15),uint16(3)),uint16([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2
3]))
+%!assert(bitand(uint32(0:15),uint32(2)),uint32([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2
2]))
+%!assert(bitand(uint32(0:15),uint32(3)),uint32([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2
3]))
+%!assert(bitand(uint64(0:15),uint64(2)),uint64([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2
2]))
+%!assert(bitand(uint64(0:15),uint64(3)),uint64([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2
3]))
+%% MATLAB does not define bitwise functions for int types.
+%!assert(bitand(int8(0:15),int8(2)),int8([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2]))
+%!assert(bitand(int8(0:15),int8(3)),int8([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]))
+%!assert(bitand(int16(0:15),int16(2)),int16([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2]))
+%!assert(bitand(int16(0:15),int16(3)),int16([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]))
+%!assert(bitand(int32(0:15),int32(2)),int32([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2]))
+%!assert(bitand(int32(0:15),int32(3)),int32([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]))
+%!assert(bitand(int64(0:15),int64(2)),int64([0 0 2 2 0 0 2 2 0 0 2 2 0 0 2 2]))
+%!assert(bitand(int64(0:15),int64(3)),int64([0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]))
+ */
+
DEFUN (bitor, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} bitor (@var{x}, @var{y})\n\
@@ -283,6 +305,28 @@
BITOP (|, "bitor");
}
+/*
+%!assert(bitor(0:15,2),[2 3 2 3 6 7 6 7 10 11 10 11 14 15 14 15])
+%!assert(bitor(0:15,3),[3 3 3 3 7 7 7 7 11 11 11 11 15 15 15 15])
+%!assert(bitor(uint8(0:15),uint8(2)),uint8([2 3 2 3 6 7 6 7 10 11 10 11 14 15
14 15]))
+%!assert(bitor(uint8(0:15),uint8(3)),uint8([3 3 3 3 7 7 7 7 11 11 11 11 15 15
15 15]))
+%!assert(bitor(uint16(0:15),uint16(2)),uint16([2 3 2 3 6 7 6 7 10 11 10 11 14
15 14 15]))
+%!assert(bitor(uint16(0:15),uint16(3)),uint16([3 3 3 3 7 7 7 7 11 11 11 11 15
15 15 15]))
+%!assert(bitor(uint32(0:15),uint32(2)),uint32([2 3 2 3 6 7 6 7 10 11 10 11 14
15 14 15]))
+%!assert(bitor(uint32(0:15),uint32(3)),uint32([3 3 3 3 7 7 7 7 11 11 11 11 15
15 15 15]))
+%!assert(bitor(uint64(0:15),uint64(2)),uint64([2 3 2 3 6 7 6 7 10 11 10 11 14
15 14 15]))
+%!assert(bitor(uint64(0:15),uint64(3)),uint64([3 3 3 3 7 7 7 7 11 11 11 11 15
15 15 15]))
+%% MATLAB does not define bitwise functions for int types.
+%!assert(bitor(int8(0:15),int8(2)),int8([2 3 2 3 6 7 6 7 10 11 10 11 14 15 14
15]))
+%!assert(bitor(int8(0:15),int8(3)),int8([3 3 3 3 7 7 7 7 11 11 11 11 15 15 15
15]))
+%!assert(bitor(int16(0:15),int16(2)),int16([2 3 2 3 6 7 6 7 10 11 10 11 14 15
14 15]))
+%!assert(bitor(int16(0:15),int16(3)),int16([3 3 3 3 7 7 7 7 11 11 11 11 15 15
15 15]))
+%!assert(bitor(int32(0:15),int32(2)),int32([2 3 2 3 6 7 6 7 10 11 10 11 14 15
14 15]))
+%!assert(bitor(int32(0:15),int32(3)),int32([3 3 3 3 7 7 7 7 11 11 11 11 15 15
15 15]))
+%!assert(bitor(int64(0:15),int64(2)),int64([2 3 2 3 6 7 6 7 10 11 10 11 14 15
14 15]))
+%!assert(bitor(int64(0:15),int64(3)),int64([3 3 3 3 7 7 7 7 11 11 11 11 15 15
15 15]))
+ */
+
DEFUN (bitxor, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} bitxor (@var{x}, @var{y})\n\
@@ -293,6 +337,31 @@
{
BITOP (^, "bitxor");
}
+/*
+%!assert(bitxor(0:15,2),[2 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13])
+%!assert(bitxor(0:15,3),[3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12])
+%!assert(bitxor(uint8(0:15),uint8(2)),uint8([2 3 0 1 6 7 4 5 10 11 8 9 14 15
12 13]))
+%!assert(bitxor(uint8(0:15),uint8(3)),uint8([3 2 1 0 7 6 5 4 11 10 9 8 15 14
13 12]))
+%!assert(bitxor(uint16(0:15),uint16(2)),uint16([2 3 0 1 6 7 4 5 10 11 8 9 14
15 12 13]))
+%!assert(bitxor(uint16(0:15),uint16(3)),uint16([3 2 1 0 7 6 5 4 11 10 9 8 15
14 13 12]))
+%!assert(bitxor(uint32(0:15),uint32(2)),uint32([2 3 0 1 6 7 4 5 10 11 8 9 14
15 12 13]))
+%!assert(bitxor(uint32(0:15),uint32(3)),uint32([3 2 1 0 7 6 5 4 11 10 9 8 15
14 13 12]))
+%!assert(bitxor(uint32(0:15),uint32(2)),uint32([2 3 0 1 6 7 4 5 10 11 8 9 14
15 12 13]))
+%!assert(bitxor(uint32(0:15),uint32(3)),uint32([3 2 1 0 7 6 5 4 11 10 9 8 15
14 13 12]))
+%!assert(bitxor(uint64(0:15),uint64(2)),uint64([2 3 0 1 6 7 4 5 10 11 8 9 14
15 12 13]))
+%!assert(bitxor(uint64(0:15),uint64(3)),uint64([3 2 1 0 7 6 5 4 11 10 9 8 15
14 13 12]))
+%% MATLAB does not define bitwise functions for int types.
+%!assert(bitxor(int8(0:15),int8(2)),int8([2 3 0 1 6 7 4 5 10 11 8 9 14 15 12
13]))
+%!assert(bitxor(int8(0:15),int8(3)),int8([3 2 1 0 7 6 5 4 11 10 9 8 15 14 13
12]))
+%!assert(bitxor(int16(0:15),int16(2)),int16([2 3 0 1 6 7 4 5 10 11 8 9 14 15
12 13]))
+%!assert(bitxor(int16(0:15),int16(3)),int16([3 2 1 0 7 6 5 4 11 10 9 8 15 14
13 12]))
+%!assert(bitxor(int32(0:15),int32(2)),int32([2 3 0 1 6 7 4 5 10 11 8 9 14 15
12 13]))
+%!assert(bitxor(int32(0:15),int32(3)),int32([3 2 1 0 7 6 5 4 11 10 9 8 15 14
13 12]))
+%!assert(bitxor(int32(0:15),int32(2)),int32([2 3 0 1 6 7 4 5 10 11 8 9 14 15
12 13]))
+%!assert(bitxor(int32(0:15),int32(3)),int32([3 2 1 0 7 6 5 4 11 10 9 8 15 14
13 12]))
+%!assert(bitxor(int64(0:15),int64(2)),int64([2 3 0 1 6 7 4 5 10 11 8 9 14 15
12 13]))
+%!assert(bitxor(int64(0:15),int64(3)),int64([3 2 1 0 7 6 5 4 11 10 9 8 15 14
13 12]))
+*/
static int64_t
bitshift (double a, int n, int64_t mask)
@@ -510,6 +579,47 @@
return retval;
}
+
+/*
+%!assert(bitshift(0:15,1),[0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30])
+%!assert(bitshift(0:15,-1),[0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7])
+%!assert(bitshift(0:15,1,3),[0 2 4 6 0 2 4 6 0 2 4 6 0 2 4 6])
+%!assert(bitshift(0:15,-1,3),[0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7])
+%!assert(bitshift(uint8(0:15),1),uint8([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(uint8(0:15),-1),uint8([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%% The xtests work in MATLAB but fail in octave
+%!xtest assert(bitshift(uint8(0:15),1),uint8(3),uint8([0 2 4 6 0 2 4 6 0 2 4 6
0 2 4 6]))
+%!assert(bitshift(uint8(0:15),-1,uint8(3)),uint8([0 0 1 1 2 2 3 3 4 4 5 5 6 6
7 7]))
+%!assert(bitshift(uint16(0:15),1),uint16([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(uint16(0:15),-1),uint16([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(uint16(0:15),1),uint16(3),uint16([0 2 4 6 0 2 4 6 0 2
4 6 0 2 4 6]))
+%!assert(bitshift(uint16(0:15),-1,uint16(3)),uint16([0 0 1 1 2 2 3 3 4 4 5 5 6
6 7 7]))
+%!assert(bitshift(uint32(0:15),1),uint32([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(uint32(0:15),-1),uint32([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(uint32(0:15),1),uint32(3),uint32([0 2 4 6 0 2 4 6 0 2
4 6 0 2 4 6]))
+%!assert(bitshift(uint32(0:15),-1,uint32(3)),uint32([0 0 1 1 2 2 3 3 4 4 5 5 6
6 7 7]))
+%!assert(bitshift(uint64(0:15),1),uint64([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(uint64(0:15),-1),uint64([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(uint64(0:15),1),uint64(3),uint64([0 2 4 6 0 2 4 6 0 2
4 6 0 2 4 6]))
+%!assert(bitshift(uint64(0:15),-1,uint64(3)),uint64([0 0 1 1 2 2 3 3 4 4 5 5 6
6 7 7]))
+%% MATLAB doesn't define bitwise operators for int types.
+%!assert(bitshift(int8(0:15),1),int8([0 2 4 6 8 10 12 14 16 18 20 22 24 26 28
30]))
+%!assert(bitshift(int8(0:15),-1),int8([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(int8(0:15),1),int8(3),int8([0 2 4 6 0 2 4 6 0 2 4 6 0
2 4 6]))
+%!assert(bitshift(int8(0:15),-1,int8(3)),int8([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7
7]))
+%!assert(bitshift(int16(0:15),1),int16([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(int16(0:15),-1),int16([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(int16(0:15),1),int16(3),int16([0 2 4 6 0 2 4 6 0 2 4 6
0 2 4 6]))
+%!assert(bitshift(int16(0:15),-1,int16(3)),int16([0 0 1 1 2 2 3 3 4 4 5 5 6 6
7 7]))
+%!assert(bitshift(int32(0:15),1),int32([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(int32(0:15),-1),int32([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(int32(0:15),1),int32(3),int32([0 2 4 6 0 2 4 6 0 2 4 6
0 2 4 6]))
+%!assert(bitshift(int32(0:15),-1,int32(3)),int32([0 0 1 1 2 2 3 3 4 4 5 5 6 6
7 7]))
+%!assert(bitshift(int64(0:15),1),int64([0 2 4 6 8 10 12 14 16 18 20 22 24 26
28 30]))
+%!assert(bitshift(int64(0:15),-1),int64([0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7]))
+%!xtest assert(bitshift(int64(0:15),1),int64(3),int64([0 2 4 6 0 2 4 6 0 2 4 6
0 2 4 6]))
+%!assert(bitshift(int64(0:15),-1,int64(3)),int64([0 0 1 1 2 2 3 3 4 4 5 5 6 6
7 7]))
+ */
DEFUN (bitmax, args, ,
"-*- texinfo -*-\n\
- patch - tests in bitfcns,
Robert T. Short <=
- patch - tests in bitfcns, John W. Eaton, 2009/07/15
- Re: patch - tests in bitfcns, Robert T. Short, 2009/07/15
- Re: patch - tests in bitfcns, John W. Eaton, 2009/07/15
- Re: patch - tests in bitfcns, John W. Eaton, 2009/07/15
- Re: patch - tests in bitfcns, Robert T. Short, 2009/07/15
- More on bitfcns, Robert T. Short, 2009/07/19
- Re: More on bitfcns, Jaroslav Hajek, 2009/07/20
- Re: patch - tests in bitfcns, John W. Eaton, 2009/07/15