Skip to content

Commit

Permalink
Merge pull request #6 from justcoding121/develop
Browse files Browse the repository at this point in the history
Beta release 128+
  • Loading branch information
justcoding121 authored Jan 23, 2018
2 parents 2fe2b00 + 907041d commit df3c2a1
Show file tree
Hide file tree
Showing 21 changed files with 595 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .build/Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Install-Psake

$psakeDirectory = (Resolve-Path $env:ChocolateyInstall\lib\Psake*)

Import-Module (Join-Path $psakeDirectory "tools\Psake.psm1")
Import-Module (Join-Path $psakeDirectory "tools\Psake\Psake.psm1")

if($Help)
{
Expand Down
2 changes: 1 addition & 1 deletion .build/Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Install-Chocolatey()

function Install-Psake()
{
if(!(Test-Path $env:ChocolateyInstall\lib\Psake*))
if(!(Test-Path $env:ChocolateyInstall\lib\Psake\tools\Psake*))
{
choco install psake -y
}
Expand Down
2 changes: 1 addition & 1 deletion .build/default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Task Restore-Packages {
}

Task Install-MSBuild {
if(!(Test-Path $MSBuild14))
if(!(Test-Path $MSBuild))
{
cinst microsoft-build-tools -y
}
Expand Down
6 changes: 4 additions & 2 deletions Advanced.Algorithms.Tests/Advanced.Algorithms.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<Compile Include="BitAlgorithms\NextPowOfTwo_Tests.cs" />
<Compile Include="BitAlgorithms\ToggleCase_Tests.cs" />
<Compile Include="Combinatorics\Subset_Tests.cs" />
<Compile Include="Combinatorics\Variation_Tests.cs" />
<Compile Include="Combinatorics\Combination_Tests.cs" />
<Compile Include="Combinatorics\Permutation_Tests.cs" />
<Compile Include="Compression\HuffmanCoding_Tests.cs" />
Expand Down Expand Up @@ -99,7 +98,7 @@
<Compile Include="DataStructures\Lists\ArrayList_Tests.cs" />
<Compile Include="DataStructures\Lists\SkipList_Tests.cs" />
<Compile Include="DataStructures\Queues\PriorityQueue\MaxPriorityQueue_Tests.cs" />
<Compile Include="DataStructures\Queues\CircularQueue_Tests.cs" />
<Compile Include="DistributedSystems\CircularQueue_Tests.cs" />
<Compile Include="DataStructures\Queues\Queue_Tests.cs" />
<Compile Include="DataStructures\Set\BloomFilter_Tests.cs" />
<Compile Include="DataStructures\Set\DisJointSet_Tests.cs" />
Expand All @@ -126,7 +125,10 @@
<Compile Include="DataStructures\Tree\TestHelpers\BinarySearchTreeTester.cs" />
<Compile Include="DataStructures\Tree\Tree_Tests.cs" />
<Compile Include="DataStructures\Tree\BinaryTree_Tests.cs" />
<Compile Include="DistributedSystems\ConsistentHash_Tests.cs" />
<Compile Include="DistributedSystems\LRUCache_Tests.cs" />
<Compile Include="Geometry\PointRotation_Tests.cs" />
<Compile Include="GraphAlgorithms\ShortestPath\TravellingSalesman_Tests.cs" />
<Compile Include="Miscellaneous\MatrixMultiplication_Tests.cs" />
<Compile Include="Geometry\ClosestPointPair_Tests.cs" />
<Compile Include="Geometry\ConvexHull_Tests.cs" />
Expand Down
79 changes: 33 additions & 46 deletions Advanced.Algorithms.Tests/Combinatorics/Permutation_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,64 @@ namespace Advanced.Algorithms.Tests.Combinatorics
public class Permutation_Tests
{
//for verification
readonly Func<int, int> factorial = n => n == 0 ? 1 :
static readonly Func<int, int> factorial = n => n == 0 ? 1 :
Enumerable.Range(1, n).Aggregate((acc, x) => acc * x);


[TestMethod]
public void Permutation_Without_Repetitions_Smoke_Test()
{
var input = "".ToCharArray().ToList();
var permuations = Permutation.Find<char>(input);
Assert.AreEqual(factorial(input.Count), permuations.Count);

input = "cookie".ToCharArray().ToList();
permuations = Permutation.Find<char>(input);
Assert.AreEqual(factorial(input.Count), permuations.Count);

input = "monster".ToCharArray().ToList();
permuations = Permutation.Find<char>(input);
Assert.AreEqual(factorial(input.Count), permuations.Count);
}

//for verification
static readonly Func<int, int, int> permutation = (int n, int r)
=> n == 0 || r == 0 ? 1 : factorial(n) / factorial(n - r);

[TestMethod]
public void Permutation_With_Repetition_Smoke_Test()
{
var input = "".ToCharArray().ToList();
var permuations = Permutation.Find<char>(input, true);
var permuations = Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);

input = "pen".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, true);
permuations = Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);

input = "scan".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, true);
permuations = Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);
}

[TestMethod]
public void Permutation_Without_Repetition_Without_Inversions_Smoke_Test()
{
var input = "".ToCharArray().ToList();
var permuations = Permutation.Find<char>(input, false, false);
Assert.AreEqual(factorial(input.Count) / 2, permuations.Count);
input = "scan".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, 2, true);
Assert.AreEqual(Math.Pow(input.Count, 2), permuations.Count);

input = "abc".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, false, false);
Assert.AreEqual(factorial(input.Count) / 2, permuations.Count);
input = "scan".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, 3, true);
Assert.AreEqual(Math.Pow(input.Count, 3), permuations.Count);

