annotate tests/mini/bitops.d @ 341:1bb99290e03a trunk

[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author lindquist
date Sun, 13 Jul 2008 02:51:19 +0200
parents test/bitops.d@d9d5d59873d8
children
rev   line source
lindquist@270 1
lindquist@270 2 extern(C) int printf(char*, ...);
lindquist@270 3
lindquist@1 4 void main()
lindquist@1 5 {
lindquist@1 6 printf("Bitwise operations test\n");
lindquist@1 7 { ushort a = 0xFFF0;
lindquist@1 8 ushort b = 0x0FFF;
lindquist@1 9 assert((a&b) == 0x0FF0);
lindquist@1 10 assert((a|b) == 0xFFFF);
lindquist@1 11 assert((a^b) == 0xF00F);
lindquist@1 12 }
lindquist@1 13 { ubyte a = 0xFF;
lindquist@1 14 ulong b = 0xFFFF_FFFF_FFFF_FFF0;
lindquist@1 15 assert((a&b) == 0xF0);
lindquist@1 16 }
lindquist@1 17 { ushort s = 0xFF;
lindquist@1 18 assert((s<<1) == s*2);
lindquist@1 19 assert((s>>>1) == s/2);
lindquist@1 20 }
lindquist@1 21 { int s = -10;
lindquist@1 22 assert((s>>1) == -5);
lindquist@1 23 assert((s>>>1) != -5);
lindquist@1 24 }
lindquist@86 25
lindquist@1 26 { ushort a = 0xFFF0;
lindquist@1 27 ushort b = 0x0FFF;
lindquist@1 28 auto t = a;
lindquist@1 29 t &= b;
lindquist@1 30 assert(t == 0x0FF0);
lindquist@1 31 t = a;
lindquist@1 32 t |= b;
lindquist@1 33 assert(t == 0xFFFF);
lindquist@1 34 t = a;
lindquist@1 35 t ^= b;
lindquist@1 36 assert(t == 0xF00F);
lindquist@1 37 }
lindquist@1 38 { ubyte a = 0xFF;
lindquist@1 39 ulong b = 0xFFFF_FFFF_FFFF_FFF0;
lindquist@1 40 a &= b;
lindquist@1 41 assert(a == 0xF0);
lindquist@1 42 }
lindquist@1 43 { ushort s = 0xFF;
lindquist@1 44 auto t = s;
lindquist@1 45 t <<= 1;
lindquist@1 46 assert(t == (s*2));
lindquist@1 47 t = s;
lindquist@1 48 t >>>= 1;
lindquist@1 49 assert(t == s/2);
lindquist@1 50 }
lindquist@1 51 { int s = -10;
lindquist@1 52 auto t = s;
lindquist@1 53 t >>= 1;
lindquist@1 54 assert(t == -5);
lindquist@1 55 t = s;
lindquist@1 56 t >>>= 1;
lindquist@1 57 assert(t != -5);
lindquist@1 58 }
lindquist@1 59 { struct S
lindquist@1 60 {
lindquist@1 61 uint i;
lindquist@1 62 ulong l;
lindquist@1 63 };
lindquist@1 64 S s = S(1,4);
lindquist@1 65 auto a = s.i | s.l;
lindquist@1 66 assert(a == 5);
lindquist@1 67 s.i = 0xFFFF_00FF;
lindquist@1 68 s.l = 0xFFFF_FFFF_0000_FF00;
lindquist@1 69 s.l ^= s.i;
lindquist@1 70 assert(s.l == ulong.max);
lindquist@1 71 s.i = 0x__FFFF_FF00;
lindquist@1 72 s.l = 0xFF00FF_FF00;
lindquist@1 73 s.i &= s.l;
lindquist@1 74 assert(s.i == 0x00FF_FF00);
lindquist@1 75 }
lindquist@86 76
lindquist@1 77 printf(" SUCCESS\n");
lindquist@1 78 }