public void calculate() { int _inputDataSize = this.inputData.Length; int _operatorCombinationCount = (int)Math.Round(Math.Pow(operatorsCount, _inputDataSize - 1)); PermutationIterator _permutationInterator = new PermutationIterator(_inputDataSize); while (_permutationInterator.MoveNext()) { for (int _opIndex = 0; _opIndex < _operatorCombinationCount; _opIndex++) { int _temp = _opIndex; double[] _sortedInputData = new double[_inputDataSize]; for (int i = 0; i < _inputDataSize; i++) { _sortedInputData[i] = this.inputData[_permutationInterator.Current[i]]; } int[] _opList = new int[_inputDataSize - 1]; for (int j = 0; j < _inputDataSize - 1; j++) { int _op = _temp % operatorsCount; _temp /= operatorsCount; _opList[j] = _op; } compute1(_sortedInputData, _opList); compute2(_sortedInputData, _opList); compute3(_sortedInputData, _opList); compute4(_sortedInputData, _opList); compute5(_sortedInputData, _opList); } } }
public void Enumerator_test() { // Arrange var sut = new PermutationIterator <int>(new[] { 1, 2, 3, 4 }, true); // Act var enumerator = sut.GetEnumerator(); }
public void All_permutations_generated_when_all_elements_are_the_same() { // Arrange var sut = new PermutationIterator <int>(new[] { 5, 5, 5 }, true); // Act var result = sut.ToList(); // Assert result.Should() .HaveCount(6).And .AllBeEquivalentTo(new[] { 5, 5, 5 }); }
public void All_permutations_generated() { // Arrange var sut = new PermutationIterator <int>(new[] { 1, 2, 3 }, true); var expected = new List <int[]> { new[] { 1, 2, 3 }, new[] { 1, 3, 2 }, new[] { 2, 1, 3 }, new[] { 2, 3, 1 }, new[] { 3, 1, 2 }, new[] { 3, 2, 1 } }; // Act var result = sut.ToList(); // Assert // This FluentAssertion is based on: // https://stackoverflow.com/questions/68527627/fluent-assertions-equivalency-of-two-lists-of-arrays-with-arrays-needing-stric result.Should().BeEquivalentTo(expected, options => options .WithStrictOrderingFor(info => info.RuntimeType == typeof(int[]))); }