Beispiel #1
0
 public void ReserveArray_MustReverseTheArray_AsExpected()
 {
     CollectionAssert.AreEqual(
         expected: new List <char> {
         '0', '0', '1', '1', '0', '0', '0', '0'
     },
         actual: BitService.ReverseBitArray(new List <char> {
         '0', '0', '0', '0', '1', '1', '0', '0'
     }).ToList(),
         message: "The result is not the expected");
 }
Beispiel #2
0
        public IEnumerable <int> Count(int input)
        {
            try
            {
                _bitService.ValidateInput(input);

                var arrayOfBits = _bitService.ConvertToBitArray(input);

                // IN CASE OF NEED TO GET THE OCCURRENCES OF '0' it's possible
                var bitOccurrences = _bitService.GetBitOccurrences(arrayOfBits, '1');

                var reversedArrayOfBits = _bitService.ReverseBitArray(arrayOfBits);

                // IN CASE OF NEED TO GET THE POSITIONS OF '0' it's possible
                var bitPositions = _bitService.GetBitPositions(reversedArrayOfBits, '1');

                return(_bitService.GetCountingBitsOutput(bitOccurrences, bitPositions));
            }
            catch (Exception ex)
            {
                _loggerService.Error("Problem on Counting Bits for '${input}'", ex);
                throw ex;
            }
        }