Skip to content

Commit d79e725

Browse files
authored
Switch to file-scoped namespaces (TheAlgorithms#436)
1 parent e8ca3f4 commit d79e725

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5716
-5763
lines changed

DataStructures.Tests/AATreeTests.cs

Lines changed: 245 additions & 246 deletions
Large diffs are not rendered by default.

DataStructures.Tests/AVLTreeTests.cs

Lines changed: 318 additions & 319 deletions
Large diffs are not rendered by default.

DataStructures.Tests/BinarySearchTreeTests.cs

Lines changed: 274 additions & 275 deletions
Large diffs are not rendered by default.

DataStructures.Tests/BitArrayTests.cs

Lines changed: 410 additions & 411 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,76 @@
1-
using System;
21
using DataStructures.Cache;
3-
using NUnit.Framework;
42
using FluentAssertions;
3+
using NUnit.Framework;
54

6-
namespace DataStructures.Tests.Cache
5+
namespace DataStructures.Tests.Cache;
6+
7+
public static class LfuCacheTests
78
{
8-
public static class LfuCacheTests
9+
[Test]
10+
public static void TestPutGet()
11+
{
12+
var cache = new LfuCache<int, string>();
13+
cache.Put(1, "one");
14+
15+
cache.Contains(1).Should().BeTrue();
16+
cache.Get(1).Should().Be("one");
17+
}
18+
19+
[Test]
20+
public static void TestCacheMiss()
921
{
10-
[Test]
11-
public static void TestPutGet()
12-
{
13-
var cache = new LfuCache<int, string>();
14-
cache.Put(1, "one");
15-
16-
cache.Contains(1).Should().BeTrue();
17-
cache.Get(1).Should().Be("one");
18-
}
19-
20-
[Test]
21-
public static void TestCacheMiss()
22-
{
23-
var cache = new LfuCache<int, string>();
24-
cache.Put(1, "one");
25-
26-
cache.Contains(5).Should().BeFalse();
27-
cache.Get(5).Should().BeNull();
28-
}
29-
30-
[Test]
31-
public static void Evict_ItemWasNotUsed()
32-
{
33-
var cache = new LfuCache<int, string>(capacity: 1);
34-
cache.Put(1, "one");
35-
36-
// Add to the full cache, 1 will be removed
37-
cache.Put(2, "two");
38-
39-
cache.Get(1).Should().BeNull();
40-
cache.Get(2).Should().Be("two");
41-
}
42-
43-
[Test]
44-
public static void Evict_OneItemWasUsed()
45-
{
46-
var cache = new LfuCache<int, string>(capacity: 2);
47-
cache.Put(1, "one");
48-
cache.Put(2, "two");
49-
50-
cache.Put(1, "ONE");
51-
52-
// Add to the full cache, 2 will be removed
53-
cache.Put(3, "three");
54-
55-
cache.Get(1).Should().Be("ONE");
56-
cache.Get(2).Should().BeNull();
57-
cache.Get(3).Should().Be("three");
58-
}
59-
60-
[Test]
61-
public static void Evict_LruOrder()
62-
{
63-
var cache = new LfuCache<int, string>(capacity: 2);
64-
cache.Put(1, "one");
65-
cache.Put(2, "two");
66-
67-
cache.Put(1, "ONE");
68-
cache.Put(2, "TWO");
69-
70-
// Add to the full cache, 1 will be removed
71-
cache.Put(3, "three");
72-
73-
cache.Get(1).Should().BeNull();
74-
cache.Get(2).Should().Be("TWO");
75-
cache.Get(3).Should().Be("three");
76-
}
22+
var cache = new LfuCache<int, string>();
23+
cache.Put(1, "one");
24+
25+
cache.Contains(5).Should().BeFalse();
26+
cache.Get(5).Should().BeNull();
27+
}
28+
29+
[Test]
30+
public static void Evict_ItemWasNotUsed()
31+
{
32+
var cache = new LfuCache<int, string>(capacity: 1);
33+
cache.Put(1, "one");
34+
35+
// Add to the full cache, 1 will be removed
36+
cache.Put(2, "two");
37+
38+
cache.Get(1).Should().BeNull();
39+
cache.Get(2).Should().Be("two");
40+
}
41+
42+
[Test]
43+
public static void Evict_OneItemWasUsed()
44+
{
45+
var cache = new LfuCache<int, string>(capacity: 2);
46+
cache.Put(1, "one");
47+
cache.Put(2, "two");
48+
49+
cache.Put(1, "ONE");
50+
51+
// Add to the full cache, 2 will be removed
52+
cache.Put(3, "three");
53+
54+
cache.Get(1).Should().Be("ONE");
55+
cache.Get(2).Should().BeNull();
56+
cache.Get(3).Should().Be("three");
57+
}
58+
59+
[Test]
60+
public static void Evict_LruOrder()
61+
{
62+
var cache = new LfuCache<int, string>(capacity: 2);
63+
cache.Put(1, "one");
64+
cache.Put(2, "two");
65+
66+
cache.Put(1, "ONE");
67+
cache.Put(2, "TWO");
68+
69+
// Add to the full cache, 1 will be removed
70+
cache.Put(3, "three");
71+
72+
cache.Get(1).Should().BeNull();
73+
cache.Get(2).Should().Be("TWO");
74+
cache.Get(3).Should().Be("three");
7775
}
7876
}
Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,69 @@
1-
using System;
21
using DataStructures.Cache;
3-
using NUnit.Framework;
42
using FluentAssertions;
3+
using NUnit.Framework;
4+
5+
namespace DataStructures.Tests.Cache;
56

6-
namespace DataStructures.Tests.Cache
7+
public static class LruCacheTests
78
{
8-
public static class LruCacheTests
9+
[Test]
10+
public static void TestPutGet()
911
{
10-
[Test]
11-
public static void TestPutGet()
12-
{
13-
var cache = new LruCache<int, string>();
14-
cache.Put(1, "one");
12+
var cache = new LruCache<int, string>();
13+
cache.Put(1, "one");
1514

16-
cache.Contains(1).Should().BeTrue();
17-
cache.Get(1).Should().Be("one");
18-
}
15+
cache.Contains(1).Should().BeTrue();
16+
cache.Get(1).Should().Be("one");
17+
}
1918

20-
[Test]
21-
public static void TestCacheMiss()
22-
{
23-
var cache = new LruCache<int, string>();
24-
cache.Put(1, "one");
19+
[Test]
20+
public static void TestCacheMiss()
21+
{
22+
var cache = new LruCache<int, string>();
23+
cache.Put(1, "one");
2524

26-
cache.Contains(5).Should().BeFalse();
27-
cache.Get(5).Should().BeNull();
28-
}
25+
cache.Contains(5).Should().BeFalse();
26+
cache.Get(5).Should().BeNull();
27+
}
2928

30-
[Test]
31-
public static void TestCacheUpdate()
32-
{
33-
var cache = new LruCache<int, string>();
34-
cache.Put(1, "one");
35-
cache.Put(1, "ONE");
29+
[Test]
30+
public static void TestCacheUpdate()
31+
{
32+
var cache = new LruCache<int, string>();
33+
cache.Put(1, "one");
34+
cache.Put(1, "ONE");
3635

37-
cache.Get(1).Should().Be("ONE");
38-
}
36+
cache.Get(1).Should().Be("ONE");
37+
}
3938

40-
[Test]
41-
public static void RemoveOldestItem_ItemWasNotUsed()
42-
{
43-
var cache = new LruCache<int, string>(capacity: 2);
44-
cache.Put(1, "one");
45-
cache.Put(2, "two");
39+
[Test]
40+
public static void RemoveOldestItem_ItemWasNotUsed()
41+
{
42+
var cache = new LruCache<int, string>(capacity: 2);
43+
cache.Put(1, "one");
44+
cache.Put(2, "two");
4645

47-
// Add to the full cache, 1 will be removed
48-
cache.Put(3, "three");
46+
// Add to the full cache, 1 will be removed
47+
cache.Put(3, "three");
4948

50-
cache.Get(1).Should().BeNull();
51-
cache.Get(2).Should().Be("two");
52-
cache.Get(3).Should().Be("three");
53-
}
49+
cache.Get(1).Should().BeNull();
50+
cache.Get(2).Should().Be("two");
51+
cache.Get(3).Should().Be("three");
52+
}
5453

55-
[Test]
56-
public static void RemoveOldestItem_ItemWasRecentlyUsed()
57-
{
58-
var cache = new LruCache<int, string>(capacity: 2);
59-
cache.Put(1, "one");
60-
cache.Put(2, "two");
61-
cache.Get(1);
54+
[Test]
55+
public static void RemoveOldestItem_ItemWasRecentlyUsed()
56+
{
57+
var cache = new LruCache<int, string>(capacity: 2);
58+
cache.Put(1, "one");
59+
cache.Put(2, "two");
60+
cache.Get(1);
6261

63-
// Add to the full cache, 1 was used, 2 should be removed
64-
cache.Put(3, "three");
62+
// Add to the full cache, 1 was used, 2 should be removed
63+
cache.Put(3, "three");
6564

66-
cache.Get(1).Should().Be("one");
67-
cache.Get(2).Should().BeNull();
68-
cache.Get(3).Should().Be("three");
69-
}
65+
cache.Get(1).Should().Be("one");
66+
cache.Get(2).Should().BeNull();
67+
cache.Get(3).Should().Be("three");
7068
}
71-
}
69+
}
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
using DataStructures.DisjointSet;
1+
using DataStructures.DisjointSet;
22
using FluentAssertions;
33
using NUnit.Framework;
44

