Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- using System.Threading.Tasks;
- namespace ConsoleApplication19
- {
- class Program
- {
- public static Random ran = new Random();
- private static readonly char[] alphaNum = "qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM".ToCharArray();
- private const int MAX_LENGTH = 50;
- private const int SPACE_CHANCE = 6;
- private const string JAVA_EXE = "c:\\Program Files\\Java\\jre6\\bin\\java.exe";
- private const string WORK_DIR = "D:\\src\\csc349\\lab5\\";
- static void Main(string[] args)
- {
- while (true)
- {
- string source = getRandomWord();
- string target = getRandomWord();
- var myStart = new ProcessStartInfo(JAVA_EXE, string.Format("-cp out\\production\\csc349lab5 -ea EditDistance"));
- var goodStart = new ProcessStartInfo(JAVA_EXE, string.Format("-cp GivenEditDistance.jar -ea EditDistance"));
- var outTask = getOutput(myStart, source, target);
- var goodTask = getOutput(goodStart, source, target);
- var myOut = outTask.Result;
- var goodOut = goodTask.Result;
- if (!linewiseEqual(myOut, goodOut))
- {
- Console.WriteLine();
- Console.WriteLine(source);
- Console.WriteLine(target);
- }
- else
- {
- Console.Write(".");
- }
- }
- }
- readonly static char[] newlineChars = new[] { '\n', '\r' };
- private static bool linewiseEqual(string a, string b)
- {
- string[] aes = a.Split(newlineChars, StringSplitOptions.RemoveEmptyEntries);
- string[] bes = b.Split(newlineChars, StringSplitOptions.RemoveEmptyEntries);
- if (aes.Length != bes.Length)
- return false;
- for (int i = 0; i < aes.Length; i++)
- {
- if (!string.Equals(aes[i], bes[i]))
- return false;
- }
- return true;
- }
- private static Task<string> getOutput(ProcessStartInfo start, string source, string target)
- {
- return Task.Factory.StartNew<string>(() =>
- {
- start.WorkingDirectory = WORK_DIR;
- start.RedirectStandardInput = true;
- start.RedirectStandardOutput = true;
- start.UseShellExecute = false;
- var p = Process.Start(start);
- p.StandardInput.WriteLine(source);
- p.StandardInput.WriteLine(target);
- p.WaitForExit();
- return p.StandardOutput.ReadToEnd();
- });
- }
- private static string getRandomWord()
- {
- int length = ran.Next(MAX_LENGTH);
- char[] chars = new char[length];
- for (int i = 0; i < length; i++)
- {
- bool isSpace = ran.Next(SPACE_CHANCE) == 0;
- if (isSpace)
- chars[i] = ' ';
- else
- chars[i] = alphaNum[ran.Next(alphaNum.Length)];
- }
- return new string(chars);
- }
- }
- }
Add Comment
Please, Sign In to add comment