132 lines
3.5 KiB
TypeScript
132 lines
3.5 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
import {
|
|
continuousMechanicalForceChartValues,
|
|
resultStateTransitionSampleIndices,
|
|
segmentedChartPath,
|
|
} from "../../src/resultEventSeries";
|
|
|
|
const mechanicalComponent = {
|
|
data: {
|
|
ports: [{ name: "port_2", domain: "mechanical" }],
|
|
},
|
|
};
|
|
|
|
const mechanicalPortForce = {
|
|
scope: "port" as const,
|
|
portName: "port_2",
|
|
quantity: "force",
|
|
category: "flow",
|
|
};
|
|
|
|
test("只分离机械事件中的孤立力尖峰,同时保留连续曲线和原始值", () => {
|
|
const time = [0, 0.5, 0.75, 1, 1.5];
|
|
const eventIndices = resultStateTransitionSampleIndices(time, {
|
|
integration: {
|
|
segments: [
|
|
{ stateTransitionTimes: [0.75] },
|
|
{ stateTransitionTimes: [0.7500000000000001] },
|
|
],
|
|
},
|
|
});
|
|
expect([...eventIndices]).toEqual([2]);
|
|
|
|
const rawForce = [1, 2, 1e12, 3, 4];
|
|
const displayedForce = continuousMechanicalForceChartValues(
|
|
mechanicalPortForce,
|
|
mechanicalComponent,
|
|
rawForce,
|
|
eventIndices,
|
|
);
|
|
expect(displayedForce.separatedEventSampleCount).toBe(1);
|
|
expect(Number.isNaN(displayedForce.values[2])).toBe(true);
|
|
expect(Math.max(...displayedForce.values.filter(Number.isFinite))).toBe(4);
|
|
expect(rawForce[2]).toBe(1e12);
|
|
|
|
const path = segmentedChartPath(
|
|
time,
|
|
displayedForce.values,
|
|
(value) => value,
|
|
(value) => value,
|
|
);
|
|
expect(path.match(/\bM /g)).toHaveLength(1);
|
|
|
|
const smoothForce = [1, 2, 2.5, 3, 4];
|
|
const displayedSmoothForce = continuousMechanicalForceChartValues(
|
|
mechanicalPortForce,
|
|
mechanicalComponent,
|
|
smoothForce,
|
|
eventIndices,
|
|
);
|
|
expect(displayedSmoothForce.values).toBe(smoothForce);
|
|
expect(displayedSmoothForce.separatedEventSampleCount).toBe(0);
|
|
|
|
const componentForce = continuousMechanicalForceChartValues(
|
|
{
|
|
scope: "component",
|
|
portName: null,
|
|
quantity: "force",
|
|
category: "derived",
|
|
},
|
|
mechanicalComponent,
|
|
[1, 2, -1e12, 3, 4],
|
|
eventIndices,
|
|
);
|
|
expect(componentForce.separatedEventSampleCount).toBe(1);
|
|
expect(Number.isNaN(componentForce.values[2])).toBe(true);
|
|
|
|
const signalForce = continuousMechanicalForceChartValues(
|
|
{
|
|
scope: "component",
|
|
portName: null,
|
|
quantity: "force",
|
|
category: "signal",
|
|
},
|
|
mechanicalComponent,
|
|
[1, 2, -1e12, 3, 4],
|
|
eventIndices,
|
|
);
|
|
expect(signalForce.values[2]).toBe(-1e12);
|
|
expect(signalForce.separatedEventSampleCount).toBe(0);
|
|
|
|
const stateValues = [0, 0.5, 1e9, 1, 1.5];
|
|
const displayedState = continuousMechanicalForceChartValues(
|
|
{ ...mechanicalPortForce, quantity: "velocity" },
|
|
mechanicalComponent,
|
|
stateValues,
|
|
eventIndices,
|
|
);
|
|
expect(displayedState.values).toBe(stateValues);
|
|
expect(displayedState.values[2]).toBe(1e9);
|
|
|
|
const pneumaticForce = continuousMechanicalForceChartValues(
|
|
mechanicalPortForce,
|
|
{
|
|
data: {
|
|
ports: [{ name: "port_2", domain: "pneumatic" }],
|
|
},
|
|
},
|
|
rawForce,
|
|
eventIndices,
|
|
);
|
|
expect(pneumaticForce.values).toBe(rawForce);
|
|
|
|
const persistentContactForce = [0, 0, 1e6, 1e6, 1e6];
|
|
const displayedPersistentContactForce =
|
|
continuousMechanicalForceChartValues(
|
|
mechanicalPortForce,
|
|
mechanicalComponent,
|
|
persistentContactForce,
|
|
eventIndices,
|
|
);
|
|
expect(displayedPersistentContactForce.values).toBe(
|
|
persistentContactForce,
|
|
);
|
|
expect(
|
|
displayedPersistentContactForce.separatedEventSampleCount,
|
|
).toBe(0);
|
|
expect(
|
|
resultStateTransitionSampleIndices(time, {}),
|
|
).toEqual(new Set<number>());
|
|
});
|