BasicBendAuto Test
Overview
This document describes the BasicBendAuto test fixture and its helper methods from Test/Bend/BasicBendAuto.cs. It explains the purpose of each line in the main class and the associated static helpers used by the tests.
Test data is in X:\TData\Bend\Auto
|
Tip
|
open the .geo file and the dump file and compare the results |
Source snippet (context)
namespace Flit;
#nullable enable
[TestFixture (4, "Basic bend auto-tooler tests", Module = "Bend", Subsystem = "AutoTool")]
class BasicBendAuto {
[Test (82, "Tooling basic part: Bend_04.geo")]
void Test1 () => Test ("Bend/Auto/Bend_04.geo");
[Test (84, "Tooling basic part: Bend_01.geo")]
void Test3 () => Test ("Bend/Auto/Bend_01.geo");
[Test (85, "Tooling basic part: Bend_02_1000.geo")]
void Test4 () => Test ("Bend/Auto/Bend_02_1000.geo");
...
public static Part Test (string file, int idMachine = 13, bool infiniteInventory = true,
bool ignoreToolHints = false, string? outfile = null,
EDoFlags flags = EDoFlags.NoGAPAdjust, string? btools = null,
bool openForEditing = false) {
Part part = FX.LoadTestPart (file);
if (part.Model == null) part.DoFoldTo3D ().Is (EResult.OK);
BendTech.Make (part, BendMachine.Get (idMachine)).Is (EResult.OK);
var tech = part.BendTech;
if (tech.Inventory == tech.BMachine.Inventory)
tech.Inventory = BToolLibrary.Get (1).MakeTestInventory (2);
tech.Settings.InfiniteBInventory = infiniteInventory;
tech.Settings.IgnoreBToolHints = ignoreToolHints;
if (btools != null) tech.Inventory = BToolList.Load (FX.TestFile (btools));
BendTooler.Process (part.BendTech, flags);
outfile = outfile == null ? Path.ChangeExtension (file, ".txt") : FX.TestFile (outfile);
if (openForEditing) part.OpenForEditing ();
CheckDump (tech, outfile);
return part;
}
public static void CheckDump (BendTech tech, string refFile) {
string file = FX.TmpTestFile;
refFile = FX.TestFile (refFile);
using (StreamWriter sw = new (file)) tech.Dump (sw);
Assert.AreTextFilesEqual (refFile, file);
}
}
Line-by-line explanation
Below each numbered line or small group of lines from the main class is explained. The explanations focus on intent, side effects, and interactions with test infrastructure.
namespace Flit;-
Declares the
Flitnamespace for the file. Groups related types and avoids global name collisions.
[TestFixture (4, "Basic bend auto-tooler tests", Module = "Bend", Subsystem = "AutoTool")]-
Applies a test-framework attribute marking the
BasicBendAutoclass as a test fixture. -
The parameters (e.g.,
4, description,Module,Subsystem) are metadata used by the project’s test runner to categorize and identify the fixture.
class BasicBendAuto {-
Begins the definition of the test fixture class named
BasicBendAuto. Contains test methods and helpers.
-
Attribute marking the next method as a test case.
-
First parameter
82is the test id used by the project’s test harness; the string describes the test.
-
Single-line test method using expression-bodied syntax.
-
Calls the static helper
Test(…)to run tooling on the indicated test file. -
Keeps the test method minimal; all heavy lifting delegated to
Test.
(Tests 2–n follow the same pattern: attribute with id and description, and a one-line method calling Test with a file path.)
- Each test method pairs an id + description attribute with a minimal body that invokes the shared Test helper. This avoids duplicating setup and verification logic across tests.
public static Part Test (string file, int idMachine = 13, bool infiniteInventory = true, bool ignoreToolHints = false, string? outfile = null, EDoFlags flags = EDoFlags.NoGAPAdjust, string? btools = null, bool openForEditing = false) {-
Declares a public static helper method used by all the test methods.
-
Parameters:
-
file: relative path to the test input file (DXF/.geo/.fx, etc.). -
idMachine: machine id to use (default13). -
infiniteInventory: iftrue, simulate unlimited tools in inventory (defaulttrue). -
ignoreToolHints: iftrue, ignore hints embedded in the model about tooling. -
outfile: optional expected output file path (if null, derived from input filename). -
flags: processing flags controlling pre-processing/accuracy; default isEDoFlags.NoGAPAdjust. -
btools: optional override tool-list file. -
openForEditing: if true, leaves the part open for manual inspection.
-
Loads the test part from the provided
fileusing a test helperFX.LoadTestPart. -
Returns a domain
Partobject representing the model to test.
-
If the loaded
Partdoes not already have a 3D model, callDoFoldTo3D()to generate/fold it. -
The
.Is(EResult.OK)call asserts the result equalsEResult.OK— a lightweight assertion idiom in this codebase.
-
Constructs or computes
BendTechfor theparttargeting the machine returned byBendMachine.Get(idMachine). -
.Is(EResult.OK)asserts the operation succeeded.BendTech.Makeprepares tooling, stations, and other bend-specific data.
-
Short local to hold the computed
BendTechobject for convenient access in subsequent steps.
-
Ensures the
BendTechhas a testable inventory distinct from the machine default: -
If the
tech.Inventoryreferences the machine’s default inventory, replace it with a test inventory created fromBToolLibrary.Get(1). -
MakeTestInventory(2)likely creates a small inventory with 2 copies or 2 sets for deterministic testing.
-
Sets a boolean testing setting on the
BendTechto simulate unlimited stock of tools whentrue. Useful to avoid inventory-limited failures during tests.
-
Controls whether tooling hints embedded in the model are honored. When
true, hints are ignored so the auto-tooler decides without model-supplied recommendations.
-
If the test specified a
btoolspath, load that tool list and use it as thetech.Inventory, overriding prior inventory adjustments. -
FX.TestFileconverts a logical test file path to a filesystem path.
-
Runs the core auto-tooling algorithm
BendTooler.Processon the preparedBendTech. -
flagscontrols behavior such as alignment, gap adjustments, and other processing nuances.
-
Determine the expected output reference file:
-
If
outfilewas not provided, derive it by replacing the input file extension with.txt(e.g.,Bend_04.geo→Bend_04.txt). -
If
outfilewas provided, convert it to the actual test reference path usingFX.TestFile.
-
If
openForEditingis true, open the resultingPartin an editor or UI for manual inspection (useful for debugging failing tests).
-
Call
CheckDumpto serialize theBendTechto a temporary file and compare it to the referenceoutfile. -
This is the primary assertion: produced tooling dump must match the expected text dump.
-
Return the
Partinstance so callers/tests can make further checks if needed.
-
End of
Testmethod.
-
Declare a helper that writes the current tooling state to a temporary file and compares it with a reference text file.
-
Acquire a temporary file path from test helper
FX.TmpTestFileto hold the dump output.
-
Resolve the provided
refFilelogical path to an absolute test-file path used for comparison.
-
Open a
StreamWriterto the temp file and calltech.Dump(sw)to serialize theBendTechcontents (tools, stations, sequence, settings) to text. -
usingensures the writer (and file descriptor) is disposed/closed.
-
Compare the reference file and produced temp file text content via the project’s
Assert.AreTextFilesEqualhelper. -
If they differ, the test fails and the diff indicates tooling/regression.
-
End of
CheckDumpmethod.
}-
End of
BasicBendAutoclass.
Example dump from GEO04.txt
Matl=1.0038 Thick=2 MC=13:"5130X 6A B23"
4, 2, 8, 6
'OW202/S R1/28 H220' [500+30] X=0 'EV005 W16/30 R1.6' [500+30] X=0
Open=110 G1 (-308,54,-8) Surf=4 G2 (267,70,-8) Surf=1 Status=RotateR
Open=110 HBox=101 G1 (-308,54,-8) Surf=4 G2 (267,70,-8) Surf=1 Status=RotateR
Open=110 HBox=101 G1 (-308,54,-8) Surf=4 G2 (267,70,-8) Surf=1 Status=RotateR
Open=110 HBox=101 G1 (-308,54,-8) Surf=4 G2 (267,70,-8) Surf=1 Status=OK