5-
namespace DataStructures.Tests.DisjointSet
5+
namespace DataStructures.Tests.DisjointSet;
6+
7+
[TestFixture]
8+
public class DisjointSetTests
69
{
7-
[TestFixture]
8-
public class DisjointSetTests
10+
[Test]
11+
public static void MakeSetDataInitializationTest()
12+
{
13+
DisjointSet<int> ds = new();
14+
var one = ds.MakeSet(1);
15+
var two = ds.MakeSet(2);
16+
one.Data.Should().Be(1);
17+
two.Data.Should().Be(2);
18+
}
19+
[Test]
20+
public static void UnionTest()
921
{
10-
[Test]
11-
public static void MakeSetDataInitializationTest()
12-
{
13-
DisjointSet<int> ds = new();
14-
var one = ds.MakeSet(1);
15-
var two = ds.MakeSet(2);
16-
one.Data.Should().Be(1);
17-
two.Data.Should().Be(2);
18-
}
19-
[Test]
20-
public static void UnionTest()
21-
{
22-
DisjointSet<int> ds = new();
23-
var one = ds.MakeSet(1);
24-
var two = ds.MakeSet(2);
25-
var three = ds.MakeSet(3);
26-
ds.UnionSet(one, two);
27-
ds.FindSet(one).Should().Be(ds.FindSet(two));
28-
ds.UnionSet(one, three);
29-
ds.FindSet(two).Should().Be(ds.FindSet(three));
30-
(one.Rank + two.Rank + three.Rank).Should().Be(1);
31-
}
22+
DisjointSet<int> ds = new();
23+
var one = ds.MakeSet(1);
24+
var two = ds.MakeSet(2);
25+
var three = ds.MakeSet(3);
26+
ds.UnionSet(one, two);
27+
ds.FindSet(one).Should().Be(ds.FindSet(two));
28+
ds.UnionSet(one, three);
29+
ds.FindSet(two).Should().Be(ds.FindSet(three));
30+
(one.Rank + two.Rank + three.Rank).Should().Be(1);
3231
}
3332
}
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
using DataStructures.Fenwick;
2-
using NUnit.Framework;
32
using FluentAssertions;
4-
using System;
3+
using NUnit.Framework;
4+
5+
namespace DataStructures.Tests.Fenwick;
56

