Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/model/box-hit.group.spec.ts is written in an unsupported language. File is not indexed.

0001 // box-hit.group.spec.ts
0002 
0003 import { BoxHitGroup, BoxHit } from './box-hit.group';
0004 import { initGroupFactories } from "./default-group-init";
0005 
0006 describe('BoxHitGroup', () => {
0007     initGroupFactories();
0008 
0009     it('should create an instance with given name', () => {
0010         const component = new BoxHitGroup('TestComponent');
0011 
0012         expect(component.name).toBe('TestComponent');
0013         expect(component.type).toBe(BoxHitGroup.type);
0014         expect(component.hits.length).toBe(0);
0015     });
0016 
0017     it('should serialize to DexObject correctly', () => {
0018         const hit1 = new BoxHit([1, 2, 3], [10, 10, 1], [4, 1], [0.001, 0.0001]);
0019         const hit2 = new BoxHit([4, 5, 6], [10, 10, 2], [5, 1], [0.002, 0.0002]);
0020 
0021         const component = new BoxHitGroup('TestComponent', 'Testorigin');
0022         component.hits.push(hit1, hit2);
0023 
0024         const dexObject = component.toDexObject();
0025 
0026         expect(dexObject).toEqual({
0027             name: 'TestComponent',
0028             type: 'BoxHit',
0029             origin: 'Testorigin',
0030             hits: [hit1.toDexObject(), hit2.toDexObject()],
0031         });
0032     });
0033 
0034 
0035     describe('BoxHitGroup timeRange', () => {
0036         let component: BoxHitGroup;
0037 
0038         beforeEach(() => {
0039             component = new BoxHitGroup('TestComponent');
0040         });
0041 
0042         it('should return null when hits array is empty', () => {
0043             expect(component.timeRange).toBeNull();
0044         });
0045 
0046         it('should return correct time range with a single hit with valid time', () => {
0047             const hit = new BoxHit([1, 2, 3], // position
0048             [10, 10, 1], // dimensions
0049             [5, 1], // time [value, error]
0050             [0.001, 0.0001] // energyDeposit
0051             );
0052             component.hits.push(hit);
0053 
0054             expect(component.timeRange).toEqual([5, 5]);
0055         });
0056 
0057 
0058         it('should return correct time range with multiple hits with valid times', () => {
0059             const hit1 = new BoxHit([1, 2, 3], [10, 10, 1], [5, 1], [0.001, 0.0001]);
0060             const hit2 = new BoxHit([4, 5, 6], [10, 10, 2], [3, 1], [0.002, 0.0002]);
0061             const hit3 = new BoxHit([7, 8, 9], [10, 10, 3], [8, 1], [0.003, 0.0003]);
0062 
0063             component.hits.push(hit1, hit2, hit3);
0064 
0065             expect(component.timeRange).toEqual([3, 8]);
0066         });
0067 
0068         it('should handle null time values correctly when first hit has valid time', () => {
0069             const hit1 = new BoxHit([1, 2, 3], [10, 10, 1], [5, 1], [0.001, 0.0001]);
0070 
0071             const hit3 = new BoxHit([7, 8, 9], [10, 10, 3], [3, 1], [0.003, 0.0003]);
0072 
0073             component.hits.push(hit1, hit3);
0074 
0075             expect(component.timeRange).toEqual([3, 5]);
0076         });
0077 
0078 
0079 
0080 
0081         it('should return correct range when all times are the same', () => {
0082             const hit1 = new BoxHit([1, 2, 3], [10, 10, 1], [5, 1], [0.001, 0.0001]);
0083             const hit2 = new BoxHit([4, 5, 6], [10, 10, 2], [5, 1], [0.002, 0.0002]);
0084 
0085             component.hits.push(hit1, hit2);
0086 
0087             expect(component.timeRange).toEqual([5, 5]);
0088         });
0089     });
0090 });