public void MakeConcatenated_LastElementIsSuffix() { var suffix = BlobBuilder.Build("a"); var prefixes = new CompositionAlternatives2("de", new List <BlobComposition>() { new BlobComposition(new List <Blob> { BlobBuilder.Build("d"), BlobBuilder.Build("e") }), new BlobComposition(new List <Blob> { new Blob("de", new List <string> { "de", "ed" }) }), }); var actual = CompositionAlternatives2.GetCombined(prefixes, suffix); Assert.Equal("ade", actual.CharPool); Assert.Equal(actual.BlobCompositions.Count, prefixes.BlobCompositions.Count); for (var i = 0; i < prefixes.BlobCompositions.Count; i++) { Assert.Equal(actual.BlobCompositions[i].OrderedBlobs.First().CharPool, prefixes.BlobCompositions[i].OrderedBlobs.First().CharPool); //blobs are equal Assert.Equal(actual.BlobCompositions[i].OrderedBlobs.Last().CharPool, suffix.CharPool); //blobs are equal } }
public void CompositionAlternatives2_PrefixConstructor(CompositionAlternatives2 prefixes, Blob suffix, string[] expectedBlobae) { var actual = CompositionAlternatives2.GetCombined(prefixes, suffix); var iEnumerable = actual.BlobCompositions.Select(x => string.Join(",", x.OrderedBlobs.Select(y => y.CharPool))).ToList(); Assert.Equal(expectedBlobae, iEnumerable); }
public void CompositionAlternatives2_PrefixConstructor_SuffixArgumentValidation() { var prefixes = new CompositionAlternatives2("a", new List <BlobComposition> { new BlobComposition(new List <Blob> { BlobBuilder.Build("a") }) }); Blob badSuffix = null; Assert.Throws <ArgumentException>("suffix", () => CompositionAlternatives2.GetCombined(prefixes, badSuffix)); }
public void CompositionAlternatives2_PrefixConstructor_PrefixArgumentValidation() { Assert.Throws <ArgumentException>("prefixes", () => CompositionAlternatives2.GetCombined(null, BlobBuilder.Build("a"))); }
private CompositionAlternatives2 RecursiveShrinking( string anagramCharPool, IList <Blob> dictionary, Memo2 memo, int level, int maxLevel) { if (memo.Has(anagramCharPool)) { return(memo.Get(anagramCharPool)); } if (level > maxLevel) { return(CompositionAlternatives2.DeadEnd); } var localBlackList = new List <Blob>(); foreach (var wordEquivalencyClass in dictionary) { if (localBlackList.Contains(wordEquivalencyClass)) { //this is a "big bother of an instant looser so it is a bigger looser" continue; } var difference = anagramCharPool.SubtractChars(wordEquivalencyClass.CharPool); switch (difference) { case null: //negative // this is an instant looser localBlackList.AddRange(wordEquivalencyClass.BigBrothers); continue; case "": // solution var solution = new BlobComposition(new List <Blob> { wordEquivalencyClass }); memo.Add(anagramCharPool, solution); break; default: //inconclusive var sols = CompositionAlternatives2.GetCombined(RecursiveShrinking(difference, dictionary, memo, level++), wordEquivalencyClass); if (!sols.IsDeadend) { memo.AddMultiple(anagramCharPool, sols); } break; } } if (!memo.Has(anagramCharPool)) { memo.AddDeadEnd(anagramCharPool); } return(memo.Get(anagramCharPool)); }