-
Notifications
You must be signed in to change notification settings - Fork 45
/
RangeTests.cs
65 lines (56 loc) · 2.43 KB
/
RangeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using CompatBot.Utils;
using NUnit.Framework;
// ReSharper disable RedundantRangeBound
namespace Tests;
[TestFixture]
public class RangeTests
{
[Test]
public void UniqueListRangeAccessorTest()
{
var testValue = new[] {0, 1, 2, 3, 4};
var list = new UniqueList<int>(testValue);
Assert.Multiple(() =>
{
Assert.That(list, Is.EqualTo(testValue));
Assert.That(list[0..], Is.EqualTo(testValue[0..]));
Assert.That(list[1..], Is.EqualTo(testValue[1..]));
Assert.That(list[4..], Is.EqualTo(testValue[4..]));
Assert.That(list[5..], Is.EqualTo(testValue[5..]));
Assert.That(list[0..1], Is.EqualTo(testValue[0..1]));
Assert.That(list[0..4], Is.EqualTo(testValue[0..4]));
Assert.That(list[0..5], Is.EqualTo(testValue[0..5]));
Assert.That(list[1..4], Is.EqualTo(testValue[1..4]));
Assert.That(list[1..5], Is.EqualTo(testValue[1..5]));
Assert.That(list[..0], Is.EqualTo(testValue[..0]));
Assert.That(list[..1], Is.EqualTo(testValue[..1]));
Assert.That(list[..4], Is.EqualTo(testValue[..4]));
Assert.That(list[..5], Is.EqualTo(testValue[..5]));
Assert.That(list[^0..], Is.EqualTo(testValue[^0..]));
Assert.That(list[^1..], Is.EqualTo(testValue[^1..]));
Assert.That(list[^4..], Is.EqualTo(testValue[^4..]));
Assert.That(list[^5..], Is.EqualTo(testValue[^5..]));
Assert.That(list[^1..^0], Is.EqualTo(testValue[^1..^0]));
Assert.That(list[^4..^0], Is.EqualTo(testValue[^4..^0]));
Assert.That(list[^5..^0], Is.EqualTo(testValue[^5..^0]));
Assert.That(list[^4..^1], Is.EqualTo(testValue[^4..^1]));
Assert.That(list[^5..^1], Is.EqualTo(testValue[^5..^1]));
Assert.That(list[..^0], Is.EqualTo(testValue[..^0]));
Assert.That(list[..^1], Is.EqualTo(testValue[..^1]));
Assert.That(list[..^4], Is.EqualTo(testValue[..^4]));
Assert.That(list[..^5], Is.EqualTo(testValue[..^5]));
});
}
[Test]
public void SubstringTests()
{
var str = "abc";
Assert.Multiple(() =>
{
Assert.That(str[1..], Is.EqualTo(str.Substring(1)));
Assert.That("a"[1..], Is.EqualTo("a".Substring(1)));
Assert.That(str[0], Is.EqualTo('a'));
Assert.That(str[^1], Is.EqualTo('c'));
});
}
}