public void GetRangeNegativeArgsThrow() { var set = new OrderedSet <int> { 0, 1, 2, 3 }; var exception = Assert.Throws <ArgumentException>(() => set.GetRange(-1, 3)); Assert.Equal("Index and count must be positive", exception.Message); var exception2 = Assert.Throws <ArgumentException>(() => set.GetRange(0, -3)); Assert.Equal("Index and count must be positive", exception2.Message); }
public void SkipTest() { var set = new OrderedSet <int> { 1, 2, 3, 4, 5, 6 }; var range = set.GetRange(0, 2); var range2 = set.Skip(0).Take(2); Assert.Equal(range, range2); range = set.GetRange(1, 2); range2 = set.Skip(1).Take(2); Assert.Equal(range, range2); }
public void GetEmptyRangeSuccessfully() { var set = new OrderedSet <int>(); var subSet = set.GetRange(0, 0); Assert.Equal(subSet.Count, 0); }
public void GetRangeOutOfBoundsThrows() { var set = new OrderedSet <int> { 0, 1, 2, 3 }; var exception = Assert.Throws <ArgumentException>(() => set.GetRange(2, 3)); Assert.Equal("Trying to get range outside collection bounds", exception.Message); }
public void GetRangeSuccessfully() { var set = new OrderedSet <int> { 0, 1, 2, 3, 4, 5 }; var subSet = set.GetRange(3, 2); Assert.Equal(subSet.Count, 2); Assert.Equal(subSet[0], 3); Assert.Equal(subSet[1], 4); }
private static Tuple <string[], string> GetAddressTransactions(OrderedSet <string> transactionIds, int?from = null, int?to = null) { if (from == null && to == null) { from = 0; to = transactionIds.Count; } else { from = Math.Max(from ?? 0, 0); to = Math.Min(to ?? transactionIds.Count, transactionIds.Count); var validationResult = ValidateParameters(from.Value, to.Value); if (!validationResult.Item1) { return(new Tuple <string[], string>(null, validationResult.Item2)); } } return(new Tuple <string[], string>(transactionIds.GetRange(from.Value, to.Value - from.Value).ToArray(), "")); }
private static Tuple <string[], string> GetAddressTransactions(OrderedSet <string> transactionIds, int from, int to) { if (transactionIds.Count == 0) { return(new Tuple <string[], string>(new string[0], "")); } if (to == 0) { to = Math.Min(transactionIds.Count, from + Constants.MAX_TX_COUNT_BY_ADDRESS); } var validationResult = ValidateParameters(from, to, transactionIds.Count); if (!validationResult.Item1) { return(new Tuple <string[], string>(null, validationResult.Item2)); } return(new Tuple <string[], string>(transactionIds.GetRange(from, to - from).ToArray(), "")); }