6-
namespace DataStructures.Tests.Fenwick
7+
[TestFixture]
8+
internal class BinaryIndexedTreeTests
79
{
8-
[TestFixture]
9-
internal class BinaryIndexedTreeTests
10+
[Test]
11+
public void GetSum_CreateBITAndRequestSum_ReturnCorrect()
1012
{
11-
[Test]
12-
public void GetSum_CreateBITAndRequestSum_ReturnCorrect()
13-
{
14-
int[] array = { 2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9 };
15-
var tree = new BinaryIndexedTree(array);
16-
var expectedSum = 12;
13+
int[] array = { 2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9 };
14+
var tree = new BinaryIndexedTree(array);
15+
var expectedSum = 12;
1716

18-
var resultedSum = tree.GetSum(5);
17+
var resultedSum = tree.GetSum(5);
1918

20-
resultedSum.Should().Be(expectedSum);
21-
}
19+
resultedSum.Should().Be(expectedSum);
20+
}
2221

23-
[Test]
24-
public void UpdateTree_UpdateTreeAndRequestSum_GetSum()
25-
{
26-
int[] array = { 2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9 };
27-
var tree = new BinaryIndexedTree(array);
28-
var expectedSum = 18;
22+
[Test]
23+
public void UpdateTree_UpdateTreeAndRequestSum_GetSum()
24+
{
25+
int[] array = { 2, 1, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9 };
26+
var tree = new BinaryIndexedTree(array);
27+
var expectedSum = 18;
2928

30-
array[3] += 6;
31-
tree.UpdateTree(3, 6);
29+
array[3] += 6;
30+
tree.UpdateTree(3, 6);
3231

33-
var resultedSum = tree.GetSum(5);
34-
resultedSum.Should().Be(expectedSum);
35-
}
32+
var resultedSum = tree.GetSum(5);
33+
resultedSum.Should().Be(expectedSum);
3634
}
3735
}

0 commit comments

Comments
 (0)