Skip to content

Commit

Permalink
Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed Jul 21, 2019
1 parent 7cedd57 commit 3351b32
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Range.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Platform.Ranges
{
Expand Down Expand Up @@ -26,13 +27,15 @@ public struct Range<T>
public readonly T Maximum;

public Range(T minimumAndMaximum)
: this(minimumAndMaximum, minimumAndMaximum)
{
Minimum = minimumAndMaximum;
Maximum = minimumAndMaximum;
}

public Range(T minimum, T maximum)
{
if (_comparer.Compare(maximum, minimum) < 0)
throw new ArgumentException("Maximum should be greater or equal to minimum.", nameof(maximum));

Minimum = minimum;
Maximum = maximum;
}
Expand All @@ -44,12 +47,6 @@ public Range(T minimum, T maximum)
/// <returns>String representation of the Range. Строковое представление диапазона.</returns>
public override string ToString() => $"[{Minimum}, {Maximum}]";

/// <summary>
/// Determines if the range is valid. Определяет, является ли диапазон корректным.
/// </summary>
/// <returns>True if range is valid, else false. True, если диапазон корректный, иначе false.</returns>
public bool IsValid() => _comparer.Compare(Minimum, Maximum) <= 0;

/// <summary>
/// Determines if the provided value is inside the range.
/// Определяет, находится ли указанное значение внутри диапазона.
Expand All @@ -72,6 +69,6 @@ public Range(T minimum, T maximum)
/// </summary>
/// <param name="range">The child range to test. Дочерний диапазон для проверки.</param>
/// <returns>True if range is inside, else false. True, если диапазон находится внутри, иначе false.</returns>
public bool ContainsRange(Range<T> range) => IsValid() && range.IsValid() && ContainsValue(range.Minimum) && ContainsValue(range.Maximum);
public bool ContainsRange(Range<T> range) => ContainsValue(range.Minimum) && ContainsValue(range.Maximum);
}
}

0 comments on commit 3351b32

Please sign in to comment.