-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathPermutation_Tests.cs
72 lines (58 loc) · 3.22 KB
/
Permutation_Tests.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
66
67
68
69
70
71
72
using System;
using System.Linq;
using Advanced.Algorithms.Combinatorics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.Combinatorics
{
[TestClass]
public class PermutationTests
{
//for verification
static readonly Func<int, int> Factorial = n =>
n == 0 ? 1 : Enumerable.Range(1, n).Aggregate((acc, x) => acc * x);
//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 = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);
input = "pen".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);
input = "scan".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count, true);
Assert.AreEqual(Math.Pow(input.Count, input.Count), permuations.Count);
input = "scan".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, 2, true);
Assert.AreEqual(Math.Pow(input.Count, 2), permuations.Count);
input = "scan".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, 3, true);
Assert.AreEqual(Math.Pow(input.Count, 3), permuations.Count);
input = "scaner".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, 4, true);
Assert.AreEqual(Math.Pow(input.Count, 4), permuations.Count);
}
[TestMethod]
public void Permutation_Without_Repetitions_Smoke_Test()
{
var input = "".ToCharArray().ToList();
var permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count);
Assert.AreEqual(Permutation(input.Count, input.Count), permuations.Count);
input = "cookie".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count);
Assert.AreEqual(Permutation(input.Count, input.Count), permuations.Count);
input = "monster".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, input.Count);
Assert.AreEqual(Permutation(input.Count, input.Count), permuations.Count);
input = "cookie".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, 2);
Assert.AreEqual(Permutation(input.Count, 2), permuations.Count);
input = "monster".ToCharArray().ToList();
permuations = Algorithms.Combinatorics.Permutation.Find<char>(input, 3);
Assert.AreEqual(Permutation(input.Count, 3), permuations.Count);
}
}
}