public void SeedsToUseReturnsCorrectNumberOfSeeds() { var numberOfSeeds = 6; var seedsToUse = SapsUtils.SeedsToUse(numberOfSeeds, 42); seedsToUse.Count().ShouldBe(numberOfSeeds); }
public void CreateParameterTreeReturnsIndependentSapsParameters() { var tree = SapsUtils.CreateParameterTree(); // Check root is an and node, i.e. independent parameters follow. var root = tree.Root; (root is AndNode).ShouldBeTrue("Parameters are not independent."); // Try and get all parameters needed for Saps from those node's children. var alpha = root.Children.Single(child => TestUtils.RepresentsParameter(child, "alpha")) as IParameterNode; var rho = root.Children.Single(child => TestUtils.RepresentsParameter(child, "rho")) as IParameterNode; var ps = root.Children.Single(child => TestUtils.RepresentsParameter(child, "ps")) as IParameterNode; var wp = root.Children.Single(child => TestUtils.RepresentsParameter(child, "wp")) as IParameterNode; // Check that no other parameters exist in the tree. (root.Children.Count() == 4 && !root.Children.Any(child => child.Children.Any())).ShouldBeTrue("Only 4 parameters are needed for SAPS."); // Check parameter domains. (alpha.Domain is LogDomain).ShouldBeTrue("alpha should be distributed logarithmically."); TestUtils.CheckRange((LogDomain)alpha.Domain, "alpha", expectedMinimum: 1.01, expectedMaximum: 1.4); (rho.Domain is ContinuousDomain).ShouldBeTrue("rho should be distributed uniformly."); TestUtils.CheckRange((ContinuousDomain)rho.Domain, "rho", expectedMinimum: 0, expectedMaximum: 1); (ps.Domain is ContinuousDomain).ShouldBeTrue("ps should be distributed uniformly."); TestUtils.CheckRange((ContinuousDomain)ps.Domain, "ps", 0, 0.2); (wp.Domain is ContinuousDomain).ShouldBeTrue("wp should be distributed uniformly."); TestUtils.CheckRange((ContinuousDomain)wp.Domain, "wp", 0, 0.06); }
public void CreateInstancesIgnoresFilesNotInCnfFormat() { // Call method. var instances = SapsUtils.CreateInstances(this._instanceFolder, 1, 42); // Check that no non-cnf file has been translated into an instance. var instancePaths = instances.Select(instance => instance.Path); instancePaths.Any(path => SapsUtilsTests.NonCnfFileNames.Any(file => path.Contains(file))) .ShouldBeFalse("Not all non-cnf files have been ignored."); }
public void CreateInstancesCorrectlyExtractsPathsToCnfFiles() { // Call method. var instances = SapsUtils.CreateInstances(this._instanceFolder, 1, 42); // Check that file names of instances match the complete paths of all .cnf files. var expectedPaths = SapsUtilsTests.CnfFileNames.Select(name => this._instanceFolder + Path.DirectorySeparatorChar + name); var instancePaths = instances.Select(instance => instance.Path); expectedPaths.ShouldBe( instancePaths, true, $"{TestUtils.PrintList(instancePaths)} should have been equal to {TestUtils.PrintList(expectedPaths)}."); }
public void CreateInstancesPrintsMessageIfItCannotOpenFolder() { TestUtils.CheckOutput( action: () => { // Call CreateInstances with a non existant directory path. try { SapsUtils.CreateInstances("foobarFolder", 1, 42); } catch (DirectoryNotFoundException) { // This is expected. } }, check: consoleOutput => { // Check that information about it is written to console. StringReader reader = new StringReader(consoleOutput.ToString()); reader.ReadLine().ShouldContain("foobarFolder", "The problematic path did not get printed."); reader.ReadLine().ShouldBe("Cannot open folder.", "Cause of exception has not been printed."); }); }
public void CreateInstancesThrowsExceptionIfItCannotOpenFolder() { Exception exception = Assert.Throws <DirectoryNotFoundException>( () => { SapsUtils.CreateInstances("foobarFolder", 1, 42); }); }