Warning, /firebird/firebird-ng/src/app/model/point-trajectory.group.spec.ts is written in an unsupported language. File is not indexed.
0001 // point-trajectory.component.spec.ts
0002 import { PointTrajectoryGroup, PointTrajectoryGroupFactory } from './point-trajectory.group';
0003 import { getEventGroupFactory } from './event-group';
0004 import {initGroupFactories} from "./default-group-init";
0005
0006
0007 describe('PointTrajectoryGroup', () => {
0008 beforeEach(()=>{
0009 initGroupFactories();
0010 });
0011
0012 it('should be registered in the component factory registry', () => {
0013 const factory = getEventGroupFactory(PointTrajectoryGroup.type);
0014 expect(factory).toBeDefined();
0015 expect(factory instanceof PointTrajectoryGroupFactory).toBeTrue();
0016 });
0017
0018 it('should create a component from a valid Dex object', () => {
0019 // Prepare a mock DEX object
0020 const dexObj = {
0021 name: 'CentralTrackSegments',
0022 type: 'PointTrajectory',
0023 origin: ['edm4eic::TrackPoint','edm4eic::TrackSegmentData'],
0024 paramColumns: ['theta','phi','qOverP','charge','pdg'],
0025 pointColumns: ['x','y','z','t','dx','dy','dz','dt'],
0026 trajectories: [
0027 {
0028 points: [
0029 [0, 0, 0, 100, 0.1, 0.1, 0.1, 0.0],
0030 [10, 20, 30, 120, 0.2, 0.2, 0.2, 0.1],
0031 ],
0032 params: [1.57, 3.14, -0.0005, -1, 11]
0033 },
0034 {
0035 points: [],
0036 params: []
0037 }
0038 ]
0039 };
0040
0041 // Retrieve the factory and create the component
0042 const factory = getEventGroupFactory(PointTrajectoryGroup.type);
0043 expect(factory).toBeTruthy();
0044
0045 const component = factory?.fromDexObject(dexObj) as PointTrajectoryGroup;
0046 expect(component).toBeDefined();
0047 expect(component.name).toBe('CentralTrackSegments');
0048 expect(component.paramColumns).toEqual(['theta','phi','qOverP','charge','pdg']);
0049 expect(component.pointColumns).toEqual(['x','y','z','t','dx','dy','dz','dt']);
0050
0051 // Lines
0052 expect(component.trajectories.length).toBe(2);
0053 // First line
0054 const trajectory1 = component.trajectories[0];
0055 expect(trajectory1.points.length).toBe(2);
0056 expect(trajectory1.params).toEqual([1.57, 3.14, -0.0005, -1, 11]);
0057 // Second line
0058 const trajectory2 = component.trajectories[1];
0059 expect(trajectory2.points.length).toBe(0);
0060 expect(trajectory2.params.length).toBe(0);
0061 });
0062
0063 it('should serialize back to Dex format via toDexObject()', () => {
0064 // Create a component manually
0065 const component = new PointTrajectoryGroup('MyTrajectory', 'testOrigin');
0066 component.paramColumns = ['alpha','beta'];
0067 component.pointColumns = ['x','y','z','t'];
0068 component.trajectories = [
0069 {
0070 points: [[1,2,3,10],[4,5,6,20]],
0071 params: [42, 99]
0072 }
0073 ];
0074
0075 // Convert to Dex
0076 const dex = component.toDexObject();
0077
0078 // Check top-level
0079 expect(dex.name).toBe('MyTrajectory');
0080 expect(dex.type).toBe('PointTrajectory');
0081 expect(dex.origin).toBe('testOrigin');
0082 expect(dex.paramColumns).toEqual(['alpha','beta']);
0083 expect(dex.pointColumns).toEqual(['x','y','z','t']);
0084
0085 // Check lines
0086 expect(dex.trajectories.length).toBe(1);
0087 expect(dex.trajectories[0].points.length).toBe(2);
0088 expect(dex.trajectories[0].points[0]).toEqual([1,2,3,10]);
0089 expect(dex.trajectories[0].params).toEqual([42,99]);
0090 });
0091
0092 });