开发:增加测试用例

pull/2504/head
ChenX 10 months ago
parent 7793c60ed9
commit e4d565dda2

@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`异形优化测试 1`] = `
Array [
1,
1.959058347014103,
2,
-1,
0,
undefined,
1,
0,
0,
Object {
"x": 0,
"y": 0,
},
Array [
0,
0,
],
Array [
94,
94,
],
-1,
0,
undefined,
1,
1,
0,
Object {
"x": 0,
"y": 0,
},
Array [
0,
0,
],
Array [
1194,
2394,
],
0,
0,
]
`;

@ -0,0 +1,99 @@
import { Circle } from "../../src/DatabaseServices/Entity/Circle";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { InitClipperCpp } from "../../src/Nest/Common/ClipperCpp";
import { NestFiler } from "../../src/Nest/Common/Filer";
import { CurveWrap } from "../../src/Nest/Converter/CurveWrap";
import { Circle2Points } from "../../src/Nest/Converter/Curves2Points";
import { DefaultBin } from "../../src/Nest/Core/DefaultBin";
import { Individual } from "../../src/Nest/Core/Individual";
import { NestCache } from "../../src/Nest/Core/NestCache";
import { DefaultComparePointKeys, NestDatabase } from "../../src/Nest/Core/NestDatabase";
import { OptimizeMachine } from "../../src/Nest/Core/OptimizeMachine";
import { Part } from "../../src/Nest/Core/Part";
import { Path } from "../../src/Nest/Core/Path";
import { PathGeneratorSingle } from "../../src/Nest/Core/PathGenerator";
//@ts-ignore
globalThis.document = {};
export function Curve2Path(curve: Circle | Polyline, outside = false): Path
{
if (curve.IsClockWise)
curve.Reverse();
if (curve instanceof Circle)
{
return new Path(Circle2Points(curve, 0, 10, outside), 3);
}
else
{
let w = new CurveWrap(curve, 3, outside);
return new Path(outside ? w.GetOutsidePoints() : w.GetInsidePoints());
}
}
test('异形优化测试', async () =>
{
await InitClipperCpp();
PathGeneratorSingle.Clear();
NestCache.Clear();
DefaultBin.InsideNFPCache = {};
let binPath = DefaultBin;
binPath.Id = undefined;
PathGeneratorSingle.RegisterId(binPath);
let path = Curve2Path(new Polyline().Rectangle(100, 100));
let part1 = new Part().Init(path, binPath);
let path2 = Curve2Path(new Polyline().Rectangle(1200, 2400));
let part2 = new Part().Init(path2, binPath);
part1.IsPrePlace = true;
part2.IsPrePlace = false;
let parts = [part1, part2];
parts.forEach((p, i) => p.Id = i);
let db = new NestDatabase();
db.Paths = PathGeneratorSingle.paths;
db.Parts = parts;
db.Bin = DefaultBin;
db.OddmentsBins = [];
db.ComparePointKeys = DefaultComparePointKeys;
let f = new NestFiler();
db.WriteFile(f);
db = new NestDatabase;
db.ReadFile(f);
let m = new OptimizeMachine;
m.Bin = db.Bin;
m.OddmentsBins = db.OddmentsBins;
m.PutParts(db.Parts);
let promise = new Promise<void>((res, rej) =>
{
m.callBack = async (inv) =>
{
m.Suspend();
let f = new NestFiler;
inv.WriteFile(f);
expect(f._datas).toMatchSnapshot();
let inv2 = new Individual(db.Parts);
inv2.ReadFile(f);
res();
};
});
m.Start();
await promise;
});
Loading…
Cancel
Save