Exemplo n.º 1
0
 public void TestHasOppositeSigns()
 {
     Assertions.Assert(HasOppositeSigns(10, -10));
     Assertions.Assert(HasOppositeSigns(-9918, 2147));
     Assertions.Assert(!HasOppositeSigns(23, 27));
     Assertions.Assert(!HasOppositeSigns(-621, -486));
 }
Exemplo n.º 2
0
 public void TestIsEven()
 {
     Assertions.Assert(IsEven(4));
     Assertions.Assert(IsEven(60));
     Assertions.Assert(!IsEven(3));
     Assertions.Assert(!IsEven(51));
 }
Exemplo n.º 3
0
 public static void Assert(bool test, string location, Func <string> message)
 {
     if (CanAssert)
     {
         Assertions.Assert(test, message);
     }
     else
     {
         Assertions.Assert(test, $"at {location}: {message}");
     }
 }
Exemplo n.º 4
0
        public void TestIsPowerOfTwo()
        {
            Assertions.Assert(IsPowerOfTwo(1));
            Assertions.Assert(IsPowerOfTwo(4));
            Assertions.Assert(IsPowerOfTwo(16));
            Assertions.Assert(IsPowerOfTwo(64));

            Assertions.Assert(!IsPowerOfTwo(63));
            Assertions.Assert(!IsPowerOfTwo(621));
            Assertions.Assert(!IsPowerOfTwo(513));
            Assertions.Assert(!IsPowerOfTwo(0));
        }
Exemplo n.º 5
0
        public void TestToggleNthBit()
        {
            var testNumber = 0;

            Assertions.Assert(!IsNthBitSet(testNumber, 2));

            testNumber = ToggleNthBit(testNumber, 2);
            Assertions.Assert(IsNthBitSet(testNumber, 2));

            testNumber = ToggleNthBit(testNumber, 2);
            Assertions.Assert(!IsNthBitSet(testNumber, 2));
        }
Exemplo n.º 6
0
        public void TestIsBitSet()
        {
            var testNumber = 0b10001110;

            Assertions.Assert(!IsNthBitSet(testNumber, 0));
            Assertions.Assert(IsNthBitSet(testNumber, 1));
            Assertions.Assert(IsNthBitSet(testNumber, 2));
            Assertions.Assert(IsNthBitSet(testNumber, 3));
            Assertions.Assert(!IsNthBitSet(testNumber, 4));
            Assertions.Assert(!IsNthBitSet(testNumber, 5));
            Assertions.Assert(!IsNthBitSet(testNumber, 6));
            Assertions.Assert(IsNthBitSet(testNumber, 7));
        }
Exemplo n.º 7
0
 public void TestOptimalSolution()
 {
     Assertions.Assert(OptimalPairSum(TestArr, InThere));
     Assertions.Assert(!OptimalPairSum(TestArr, NotThere));
 }
Exemplo n.º 8
0
 public void TestNaiveSolution()
 {
     Assertions.Assert(NaivePairSum(TestArr, InThere));
     Assertions.Assert(!NaivePairSum(TestArr, NotThere));
 }
Exemplo n.º 9
0
 public static void Assert(bool condition, string message = null)
 {
     Assertions.Assert(condition, message);
 }