-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
138 lines (126 loc) · 5.75 KB
/
Copy pathProgram.cs
File metadata and controls
138 lines (126 loc) · 5.75 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Threading;
namespace ASD
{
class Program
{
static void Main(string[] args)
{
CustomTestCase[] testy =
{
makeTestCase(true, 1, 0, "()", "()"),
makeTestCase(false, int.MaxValue, 1, "())", "()"),
makeTestCase(true, 8, 0, "(()(()()))()(())", "()"),
makeTestCase(false, int.MaxValue, 3, "())())(()", "()"),
makeTestCase(true, 10, 0, "()?..().) (.)(.)", ".", "()", " ", ")?", ".."),
makeTestCase(false, int.MaxValue, 3, "abcdefgabcdefgabcdefg", "ab", "bc", "cd", "de", "ef", "fg"),
makeTestCase(true, 5, 0, "xAAAxBxC", "x", "xA", "xB", "xC", "AB", "AC"),
makeTestCase(false, int.MaxValue, 10, "(xAAxBxC)(xAAxBxC)(xAAxBxC)(xAAxBxC)(xAAxBxC)", "x", "xA", "xB", "xC", "AB", "AC"),
makeTestCase(true, 250, 0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AA", "A"),
makeTestCase(false, int.MaxValue, 1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AA"),
};
Console.WriteLine("Wynik metody Eraseable:");
int i = 0;
foreach (CustomTestCase tc in testy)
{
string msg;
tc.TestResults(out msg);
Console.WriteLine("Test " + (i++).ToString() + ":\t" + msg);
}
Console.WriteLine("\n\nOptymalna liczba skreslen:");
i = 0;
foreach (CustomTestCase tc in testy)
{
string msg;
tc.TestCrossoutsNumber(out msg);
Console.WriteLine("Test " + (i++).ToString() + ":\t" + msg);
}
Console.WriteLine("\n\nMinimalna liczba nieskreslonych syboli:");
i = 0;
foreach (CustomTestCase tc in testy)
{
string msg;
tc.TestMinimumRemainder(out msg);
Console.WriteLine("Test " + (i++).ToString() + ":\t" + msg);
}
}
static CustomTestCase makeTestCase(bool result, int minCrossouts, int minRemainder, string sequence, params string[] patterns)
{
char[] seq = new char[sequence.Length];
for (int i = 0; i < sequence.Length; i++)
seq[i] = sequence[i];
char[][] pat = new char[patterns.GetLength(0)][];
for (int i = 0; i < patterns.GetLength(0); i++)
{
pat[i] = new char[patterns[i].Length];
for (int j = 0; j < patterns[i].Length; j++)
pat[i][j] = patterns[i][j];
}
return new CustomTestCase(seq, pat, result, minCrossouts, minRemainder);
}
}
enum TestResult
{
OK, Timeout, Exception, BadResult, BadCrossoutsNumber, BadMinimumRemainder
}
class CustomTestCase
{
public char[] sequence;
public char[][] patterns;
public bool result;
public int crossoutNumber;
public int minimumRemainder;
public CustomTestCase(char[] seq, char[][] pat, bool res, int cn, int mr)
{
sequence = seq;
patterns = pat;
result = res;
crossoutNumber = cn;
minimumRemainder = mr;
}
public TestResult TestResults(out string message)
{
bool res = false;
int w;
TestResult ret = TestResult.OK;
string msg = "OK";
res = (new CrossoutChecker()).Erasable(sequence, patterns, out w);
if (res != result)
{
ret = TestResult.BadResult;
msg = "BLAD: jest " + res.ToString() + " a powinno byc " + result.ToString();
}
message = msg;
return ret;
}
public TestResult TestCrossoutsNumber(out string message)
{
bool res;
int w = -1;
TestResult ret = TestResult.OK;
string msg = "OK";
res = (new CrossoutChecker()).Erasable(sequence, patterns, out w);
if (w != crossoutNumber)
{
ret = TestResult.BadCrossoutsNumber;
msg = "BLAD: jest " + w.ToString() + " a powinno byc " + crossoutNumber.ToString();
}
message = msg;
return ret;
}
public TestResult TestMinimumRemainder(out string message)
{
int w = -1;
TestResult ret = TestResult.OK;
string msg = "OK";
w = (new CrossoutChecker()).MinimumRemainder(sequence, patterns);
if (w != minimumRemainder)
{
ret = TestResult.BadMinimumRemainder;
msg = "BLAD: jest " + w.ToString() + " a powinno byc " + minimumRemainder.ToString();
}
message = msg;
return ret;
}
}
}