public void Setup() { comparer = new MaximizingComparer <TestIntegerEvaluableState>(); generator = new TestLinearIntegerSuccessorGenerator(); climber = new ClimberConfiguration <TestIntegerEvaluableState, int>() .ComparesUsing(new MaximizingComparer <TestIntegerEvaluableState>()) .GeneratesSuccessorsWith(generator) .Build(); }
public void TestPerformOptimizationReturnsLocalExtrema() { TestIntegerEvaluableState initial = new TestIntegerEvaluableState(2); TestIntegerEvaluableState result; generator = new TestIntegerLocalMaximaSuccessorGenerator(); picker = new ClimberSuccessorSelector <TestIntegerEvaluableState, int>(generator, comparer); algorithm = new LocalClimberAlgorithm <TestIntegerEvaluableState, int>(picker); climber = new ClimberConfiguration <TestIntegerEvaluableState, int>() .ComparesUsing(comparer) .GeneratesSuccessorsWith(generator) .Build(); result = climber.Optimize(initial); Assert.AreEqual(50, result.Value); }
public void TestBuildCreatesClimberWhenValid() { IComparer <TestIntegerEvaluableState> comparer = new MinimizingComparer <TestIntegerEvaluableState>(); ClimberConfiguration <TestIntegerEvaluableState, int> config = ClimberConfiguration <TestIntegerEvaluableState, int> .Create() .GeneratesSuccessorsWith(generator) .ComparesUsing(comparer); IHillClimber <TestIntegerEvaluableState, int> climber = null; try { climber = config.Build(); } catch { Assert.Fail("Build threw an exception"); } Assert.IsNotNull(climber); }
public void TestBuildThrowsCorrectExceptionWhenInvalid() { IComparer <TestIntegerEvaluableState> comparer = new MinimizingComparer <TestIntegerEvaluableState>(); ClimberConfiguration <TestIntegerEvaluableState, int> config = ClimberConfiguration <TestIntegerEvaluableState, int> .Create(); IHillClimber <TestIntegerEvaluableState, int> climber = null; bool caught = false; try { climber = config.Build(); } catch (ConfigurationException) { caught = true; } Assert.IsTrue(caught); Assert.IsNull(climber); }