Repository navigation
Expand file tree
/
Copy pathMergeSort.cs
More file actions
95 lines (76 loc) · 2.76 KB
/
Copy pathMergeSort.cs
File metadata and controls
95 lines (76 loc) · 2.76 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using CompetitiveProgramming;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTest
{
[TestClass]
public class CompetitiveProgrammingUnitTestForMergeSort
{
[TestMethod]
public void Test()
{
StringBuilder sb = new StringBuilder();
Random random = new Random(10);
Dictionary<int,int> mpa = new Dictionary<int, int>();
for (int k = 0; k < 1000; ++k)
{
int n = random.Next(1, 100);
int[] arry = new int[n];
int[] sorted = new int[n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
arry[j] = random.Next(0, 10000);
}
for (int j = 0; j < n; j++)
{
sorted[j] = arry[j];
}
//TEST CASE RUN
Sort.MergeSort(arry, true);
sorted = sorted.OrderBy(c => c).ToArray();
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append($"NEW TEST CASE: N = {n}");
sb.Append(Environment.NewLine);
sb.Append("Array:");
sb.Append(Environment.NewLine);
foreach (var wval in sorted)
{
sb.Append(wval + " ");
}
sb.Append(Environment.NewLine);
sb.Append("Sorting:");
sb.Append(Environment.NewLine);
foreach (var wval in arry)
{
sb.Append(wval + " ");
}
sb.Append(Environment.NewLine);
int jLoop = 0;
try
{
for (jLoop = 0; jLoop < arry.Length; jLoop++)
{
Assert.AreEqual(sorted[jLoop], arry[jLoop]);
}
}
catch (Exception e)
{
sb.Append($" --> FAILED TEST CASE : got : {arry[jLoop]} vs expected: {sorted[jLoop]}");
sb.Append(Environment.NewLine);
File.WriteAllText("unit-test-input.txt", sb.ToString());
throw e;
}
sb.Append(Environment.NewLine);
}
}
File.WriteAllText("unit-test-input.txt", sb.ToString());
}
}
}