/// <summary> /// Works out the SCS of the string collection passed into the object /// </summary> /// <returns>The string that represents the Shortest Common Superstring</returns> public string GetGreedySCS() { //while there is more than 1 string in the collection we match and merge. //when there is 1 string left in the collection, that is Shortest Common Superstring while (fragmentCollection.Count > 1) { MaxOverlapFinder maxFinder = new MaxOverlapFinder(fragmentCollection); var result = maxFinder.FindMaxOverlap(); try { //delete item2 first because it will always be higher index that item1 //else get bug where item1 deleted then the indexes of the list change and deleting index item2 //is not the right index anymore because the indexes have changed after the first item removal fragmentCollection.RemoveAt(result.Item2); fragmentCollection.RemoveAt(result.Item1); fragmentCollection.Add(result.Item3); } catch (IndexOutOfRangeException e) { Console.WriteLine("Error removing or adding from the collection. " + e.Message); } } //FIXME better way of doing this? return(string.Join(" ", fragmentCollection.ToArray())); }
public void FindMaxOverlapTest() { //Arrange string[] input = { "all is well", "ell that en", "hat end", "t ends well" }; List <string> collection = new List <string>(input); int expectedIndex1 = 1; int expectedIndex2 = 2; string expectedMergedString = "ell that end"; //Act GenomeSequencing.MaxOverlapFinder maxFinder = new GenomeSequencing.MaxOverlapFinder(collection); var result = maxFinder.FindMaxOverlap(); //Assert Assert.AreEqual(expectedIndex1, result.Item1); Assert.AreEqual(expectedIndex2, result.Item2); Assert.AreEqual(expectedMergedString, result.Item3); }