diff --git a/DigitSequence/DigitEnumerator.cs b/DigitSequence/DigitEnumerator.cs index e981a8a..6e7f03e 100644 --- a/DigitSequence/DigitEnumerator.cs +++ b/DigitSequence/DigitEnumerator.cs @@ -4,31 +4,61 @@ namespace DigitSequence; public sealed class DigitEnumerator : IEnumerator { - // TODO - //private readonly int _number; + private int _divisor; + private bool _started; + private readonly int _number; + /// + /// The constructor for + /// + /// The number public DigitEnumerator(int number) { - // TODO + _number = Math.Abs(number); } + /// + /// Moves to the next position + /// Default is invalid + /// + /// True, if the move was successful, false otherwise public bool MoveNext() { - // TODO - return false; + if (!_started) + { + _started = true; + _divisor = (int)Math.Pow(10, (int)Math.Log10(_number)); + return _divisor >= 0; + } + + _divisor /= 10; + return _divisor > 0; } + /// + /// Resets the current position + /// public void Reset() { - // TODO + _started = false; + _divisor = 0; } - public int Current => -1; // TODO + /// + /// Value of the current position + /// + public int Current => _divisor > 0 ? (_number / _divisor) % 10 : 0; - object IEnumerator.Current => null!; // TODO + /// + /// IEnumerator type for + /// + object IEnumerator.Current => Current; + /// + /// Disposes resources + /// public void Dispose() { - // TODO ? + // TODON'T! it doesn't seem that there is anything that has the need to be disposed } } diff --git a/DigitSequence/Digits.cs b/DigitSequence/Digits.cs index c5e0a26..666b1a9 100644 --- a/DigitSequence/Digits.cs +++ b/DigitSequence/Digits.cs @@ -4,18 +4,44 @@ namespace DigitSequence; public sealed class Digits(int number) : IEnumerable, IComparable { - // TODO - //private readonly int _number; + private readonly int _number = Math.Abs(number); + /// + /// Compares to another digit + /// + /// The other digit + /// The default compared value public int CompareTo(Digits? other) { - // TODO - return -1; + if (other == null) + { + return 1; + } + + if (ReferenceEquals(this, other)) + { + return 0; + } + + return _number.CompareTo(other._number); } - public IEnumerator GetEnumerator() => null!; // TODO + /// + /// Gets the enumerator of type + /// + /// The of type + public IEnumerator GetEnumerator() => new DigitEnumerator(number); - IEnumerator IEnumerable.GetEnumerator() => null!; // TODO + /// + /// Gets the enumerator as an of type + /// + /// The + // I'm gonna be a wikipedia author with that many references xD + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public override string ToString() => null!; // TODO -} + /// + /// The overriden Method to get the representation of the current object + /// + /// The values of in a format + public override string ToString() => _number.ToString(); +} \ No newline at end of file