Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/model/point-trajectory.event-component.spec.ts is written in an unsupported language. File is not indexed.

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