public void TestThatWhenThereIsNoDifferenceBetweenVectorsGetHammingDistanceReturns0() { var vector1 = new List <int> { 0, 0, 1, 0, 1, 1, 0 }; var vector2 = new List <int> { 0, 0, 1, 0, 1, 1, 0 }; var result = hammingDistance.GetHammingDistance(vector1, vector2); Assert.AreEqual(0, result); }
public void TestZeroDistanceDifferentSources(string source1, string source2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(source1, source2); Assert.That(distance, Is.EqualTo(0)); }
public void TestZeroDistanceSimilarSources(byte[] data1, byte[] data2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(data1, data2); Assert.That(distance, Is.EqualTo(0)); }
public void TestDistanceByFiles(string filePath1, string filePath2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(filePath1, filePath2); Assert.That(distance, Is.EqualTo(2)); }
public void TestDistanceByStrings(string source1, string source2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(source1, source2); Assert.That(distance, Is.EqualTo(2)); }
public static int GetDistances(string s, string t, FuzzyAlgorithm algorithm = FuzzyAlgorithm.LevenshteinDistance) { int distance = 100000; switch (algorithm) { case FuzzyAlgorithm.LevenshteinDistance: distance = LevenshteinDistance.GetLevenshteinDistance(s, t); break; case FuzzyAlgorithm.DamerauLevenshteinDistance: distance = DamerauLevenshteinDistance.GetDamerauLevenshteinDistance(s, t); break; case FuzzyAlgorithm.HammingDistance: distance = HammingDistance.GetHammingDistance(s, t); break; default: distance = LevenshteinDistance.GetLevenshteinDistance(s, t); break; } return(distance); }
public void TestDifferentLengthSource(byte[] data1, byte[] data2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(data1, data2); Assert.That(hd.SourceStatus, Is.EqualTo(Const.UNEQUAL_LENGTH)); Assert.That(distance, Is.Not.EqualTo(0)); }
public void TestOnlyOneSource(string source1) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(source1, null); Assert.That(hd.SourceStatus, Is.EqualTo(Const.INSUFFICIENT_SOURCE)); Assert.That(distance, Is.Not.EqualTo(0)); }
public void TestFileNotFound(string source1, string source2) { HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(source1, source2); Assert.That(hd.SourceStatus, Is.EqualTo(Const.FILE_NOT_FOUND)); Assert.That(distance, Is.Not.EqualTo(0)); }
/// <summary> /// Show simple main menu /// </summary> /// <param name="source1">data from first argument parameters</param> /// <param name="source2">data from second argument parameters</param> /// <returns>TRUE if user want to do another calculation /// FALSE if user want to quit the application</returns> private static bool DisplayMenu(string source1, string source2) { //show the menu Console.WriteLine("HAMMING DISTANCE CALCULATOR"); Console.WriteLine(""); Console.WriteLine("Input Sources"); Console.WriteLine(""); Console.WriteLine("*. Input String Manually"); // get data directly from keyboard input Console.WriteLine("*. Input from Full Path of Text File (Must text file - *.txt)"); // get data from text file content Console.WriteLine("*. Input from Full Path of File (any file format except text file)"); // get data from converting the whole file into byte array Console.WriteLine(""); // No arguments, set the sources based on user input if (string.IsNullOrEmpty(source1) && string.IsNullOrEmpty(source2)) { Console.Write("Input Source 1 : "); source1 = Console.ReadLine(); Console.Write("Input Source 2 : "); source2 = Console.ReadLine(); } else { Console.WriteLine("Input Source 1 : {0}", source1); Console.WriteLine("Input Source 1 : {0}", source2); } if (!string.IsNullOrEmpty(source1) && !string.IsNullOrEmpty(source2)) { // init hamming distance, calculate based by sources var HammingDistanceObject = new HammingDistance(); double distance = HammingDistanceObject.GetHammingDistance(source1, source2); // distance should be >= 0 if (distance >= 0) { Console.WriteLine("\nDistance is : " + distance); Console.WriteLine("Calc. Time is : " + HammingDistanceObject.ProcessTime.Duration()); } else // else, found some error during calculate the distance { Console.WriteLine("\nGet Hamming Distance Failed!"); Console.WriteLine("Source Status : " + HammingDistanceObject.SourceStatus); } } else { Console.WriteLine("\nInsufficient arguments"); } // press key to do another calculation, otherwise quite application Console.Write("\nPress ENTER to retry, otherwise quit application.."); if (Console.ReadKey().Key != ConsoleKey.Enter) { return(false); } return(true); }
public void TestZeroDistanceByHugeFiles(string filePath1, string filePath2, int fileSizeInMB) { //Check if files is exist with the desired size FileValidator(filePath1, filePath2, fileSizeInMB); // init object and do calculation HammingDistance hd = new HammingDistance(); double distance = hd.GetHammingDistance(filePath1, filePath2); // ideally, the timespan for calculation is 1% per size of file. // e.g if size is 1000 mbs the timespan should be less than 10 seconds // int desiredTime = fileSizeInMB / 100; int desiredTime = fileSizeInMB / 50; // to be safe, create 2% instead Assert.That(distance, Is.GreaterThanOrEqualTo(0)); Assert.That(hd.ProcessTime, Is.LessThan(TimeSpan.FromSeconds(desiredTime))); }