public void ReturnsTwoResultsForTwoDisconnected() { // Arrange var validators = new[] { new ValidationConfigurationItem { Name = "0", RequiredValidations = new List <string>() }, new ValidationConfigurationItem { Name = "1", RequiredValidations = new List <string>() }, }; // Act var actual = TopologicalSort.EnumerateAll(validators); // Assert actual = actual.OrderBy(x => string.Join(" ", x)).ToList(); Assert.Equal(2, actual.Count); Assert.Equal(new List <string>() { "0", "1" }, actual[0]); Assert.Equal(new List <string>() { "1", "0" }, actual[1]); }
public void ReturnsSingleResultForPath() { // Arrange var validators = new[] { new ValidationConfigurationItem { Name = "0", RequiredValidations = new List <string>() }, new ValidationConfigurationItem { Name = "1", RequiredValidations = new List <string> { "0" } }, new ValidationConfigurationItem { Name = "2", RequiredValidations = new List <string> { "1" } }, }; // Act var actual = TopologicalSort.EnumerateAll(validators); // Assert var result = Assert.Single(actual); Assert.Equal(new List <string>() { "0", "1", "2" }, result); }
public void ReturnsEmptyListForCycle() { // Arrange var validators = new[] { new ValidationConfigurationItem { Name = "0", RequiredValidations = new List <string> { "1" } }, new ValidationConfigurationItem { Name = "1", RequiredValidations = new List <string> { "2" } }, new ValidationConfigurationItem { Name = "2", RequiredValidations = new List <string> { "0" } }, }; // Act var actual = TopologicalSort.EnumerateAll(validators); // Assert Assert.Empty(actual); }
public void ReturnsNestedEmptyListEmptyGraph() { // Arrange var validators = new ValidationConfigurationItem[0]; // Act var actual = TopologicalSort.EnumerateAll(validators); // Assert Assert.Equal(new List <List <string> > { new List <string>() }, actual); }
public void ThrowsWhenNodeIsMissing() { // Arrange var validators = new[] { new ValidationConfigurationItem { Name = "0", RequiredValidations = new List <string>() }, new ValidationConfigurationItem { Name = "1", RequiredValidations = new List <string> { "2" } }, }; // Act Assert.Throws <KeyNotFoundException>(() => TopologicalSort.EnumerateAll(validators)); }
public void ProducesTutorialOutput() { // Arrange var validators = new[] { new ValidationConfigurationItem { Name = "0", RequiredValidations = new List <string> { "4", "5" } }, new ValidationConfigurationItem { Name = "1", RequiredValidations = new List <string> { "3", "4" } }, new ValidationConfigurationItem { Name = "2", RequiredValidations = new List <string> { "5" } }, new ValidationConfigurationItem { Name = "3", RequiredValidations = new List <string> { "2" } }, new ValidationConfigurationItem { Name = "4", RequiredValidations = new List <string>() }, new ValidationConfigurationItem { Name = "5", RequiredValidations = new List <string>() }, }; var expected = new List <List <string> > { new List <string> { "4", "5", "0", "2", "3", "1" }, new List <string> { "4", "5", "2", "0", "3", "1" }, new List <string> { "4", "5", "2", "3", "0", "1" }, new List <string> { "4", "5", "2", "3", "1", "0" }, new List <string> { "5", "2", "3", "4", "0", "1" }, new List <string> { "5", "2", "3", "4", "1", "0" }, new List <string> { "5", "2", "4", "0", "3", "1" }, new List <string> { "5", "2", "4", "3", "0", "1" }, new List <string> { "5", "2", "4", "3", "1", "0" }, new List <string> { "5", "4", "0", "2", "3", "1" }, new List <string> { "5", "4", "2", "0", "3", "1" }, new List <string> { "5", "4", "2", "3", "0", "1" }, new List <string> { "5", "4", "2", "3", "1", "0" }, }; // Act var actual = TopologicalSort.EnumerateAll(validators); // Assert Assert.Equal( expected.OrderBy(x => string.Join(" ", x)), actual.OrderBy(x => string.Join(" ", x))); }