/
A.cs
109 lines (95 loc) · 3.3 KB
/
A.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// B.exe must be place in C:\
namespace A
{
public class A
{
public static int Main(String[] args)
{
//String cubestring = " sizeN, sizeM, values......."
String test_1 = "2 2 1 1 1 1";
String test_2 = "2 2 1 2 2 1";
String test_3 = "2 2 1 2 2 3";
String fileName = "C:\\";
System.Diagnostics.Process process = new System.Diagnostics.Process();
if (args.Length == 0)
{
System.Console.WriteLine("Please enter a filename.");
return 1;
}
try
{
fileName += args[0];
//System.Console.WriteLine(fileName);
}
catch (System.FormatException)
{
System.Console.WriteLine("Please enter a filename.");
return 1;
}
process.StartInfo.FileName = fileName;
// to add another cube to test add aother else if (Tester(process,cube string, expected)) Tester will return false if B is working as intented
if (Tester(process, test_1, true)) return 0;
else if (Tester(process, test_2, true)) return 0;
else if (Tester(process, test_3, false))
return 0;
else
{
System.Console.WriteLine("ok");
return 1;
}
}
//function for printing the cube
public static string printcube(string cube)
{
string returnstring = " ";
int temp = 2;
string[] temp1 = cube.Split(new Char[] { ' ' });
int sizeN = System.Convert.ToInt16(temp1[0]);
int sizeM = System.Convert.ToInt16(temp1[1]);
for (int i = 0; i < sizeN; i++)
{
for (int y = 0; y < sizeM; y++)
{
returnstring += " " + temp1[temp];
temp++;
}
returnstring += " \n ";
}
return returnstring;
}
//tester method to check if B.exe is working
public static bool Tester(System.Diagnostics.Process process, string cube, bool expected)
{
int result;
string tempCube;
process.StartInfo.Arguments = cube;
process.Start();
process.WaitForExit();
result = process.ExitCode;
if (result == 1 && expected == true)
{
System.Console.WriteLine("not ok:");
tempCube = printcube(cube);
System.Console.WriteLine(tempCube);
System.Console.WriteLine("returned:no");
System.Console.WriteLine("expected:yes");
return true;
}
else if (result == 0 && expected == false)
{
System.Console.WriteLine("not ok:");
tempCube = printcube(cube);
System.Console.WriteLine(tempCube);
System.Console.WriteLine("returned:yes");
System.Console.WriteLine("expected:no");
return true;
}
else
return false;
}
}
}