public void Addition(int x, int y, Calculator calculator, int answer) { "Given the number 1" .x(() => { _testOutputHelper.WriteLine($"{_testCase.GetType().Name}: {_testCase.DisplayName}"); x = 1; }); "And the number 2" .x(() => { _testOutputHelper.WriteLine($"{_testCase.GetType().Name}: {_testCase.DisplayName}"); y = 2; }); "And a calculator" .x(() => { _testOutputHelper.WriteLine($"{_testCase.GetType().Name}: {_testCase.DisplayName}"); calculator = new Calculator(); }); "When I add the numbers together" .x(() => { _testOutputHelper.WriteLine($"{_testCase.GetType().Name}: {_testCase.DisplayName}"); answer = calculator.Add(x, y); }); "Then the answer is 3" .x(() => { _testOutputHelper.WriteLine($"{_testCase.GetType().Name}: {_testCase.DisplayName}"); Assert.Equal(3, answer); }); }
/// <inheritdoc/> public override string Serialize(ITestCase testCase) { if (testCase.GetType() == XunitTestCaseType) { var xunitTestCase = (XunitTestCase)testCase; var className = testCase.TestMethod?.TestClass?.Class?.Name; var methodName = testCase.TestMethod?.Method?.Name; if (className != null && methodName != null && (xunitTestCase.TestMethodArguments == null || xunitTestCase.TestMethodArguments.Length == 0)) { return($":F:{className.Replace(":", "::")}:{methodName.Replace(":", "::")}:{(int)xunitTestCase.DefaultMethodDisplay}:{(int)xunitTestCase.DefaultMethodDisplayOptions}:{testCase.TestMethod.TestClass.TestCollection.UniqueID.ToString("N")}"); } } return(base.Serialize(testCase)); }
private void RunCaseSync(ITestCase cp) { this.mCurrentCaseExecuted = 0; this.mCurrentCaseFailed = 0; this.mCurrentCaseExecutedTime = 0; PAS.AutoTest.Performance.TestCase.Log.StartUpdateSync(); // start to log data. cp.Label = this.tbLabel.Text.Trim(); cp.Reset(); if (cp != null) { for (int i = 0; i < cp.Concurrent; i++) { ITestCase tc = Activator.CreateInstance(cp.GetType()) as ITestCase; tc.Label = cp.Label; tc.Repeat = cp.Repeat; tc.ExecutedTime = cp.ExecutedTime; tc.FunctionName = cp.FunctionName; tc.Executed = cp.Executed; tc.Repeat = cp.Repeat; tc.SingleCallCompleteEvent += new SingleCallCompleteEventHandler(tc_SingleCallCompleteEvent); tc.TestCaseCompleteEvent += new TestCaseCompleteEventhandler(tc_TestCaseCompleteEvent); Thread t = new Thread(new ParameterizedThreadStart(this.RunCase)); t.Priority = ThreadPriority.Highest; this.mWorkingThread.Add(t); t.Start(tc); } if (this.mUIThread != null && this.mUIThread.ThreadState == ThreadState.Running) { this.mUIThread.Abort(); } this.mUIThread = new Thread(this.UpdateUISync); this.mUIThread.Start(cp); } }
private void RunCaseSync(ITestCase cp) { this.mCurrentCaseExecuted = 0; this.mCurrentCaseFailed = 0; this.mCurrentCaseExecutedTime = 0; PAS.AutoTest.Performance.TestCase.Log.StartUpdateSync(); // start to log data. cp.Label = this.tbLabel.Text.Trim(); cp.Reset(); if (cp != null) { for (int i = 0; i < cp.Concurrent; i++) { ITestCase tc = Activator.CreateInstance(cp.GetType()) as ITestCase; tc.Label = cp.Label; tc.Repeat = cp.Repeat; tc.ExecutedTime = cp.ExecutedTime; tc.FunctionName = cp.FunctionName; tc.Executed = cp.Executed; tc.Repeat = cp.Repeat; tc.SingleCallCompleteEvent +=new SingleCallCompleteEventHandler(tc_SingleCallCompleteEvent); tc.TestCaseCompleteEvent += new TestCaseCompleteEventhandler(tc_TestCaseCompleteEvent); Thread t = new Thread(new ParameterizedThreadStart(this.RunCase)); t.Priority = ThreadPriority.Highest; this.mWorkingThread.Add(t); t.Start(tc); } if (this.mUIThread !=null && this.mUIThread.ThreadState == ThreadState.Running) this.mUIThread.Abort(); this.mUIThread = new Thread(this.UpdateUISync); this.mUIThread.Start(cp); } }
protected override double RunSolverOneStep(int TimestepNo, double phystime, double dt) { Stopwatch globalWatch = new Stopwatch(); globalWatch.Start(); /* * Configuration options */ // Only applies to subdivision-based quadrature (brute force and adaptive) int[] divisions = new int[] { (int)testCase.GridSize }; // Only applies to adaptive quadrature int leafDivisions = -1; // Only applies to regularized quadrature double[] widths = new double[] { double.NaN }; int[] vanishingMonents = new int[] { int.MinValue }; int[] continuousDerivatives = new int[] { int.MinValue }; // Only applies to HMF quadrature LineSegment.IRootFindingAlgorithm rootFindingAlgorithm; /* * ENTER CONFIGURATION HERE */ // Export options int plotSuperSampling = 3; bool logVolumeNodes = true; int logVolumeNodes_selectedCell = -1; bool logSurfaceNodes = false; bool logConsole = true; int selectedShift = -1; // Quadrature variant Modes mode = Modes.SayeGaussRules; int[] orders = new int[] { 3 }; //Modes mode = Modes.HMFClassic; //int[] orders = new int[] { 3, 4, 5, 6, 7, 8 }; //LevelSetSurfaceQuadRuleFactory.RestrictNodes = false; //LevelSetSurfaceQuadRuleFactory.UseGaussNodes = true; //LevelSetVolumeQuadRuleFactory.RestrictNodes = false; //LevelSetVolumeQuadRuleFactory.UseGaussNodes = true; //LevelSetVolumeQuadRuleFactory.NodeCountSafetyFactor = 1.0; //Modes mode = Modes.HMFClassic; //int[] orders = new int[] { 1 }; //LevelSetSurfaceQuadRuleFactory.RestrictNodes = false; //LevelSetSurfaceQuadRuleFactory.UseGaussNodes = true; //LevelSetVolumeQuadRuleFactory.RestrictNodes = false; //LevelSetVolumeQuadRuleFactory.UseGaussNodes = true; //LevelSetVolumeQuadRuleFactory.NodeCountSafetyFactor = 1.0; //Modes mode = Modes.HMFOneStepGaussAndStokes; //int[] orders = new int[] { 2, 4, 6, 8, 10 }; //Modes mode = Modes.Adaptive; //int[] orders = new int[] { 1 }; //int[] divisions = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; //int leafDivisions = 1; //Modes mode = Modes.Regularized; //int[] orders = Enumerable.Range(1, 20).Select(k => 2 * k - 1).ToArray(); //widths = new double[] { 0.1, 0.2 }; //vanishingMonents = new int[] { 0, 2, 4, 6 }; //continuousDerivatives = new int[] { 1, 3, 5 }; //Modes mode = Modes.BruteForce; //int[] orders = new int[] { 1 }; //divisions = new int[] { 0, 1, 2, 3, 4 }; //Modes mode = Modes.Standard; //int[] orders = Enumerable.Range(1, 20).Select(k => 2 * k - 1).ToArray(); if (levelSet is IAnalyticLevelSet) { rootFindingAlgorithm = new AnalyticLevelSetRootFindingAlgorithm(); } else { rootFindingAlgorithm = new LineSegment.SafeGuardedNewtonMethod(1e-14); //rootFindingAlgorithm = new LineSegment.GSLRootFindingAlgorithm(1e-14); } /* * END OF CONFIGURATION */ SubGrid cutCellGrid = levelSetTracker.Regions.GetCutCellSubGrid(); CellMask cellMask = CellMask.GetFullMask(GridData); SubGrid selectedSubGrid = new SubGrid(cellMask); testCase.ScaleShifts(0.5 * testCase.GridSpacing); double hBase = ((BoSSS.Foundation.Grid.Classic.GridData)GridData).Cells.h_maxGlobal; string logName = "" + testCase.GetType().Name + "_" + Grid.RefElements[0].GetType().Name + "_" + testCase.GridSize + "_" + mode.ToString(); if (logConsole) { string filename = logName + "_stdout.txt"; ilPSP.Environment.StdOut.WriterS.Add(new StreamWriter(filename)); } Console.WriteLine("Test case: " + testCase.GetType().Name); var errorMap = new Dictionary <Tuple <int, int, double, int, int>, List <Tuple <double, double, int> > >(); foreach (int division in divisions) { foreach (int order in orders) { foreach (double width in widths) { foreach (int vanishingMoment in vanishingMonents) { foreach (int continuousDerivative in continuousDerivatives) { errorMap[Tuple.Create(division, order, width, vanishingMoment, continuousDerivative)] = new List <Tuple <double, double, int> >(); } } } } } int i = 1; while (testCase.ProceedToNextShift()) { Console.WriteLine("Processing shift " + i + " of " + testCase.NumberOfShifts); if (selectedShift > 0 && i != selectedShift) { i++; continue; } cutCellGrid = new SubGrid( levelSetTracker.Regions.GetCutCellSubGrid().VolumeMask.Intersect( selectedSubGrid.VolumeMask)); double referenceValue = SetUpConfiguration(); StreamWriter volumeNodesLog = null; StreamWriter surfaceNodesLog = null; if (plotSuperSampling >= 0 && i == 1) { PlotCurrentState(0.0, 0, plotSuperSampling, cutCellGrid); } Console.WriteLine(); foreach (int division in divisions) { Console.WriteLine("Number of divisions: " + division); if (logVolumeNodes) { string filename = Path.Combine( Path.GetFullPath("."), "volumeNodes_" + testCase.GetType().Name + "_" + i + "_" + division); volumeNodesLog = new StreamWriter(filename + ".txt"); if (GridData.SpatialDimension == 2) { volumeNodesLog.WriteLine("Cell\tNode\tx\ty\tweight"); } else { volumeNodesLog.WriteLine("Cell\tNode\tx\ty\tz\tweight"); } } if (logSurfaceNodes) { string filename = Path.Combine( Path.GetFullPath("."), "surfaceNodes_" + testCase.GetType().Name + "_" + i + "_" + division); surfaceNodesLog = new StreamWriter(filename + ".txt"); if (Grid.SpatialDimension == 2) { surfaceNodesLog.WriteLine("Cell\tNode\tx\ty\tweight"); } else { surfaceNodesLog.WriteLine("Cell\tNode\tx\ty\tz\tweight"); } } foreach (int order in orders) { Console.WriteLine("Order: " + order); foreach (double width in widths) { foreach (int vanishingMoment in vanishingMonents) { foreach (int continuousDerivative in continuousDerivatives) { var result = PerformConfiguration( mode, order, division, volumeNodesLog, surfaceNodesLog, leafDivisions, vanishingMoment, continuousDerivative, width, hBase, rootFindingAlgorithm, logVolumeNodes_selectedCell); double error = Math.Abs(result.Item1 - referenceValue); var key = Tuple.Create( division, order, width, vanishingMoment, continuousDerivative); errorMap[key].Add(Tuple.Create( result.Item1 + testCase.Solution - referenceValue, error, result.Item2)); } } } } if (volumeNodesLog != null) { volumeNodesLog.Close(); } if (surfaceNodesLog != null) { surfaceNodesLog.Close(); } } Console.WriteLine(); i++; } testCase.ResetShifts(); using (StreamWriter log = new StreamWriter(logName + ".txt")) { log.WriteLine("Divisions\tOrder\tWidth\tMoments\tDerivatives\tResult\tMeanError\tMeanRelError\tStdDev\tMinError\tMaxError\tMaxErrorCase\tTime"); foreach (var entry in errorMap) { if (entry.Value.Count == 0) { continue; } IEnumerable <double> errors = entry.Value.Select((tuple) => tuple.Item2); double meanResult = entry.Value.Select(tuple => tuple.Item1).Average(); double meanError = errors.Average(); double stdDev = Math.Sqrt(errors.Select((error) => error * error).Average() - meanError * meanError); double time = entry.Value.Select((tuple) => tuple.Item3).Average(); string line = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}", entry.Key.Item1, // division entry.Key.Item2, // order entry.Key.Item3, // width entry.Key.Item4, // vanishing moments entry.Key.Item5, // continuous derivative meanResult.ToString(formatInfo), meanError.ToString(formatInfo), (meanError / testCase.Solution).ToString(formatInfo), stdDev.ToString(formatInfo), errors.Min().ToString(formatInfo), errors.Max().ToString(formatInfo), errors.IndexOfMax((d) => d) + 1, time.ToString(formatInfo)); log.WriteLine(line); } } globalWatch.Stop(); Console.WriteLine("Finished case " + testCase.GetType().Name + " after " + globalWatch.ElapsedMilliseconds + "ms"); return(dt); }
public void ReportFailure(ITestCase test) { Write("Failure: " + test.GetType() + "\n"); }
public void ReportSuccess(ITestCase test) { Write("Succesful: " + test.GetType() + "\n"); }
public SimpleTests(ITestOutputHelper testOutputHelper, ITestCase testCase) { Debug.WriteLine(".ctor"); testOutputHelper.WriteLine($"{testCase.GetType().Name}: {testCase.DisplayName}"); }