Skip to content

Commit 1229692

Browse files
committed
subset
1 parent 4baca7d commit 1229692

File tree

21 files changed

+1035
-43
lines changed

21 files changed

+1035
-43
lines changed

Algorithm.Sandbox.Tests/Algorithm.Sandbox.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,17 @@
8484
<Compile Include="BitAlgorithms\ToggleCase_Tests.cs" />
8585
<Compile Include="BitAlgorithms\TwoNonRepeatingNums_Tests.cs" />
8686
<Compile Include="BitAlgorithms\TwoRepeatingNums_Tests.cs" />
87+
<Compile Include="Combinatorics\Subset_Tests.cs" />
8788
<Compile Include="Combinatorics\Variation_Tests.cs" />
8889
<Compile Include="Combinatorics\Combination_Tests.cs" />
8990
<Compile Include="Combinatorics\Permutation_Tests.cs" />
9091
<Compile Include="Compression\HuffmanCoding_Tests.cs" />
9192
<Compile Include="DataStructures\Dictionary\Dictionary_Tests.cs" />
9293
<Compile Include="DataStructures\Dictionary\TreeDictionary_Tests.cs" />
94+
<Compile Include="DataStructures\Graph\AdjacencyMatrix\DiGraph_Tests.cs" />
95+
<Compile Include="DataStructures\Graph\AdjacencyMatrix\Graph_Tests.cs" />
96+
<Compile Include="DataStructures\Graph\AdjacencyMatrix\WeightedDiGraph_Tests.cs" />
97+
<Compile Include="DataStructures\Graph\AdjacencyMatrix\WeightedGraph_Tests.cs" />
9398
<Compile Include="DataStructures\Graph\AdjacencyList\DiGraph_Tests.cs" />
9499
<Compile Include="DataStructures\Graph\AdjacencyList\Graph_Tests.cs" />
95100
<Compile Include="DataStructures\Graph\AdjacencyList\WeightedDiGraph_Tests.cs" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Algorithm.Sandbox.Combinatorics;
8+
9+
namespace Algorithm.Sandbox.Tests.Combinatorics
10+
{
11+
[TestClass]
12+
public class Subset_Tests
13+
{
14+
15+
[TestMethod]
16+
public void Subset_Smoke_Test()
17+
{
18+
var input = "".ToCharArray().ToList();
19+
var combinations = Subset.Find<char>(input);
20+
Assert.AreEqual(Math.Pow(2, input.Count), combinations.Count);
21+
22+
input = "cookie".ToCharArray().ToList();
23+
combinations = Subset.Find<char>(input);
24+
Assert.AreEqual(Math.Pow(2, input.Count), combinations.Count);
25+
26+
input = "monster".ToCharArray().ToList();
27+
combinations = Subset.Find<char>(input);
28+
Assert.AreEqual(Math.Pow(2, input.Count), combinations.Count);
29+
}
30+
31+
32+
}
33+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Algorithm.Sandbox.DataStructures.Graph.AdjacencyMatrix;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace Algorithm.Sandbox.Tests.DataStructures.Graph.AdjacencyMatrix
5+
{
6+
[TestClass]
7+
public class DiGraph_Tests
8+
{
9+
/// <summary>
10+
/// key value dictionary tests
11+
/// </summary>
12+
[TestMethod]
13+
public void DiGraph_Smoke_Test()
14+
{
15+
var graph = new DiGraph<int>();
16+
17+
graph.AddVertex(1);
18+
graph.AddVertex(2);
19+
graph.AddVertex(3);
20+
graph.AddVertex(4);
21+
graph.AddVertex(5);
22+
23+
graph.AddEdge(1, 2);
24+
graph.AddEdge(2, 3);
25+
graph.AddEdge(3, 4);
26+
graph.AddEdge(4, 5);
27+
graph.AddEdge(4, 1);
28+
graph.AddEdge(3, 5);
29+
30+
Assert.AreEqual(5, graph.VerticesCount);
31+
32+
Assert.IsTrue(graph.HasEdge(1, 2));
33+
34+
graph.RemoveEdge(1, 2);
35+
36+
Assert.IsFalse(graph.HasEdge(1, 2));
37+
38+
graph.RemoveEdge(2, 3);
39+
graph.RemoveEdge(3, 4);
40+
graph.RemoveEdge(4, 5);
41+
graph.RemoveEdge(4, 1);
42+
43+
Assert.IsTrue(graph.HasEdge(3, 5));
44+
graph.RemoveEdge(3, 5);
45+
Assert.IsFalse(graph.HasEdge(3, 5));
46+
47+
graph.RemoveVertex(1);
48+
graph.RemoveVertex(2);
49+
graph.RemoveVertex(3);
50+
graph.RemoveVertex(4);
51+
graph.RemoveVertex(5);
52+
53+
Assert.AreEqual(0, graph.VerticesCount);
54+
}
55+
}
56+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Algorithm.Sandbox.DataStructures;
2+
using Algorithm.Sandbox.DataStructures.Graph.AdjacencyMatrix;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Algorithm.Sandbox.Tests.DataStructures.Graph.AdjacencyMatrix
11+
{
12+
[TestClass]
13+
public class Graph_Tests
14+
{
15+
/// <summary>
16+
/// key value dictionary tests
17+
/// </summary>
18+
[TestMethod]
19+
public void Graph_Smoke_Test()
20+
{
21+
var graph = new Graph<int>();
22+
23+
graph.AddVertex(1);
24+
graph.AddVertex(2);
25+
graph.AddVertex(3);
26+
graph.AddVertex(4);
27+
graph.AddVertex(5);
28+
29+
graph.AddEdge(1, 2);
30+
graph.AddEdge(2, 3);
31+
graph.AddEdge(3, 4);
32+
graph.AddEdge(4, 5);
33+
graph.AddEdge(4, 1);
34+
graph.AddEdge(3, 5);
35+
36+
Assert.AreEqual(5, graph.VerticesCount);
37+
38+
Assert.IsTrue(graph.HasEdge(1, 2));
39+
40+
graph.RemoveEdge(1, 2);
41+
42+
Assert.IsFalse(graph.HasEdge(1, 2));
43+
44+
graph.RemoveEdge(2, 3);
45+
graph.RemoveEdge(3, 4);
46+
graph.RemoveEdge(4, 5);
47+
graph.RemoveEdge(4, 1);
48+
49+
Assert.IsTrue(graph.HasEdge(3, 5));
50+
graph.RemoveEdge(3, 5);
51+
Assert.IsFalse(graph.HasEdge(3, 5));
52+
53+
graph.RemoveVertex(1);
54+
graph.RemoveVertex(2);
55+
graph.RemoveVertex(3);
56+
graph.RemoveVertex(4);
57+
graph.RemoveVertex(5);
58+
59+
Assert.AreEqual(0, graph.VerticesCount);
60+
}
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Algorithm.Sandbox.DataStructures;
2+
using Algorithm.Sandbox.DataStructures.Graph.AdjacencyMatrix;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Algorithm.Sandbox.Tests.DataStructures.Graph.AdjacencyMatrix
11+
{
12+
[TestClass]
13+
public class WeightedDiGraph_Tests
14+
{
15+
/// <summary>
16+
/// key value dictionary tests
17+
/// </summary>
18+
[TestMethod]
19+
public void WeightedDiGraph_Smoke_Test()
20+
{
21+
var graph = new WeightedDiGraph<int, int>();
22+
23+
graph.AddVertex(1);
24+
graph.AddVertex(2);
25+
graph.AddVertex(3);
26+
graph.AddVertex(4);
27+
graph.AddVertex(5);
28+
29+
graph.AddEdge(1, 2, 1);
30+
graph.AddEdge(2, 3, 2);
31+
graph.AddEdge(3, 4, 3);
32+
graph.AddEdge(4, 5, 1);
33+
graph.AddEdge(4, 1, 6);
34+
graph.AddEdge(3, 5, 4);
35+
36+
Assert.AreEqual(5, graph.VerticesCount);
37+
38+
Assert.IsTrue(graph.HasEdge(1, 2));
39+
40+
graph.RemoveEdge(1, 2);
41+
42+
Assert.IsFalse(graph.HasEdge(1, 2));
43+
44+
graph.RemoveEdge(2, 3);
45+
graph.RemoveEdge(3, 4);
46+
graph.RemoveEdge(4, 5);
47+
graph.RemoveEdge(4, 1);
48+
49+
Assert.IsTrue(graph.HasEdge(3, 5));
50+
graph.RemoveEdge(3, 5);
51+
Assert.IsFalse(graph.HasEdge(3, 5));
52+
53+
graph.RemoveVertex(1);
54+
graph.RemoveVertex(2);
55+
graph.RemoveVertex(3);
56+
graph.RemoveVertex(4);
57+
graph.RemoveVertex(5);
58+
59+
Assert.AreEqual(0, graph.VerticesCount);
60+
}
61+
}
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Algorithm.Sandbox.DataStructures;
2+
using Algorithm.Sandbox.DataStructures.Graph.AdjacencyMatrix;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Algorithm.Sandbox.Tests.DataStructures.Graph.AdjacencyMatrix
11+
{
12+
[TestClass]
13+
public class WeightedGraph_Tests
14+
{
15+
/// <summary>
16+
/// key value dictionary tests
17+
/// </summary>
18+
[TestMethod]
19+
public void WeightedGraph_Smoke_Test()
20+
{
21+
var graph = new WeightedGraph<int, int>();
22+
23+
graph.AddVertex(1);
24+
graph.AddVertex(2);
25+
graph.AddVertex(3);
26+
graph.AddVertex(4);
27+
graph.AddVertex(5);
28+
29+
graph.AddEdge(1, 2, 1);
30+
graph.AddEdge(2, 3, 2);
31+
graph.AddEdge(3, 4, 4);
32+
graph.AddEdge(4, 5, 5);
33+
graph.AddEdge(4, 1, 1);
34+
graph.AddEdge(3, 5, 0);
35+
36+
Assert.AreEqual(5, graph.VerticesCount);
37+
38+
Assert.IsTrue(graph.HasEdge(1, 2));
39+
40+
graph.RemoveEdge(1, 2);
41+
42+
Assert.IsFalse(graph.HasEdge(1, 2));
43+
44+
graph.RemoveEdge(2, 3);
45+
graph.RemoveEdge(3, 4);
46+
graph.RemoveEdge(4, 5);
47+
graph.RemoveEdge(4, 1);
48+
49+
Assert.IsTrue(graph.HasEdge(3, 5));
50+
graph.RemoveEdge(3, 5);
51+
Assert.IsFalse(graph.HasEdge(3, 5));
52+
53+
graph.RemoveVertex(1);
54+
graph.RemoveVertex(2);
55+
graph.RemoveVertex(3);
56+
graph.RemoveVertex(4);
57+
graph.RemoveVertex(5);
58+
59+
Assert.AreEqual(0, graph.VerticesCount);
60+
}
61+
}
62+
}

Algorithm.Sandbox.Tests/DataStructures/Queues/Queue_Tests.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ namespace Algorithm.Sandbox.Tests.DataStructures.Queues
77
[TestClass]
88
public class Queue_Tests
99
{
10-
/// <summary>
11-
/// A dynamic array test
12-
/// </summary>
10+
1311
[TestMethod]
14-
public void Queue_Test()
12+
public void ArrayQueue_Test()
1513
{
1614
var Queue = new AsQueue<string>();
1715

@@ -23,6 +21,34 @@ public void Queue_Test()
2321
Assert.AreEqual(Queue.Dequeue(), "a");
2422

2523

24+
Assert.AreEqual(Queue.Count, 2);
25+
Assert.AreEqual(Queue.Dequeue(), "b");
26+
27+
Assert.AreEqual(Queue.Count, 1);
28+
Assert.AreEqual(Queue.Dequeue(), "c");
29+
30+
Assert.AreEqual(Queue.Count, 0);
31+
32+
Queue.Enqueue("a");
33+
34+
Assert.AreEqual(Queue.Count, 1);
35+
Assert.AreEqual(Queue.Dequeue(), "a");
36+
37+
}
38+
39+
[TestMethod]
40+
public void LinkedListQueue_Test()
41+
{
42+
var Queue = new AsQueue<string>(QueueType.LinkedList);
43+
44+
Queue.Enqueue("a");
45+
Queue.Enqueue("b");
46+
Queue.Enqueue("c");
47+
48+
Assert.AreEqual(Queue.Count, 3);
49+
Assert.AreEqual(Queue.Dequeue(), "a");
50+
51+
2652
Assert.AreEqual(Queue.Count, 2);
2753
Assert.AreEqual(Queue.Dequeue(), "b");
2854

Algorithm.Sandbox.Tests/DataStructures/Stack_Tests.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ namespace Algorithm.Sandbox.Tests.DataStructures
66
[TestClass]
77
public class Stack_Tests
88
{
9-
/// <summary>
10-
/// A dynamic array test
11-
/// </summary>
9+
1210
[TestMethod]
13-
public void Stack_Test()
11+
public void ArrayStack_Test()
1412
{
1513
var stack = new AsStack<string>();
1614

@@ -33,5 +31,30 @@ public void Stack_Test()
3331
Assert.AreEqual(stack.Count, 1);
3432
Assert.AreEqual(stack.Peek(), "a");
3533
}
34+
35+
[TestMethod]
36+
public void LinkedListStack_Test()
37+
{
38+
var stack = new AsStack<string>(StackType.LinkedList);
39+
40+
stack.Push("a");
41+
stack.Push("b");
42+
43+
Assert.AreEqual(stack.Count, 2);
44+
Assert.AreEqual(stack.Peek(), "b");
45+
46+
stack.Pop();
47+
48+
Assert.AreEqual(stack.Count, 1);
49+
Assert.AreEqual(stack.Peek(), "a");
50+
51+
stack.Pop();
52+
53+
Assert.AreEqual(stack.Count, 0);
54+
55+
stack.Push("a");
56+
Assert.AreEqual(stack.Count, 1);
57+
Assert.AreEqual(stack.Peek(), "a");
58+
}
3659
}
3760
}

0 commit comments

Comments
 (0)