input = "acde".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, false, false);
Assert.AreEqual(factorial(input.Count) / 2, permuations.Count);
input = "scaner".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, 4, true);
Assert.AreEqual(Math.Pow(input.Count, 4), permuations.Count);
}


[TestMethod]
public void Permutation_With_Repetition_Without_Inversions_Smoke_Test()
public void Permutation_Without_Repetitions_Smoke_Test()
{

var input = "".ToCharArray().ToList();
var permuations = Permutation.Find<char>(input, true, false);
Assert.AreEqual(0, permuations.Count);
var permuations = Permutation.Find<char>(input, input.Count);
Assert.AreEqual(permutation(input.Count, input.Count), permuations.Count);

input = "pen".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, true, false);
Assert.AreEqual(9, permuations.Count);
input = "cookie".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, input.Count);
Assert.AreEqual(permutation(input.Count, input.Count), permuations.Count);

input = "cool".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, true, false);
Assert.AreEqual(80, permuations.Count);
}
input = "monster".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, input.Count);
Assert.AreEqual(permutation(input.Count, input.Count), permuations.Count);


input = "cookie".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, 2);
Assert.AreEqual(permutation(input.Count, 2), permuations.Count);

input = "monster".ToCharArray().ToList();
permuations = Permutation.Find<char>(input, 3);
Assert.AreEqual(permutation(input.Count, 3), permuations.Count);
}
}
}
56 changes: 0 additions & 56 deletions Advanced.Algorithms.Tests/Combinatorics/Variation_Tests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Advanced.Algorithms.DataStructures;
using Advanced.Algorithms.DataStructures.Queues;
using Advanced.Algorithms.DataStructures.DistributedSystems;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Advanced.Algorithms.Tests.DataStructures.Queues
namespace Advanced.Algorithms.Tests.DataStructures.DistributedSystems
{
[TestClass]
public class CircularQueue_Tests
Expand All @@ -13,16 +12,16 @@ public void CircularQueue_Test()
{
var Queue = new CircularQueue<int>(7);

Queue.Enqueue(1);
Queue.Enqueue(2);
Assert.AreEqual(0, Queue.Enqueue(1));
Assert.AreEqual(0, Queue.Enqueue(2));

Queue.Enqueue(3);
Queue.Enqueue(4);
Queue.Enqueue(5);
Queue.Enqueue(6);
Queue.Enqueue(7);
Queue.Enqueue(8);
Queue.Enqueue(9);
Assert.AreEqual(0, Queue.Enqueue(3));
Assert.AreEqual(0, Queue.Enqueue(4));
Assert.AreEqual(0, Queue.Enqueue(5));
Assert.AreEqual(0, Queue.Enqueue(6));
Assert.AreEqual(0, Queue.Enqueue(7));
Assert.AreEqual(1, Queue.Enqueue(8));
Assert.AreEqual(2, Queue.Enqueue(9));

Assert.AreEqual(Queue.Count, 7);
Assert.AreEqual(3, Queue.Dequeue());
Expand All @@ -47,8 +46,8 @@ public void CircularQueue_Test()

Assert.AreEqual(Queue.Count, 0);

Queue.Enqueue(1);
Queue.Enqueue(2);
Assert.AreEqual(0, Queue.Enqueue(1));
Assert.AreEqual(0, Queue.Enqueue(2));

Assert.AreEqual(Queue.Count, 2);
Assert.AreEqual(1, Queue.Dequeue());
Expand All @@ -57,6 +56,6 @@ public void CircularQueue_Test()
Assert.AreEqual(Queue.Dequeue(), 2);
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Advanced.Algorithms.DistributedSystems;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Advanced.Algorithms.Tests.DistributedSystems
{
[TestClass]
public class ConsistentHash_Tests
{

[TestMethod]
public void ConsistantHash_Smoke_Test()
{
var hash = new ConsistentHash<int>();

hash.AddNode(15);
hash.AddNode(25);
hash.AddNode(172);

for (int i = 200; i < 300; i++)
{
hash.AddNode(i);
}

hash.RemoveNode(15);
hash.RemoveNode(172);
hash.RemoveNode(25);

var rnd = new Random();
for (int i = 0; i < 1000; i++)
{
Assert.AreNotEqual(15, hash.GetNode(rnd.Next().ToString()));
Assert.AreNotEqual(25, hash.GetNode(rnd.Next().ToString()));
Assert.AreNotEqual(172, hash.GetNode(rnd.Next().ToString()));

var t = hash.GetNode(rnd.Next().ToString());
Assert.IsTrue(t >= 200 && t < 300);
}

}

}
}
30 changes: 30 additions & 0 deletions Advanced.Algorithms.Tests/DistributedSystems/LRUCache_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Advanced.Algorithms.DistributedSystems;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Advanced.Algorithms.Tests.DistributedSystems
{
[TestClass]
public class LRUCache_Tests
{

[TestMethod]
public void LRUCache_Smoke_Test()
{
var cache = new LRUCache<int,int>(2);

cache.Put(1, 1);
cache.Put(2, 2);
Assert.AreEqual(1, cache.Get(1));

cache.Put(3, 3);
Assert.AreEqual(0, cache.Get(2));

cache.Put(4, 4);
Assert.AreEqual(0, cache.Get(1));
Assert.AreEqual(3, cache.Get(3));
Assert.AreEqual(4, cache.Get(4));
}

}
}
Loading

0 comments on commit df3c2a1

Please sign in to comment.