Microsoft Interview Question for Software Engineer in Tests
- 2of 2 votes
AnswersThe object of this exercise is to fix 3 known issue with the existing code, and add a new feature to the tool.
- Purushotham Kumar July 05, 2013 in Ireland for CPL Recruitment Team @Microsoft
The known issues to address are:
· The current implementation of the tool incorrectly ignores white space (spaces and tabs) between words, which is a bug. Modify the code so that white space differences are correctly detected
· Tool doesn't report difference if second file is larger than first file
· For large input files the tool consumes considerable RAM. Modify tool to address this performance bug
The new feature to implement is:
· Add a new command line switch -i and functionality to allow case-insensitive comparison
Running the tool requires you to supply 2 command line arguments – these will be the paths to 2 text files that should be compared. You are responsible for creating this test data.
/*
* New Requirement:
* - Add a new command line switch -i and functionality to allow case-insensitive comparison.
*
* Issues to fix:
* - The current implementation of the tool incorrectly ignores white space (spaces and tabs) between words, which is a bug.
* Modify the code so that all white space differences are correctly detected and reported along with differences in words.
* - Tool doesn't report difference if second file is larger than first file.
* - For large input files the tool consumes considerable RAM. Modify tool to address this performance bug.
*
* Please ensure you include all test files that you create for each of your test cases along with your submission.
*/
namespace CsDiff
{
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
if (!ProcessArgs(args))
{
return;
}
using (FileReader sourceFile = new FileReader(args[0]))
using (FileReader targetFile = new FileReader(args[1]))
{
IEnumerator<string> sourceEnum = sourceFile.Words.GetEnumerator();
IEnumerator<string> targetEnum = targetFile.Words.GetEnumerator();
for (int word = 1; sourceEnum.MoveNext() && targetEnum.MoveNext(); word++)
{
if (sourceEnum.Current != targetEnum.Current)
{
Console.WriteLine("Difference at position {0}: '{1}' different to '{2}'",word,sourceEnum.Current, targetEnum.Current);
}
}
}
}
static bool ProcessArgs(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Please specify [source] and [target] file paths");
return false;
}
for (int arg = 0; arg <= 1; arg++)
{
if (String.IsNullOrEmpty(args[arg]) || !File.Exists(args[arg]))
{
Console.WriteLine("File '{0}' not found", args[arg]);
return false;
}
}
return true;
}
}
public class FileReader : IDisposable
{
string[] words;
public FileReader(string path)
{
string fileData = File.ReadAllText(path);
words = fileData.Split(new char[] { ' ', '\t' });
}
public IEnumerable<string> Words
{
get
{
return this.words;
}
}
public void Dispose()
{
}
}
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test
Country: Ireland
Interview Type: Written Test