コード例 #1
0
ファイル: NumberUtilTest.cs プロジェクト: kollare/Arconic
        public void ConvertNibbleToBitarrayTest()
        {
            var ba = NumberUtil.ConvertNibbleToBitarray(0);             //0000

            Assert.IsFalse(ba[0]); Assert.IsFalse(ba[1]); Assert.IsFalse(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(1);             //0001
            Assert.IsFalse(ba[0]); Assert.IsFalse(ba[1]); Assert.IsFalse(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(2);             //0010
            Assert.IsFalse(ba[0]); Assert.IsFalse(ba[1]); Assert.IsTrue(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(3);             //0011
            Assert.IsFalse(ba[0]); Assert.IsFalse(ba[1]); Assert.IsTrue(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(4);             //0100
            Assert.IsFalse(ba[0]); Assert.IsTrue(ba[1]); Assert.IsFalse(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(5);             //0101
            Assert.IsFalse(ba[0]); Assert.IsTrue(ba[1]); Assert.IsFalse(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(6);             //0110
            Assert.IsFalse(ba[0]); Assert.IsTrue(ba[1]); Assert.IsTrue(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(7);             //0111
            Assert.IsFalse(ba[0]); Assert.IsTrue(ba[1]); Assert.IsTrue(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(8);             //1000
            Assert.IsTrue(ba[0]); Assert.IsFalse(ba[1]); Assert.IsFalse(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(9);             //1001
            Assert.IsTrue(ba[0]); Assert.IsFalse(ba[1]); Assert.IsFalse(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(10);             //1010
            Assert.IsTrue(ba[0]); Assert.IsFalse(ba[1]); Assert.IsTrue(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(11);             //1011
            Assert.IsTrue(ba[0]); Assert.IsFalse(ba[1]); Assert.IsTrue(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(12);             //1100
            Assert.IsTrue(ba[0]); Assert.IsTrue(ba[1]); Assert.IsFalse(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(13);             //1101
            Assert.IsTrue(ba[0]); Assert.IsTrue(ba[1]); Assert.IsFalse(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(14);             //1110
            Assert.IsTrue(ba[0]); Assert.IsTrue(ba[1]); Assert.IsTrue(ba[2]); Assert.IsFalse(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(15);             //1111
            Assert.IsTrue(ba[0]); Assert.IsTrue(ba[1]); Assert.IsTrue(ba[2]); Assert.IsTrue(ba[3]);

            ba = NumberUtil.ConvertNibbleToBitarray(16);             //0001 0000 every input is ANDed with 0xF
            Assert.IsFalse(ba[0]); Assert.IsFalse(ba[1]); Assert.IsFalse(ba[2]); Assert.IsFalse(ba[3]);
        }