示例#1
0
        public void TestExponentiate()
        {
            Assert.True(Math_.IsIntegerPowerOfTen(+0));
            Assert.True(Math_.IsIntegerPowerOfTen(-0));
            Assert.True(Math_.IsIntegerPowerOfTen(-1));
            Assert.True(Math_.IsIntegerPowerOfTen(+4));
            Assert.True(Math_.IsIntegerPowerOfTen(+20));
            Assert.True(Math_.IsIntegerPowerOfTen(-40));
            Assert.True(Math_.IsIntegerPowerOfTen(+90000000000000L));
            Assert.True(Math_.IsIntegerPowerOfTen(-90000000000000L));

            Assert.False(Math_.IsIntegerPowerOfTen(+21));
            Assert.False(Math_.IsIntegerPowerOfTen(-42));
            Assert.False(Math_.IsIntegerPowerOfTen(+90000000000001L));
            Assert.False(Math_.IsIntegerPowerOfTen(-90000000000002L));

            Assert.Equal(new long[] { 80, 100, 20000, 400000, 7000000, 10000000 }, Math_.Exponentiate(17420180));
            Assert.Equal(new long[] { 200000 }, Math_.Exponentiate(200000));
            Assert.Equal(new long[] { -400 }, Math_.Exponentiate(-400));

            Assert.Equal(new long[] { 0xa0, 0xf00, 0x1000 }, Math_.Exponentiate(0x1fa0, 16));
            Assert.Equal(new long[] { 0b10, 0b1000, 0b10000, 0b1000000 }, Math_.Exponentiate(0x5a, 2));