private void button_beginTest_Click(object sender, EventArgs e) { if (this.comboBox_allTests.SelectedIndex >= 0) { if (this.tests.AllTests[this.selectedTestName] == true) { string filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.ShowDialog(); filePath = openFileDialog.FileName; } if (filePath != string.Empty) { if (this.comboBox_allTests.SelectedIndex == 0) { HATestUnit hATestUnit = new HATestUnit(); if (!XmlManager.Load <HATestUnit>(filePath, out hATestUnit)) { filePath = string.Empty; } else { this.button_beginTest.Enabled = false; this.tests.Begin(this.comboBox_allTests.SelectedIndex, this.listBox_testLogs, hATestUnit); } } else if (this.comboBox_allTests.SelectedIndex == 1) { LagrangeInterpolationTestUnit liTestUnit = new LagrangeInterpolationTestUnit(); if (!XmlManager.Load <LagrangeInterpolationTestUnit>(filePath, out liTestUnit)) { filePath = string.Empty; } else { this.button_beginTest.Enabled = false; this.tests.Begin(this.comboBox_allTests.SelectedIndex, this.listBox_testLogs, liTestUnit); } } } } else { this.tests.Begin(this.comboBox_allTests.SelectedIndex, this.listBox_testLogs); } } }
private async Task BeginHeuristicAlgorithmsTest(HATestUnit hATestUnit, ListBox logsBox) { OptimizationAlpha.HeuristicAlgorithms heuristicAlgorithms = new OptimizationAlpha.HeuristicAlgorithms(); logsBox.Items.Add("Test begin"); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); int globalPassCount = 0; for (int i = 0; i < hATestUnit.HATestDatas.Count; i++) { logsBox.Items.Add("Function " + (i + 1).ToString() + " test in progrss:"); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("\tType: " + hATestUnit.HATestDatas[i].Type); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("\tFunctionExpression: " + hATestUnit.HATestDatas[i].FunctionExpression); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); string argumentsSymbols = string.Empty; for (int j = 0; j < hATestUnit.HATestDatas[i].ArgumentsSymbols.Count; j++) { argumentsSymbols += "{ " + hATestUnit.HATestDatas[i].ArgumentsSymbols[j] + " } , "; } logsBox.Items.Add("\tArgumentsSymbols: " + argumentsSymbols); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); string ranges = string.Empty; for (int j = 0; j < hATestUnit.HATestDatas[i].ArgumentsSymbols.Count; j++) { ranges += "{ " + hATestUnit.HATestDatas[i].Ranges[j].Min + " ; " + hATestUnit.HATestDatas[i].Ranges[j].Max + " } , "; } logsBox.Items.Add("\tRanges: " + ranges); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("Process started"); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("Progress: 0 %"); int passCount = 0; for (int j = 0; j < 10; j++) { List <FitnessPoint> results = null; try { results = await heuristicAlgorithms.GetAllOptimalPointsAsync(hATestUnit.HATestDatas[i].Type, hATestUnit.HATestDatas[i].FunctionExpression, hATestUnit.HATestDatas[i].ArgumentsSymbols, hATestUnit.HATestDatas[i].Ranges); } catch { continue; } for (int k = 0; k < results.Count; k++) { string position = string.Empty; for (int l = 0; l < results[k].Axis.Values.Count; l++) { position += Math.Round(results[k].Axis.Values[l], 2, MidpointRounding.AwayFromZero) + " , "; } //logsBox.Items.Add("Position: [ " + position + " ] || Fitness: " + Math.Round(results[k].Fitness, 2, MidpointRounding.AwayFromZero)); this.testLogs.Add("Position: [ " + position + " ] || Fitness: " + Math.Round(results[k].Fitness, 2, MidpointRounding.AwayFromZero)); } if ((results[j].Fitness < hATestUnit.HATestDatas[i].ExpectedValue + 0.02) && (results[j].Fitness > hATestUnit.HATestDatas[i].ExpectedValue - 0.02)) { passCount++; } logsBox.Items[logsBox.Items.Count - 1] = "Progress: " + ((j + 1) * 10).ToString() + " %"; } if (passCount >= 8) { globalPassCount++; //logsBox.Items.Add("Function passed"); this.testLogs.Add("Function passed"); } else { //logsBox.Items.Add("Function fail"); this.testLogs.Add("Function fail"); } //logsBox.Items.Add("======================================================"); this.testLogs.Add("========================================================================="); } logsBox.Items.Add("==========================================================="); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("========================RESULT============================"); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("==========================================================="); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("FUNCTIONS PASS: "******"FUNCTIONS FAIL: " + (hATestUnit.HATestDatas.Count - globalPassCount)); this.testLogs.Add(logsBox.Items[logsBox.Items.Count - 1].ToString()); logsBox.Items.Add("Saving logs to: " + Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\HeuristicAlgorithmsTest_logs.txt"); using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\HeuristicAlgorithmsTest_logs.txt")) { for (int i = 0; i < this.testLogs.Count; i++) { writer.WriteLine(this.testLogs[i]); } } }