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(
0048 [1, 2, 3], // position
0049 [10, 10, 1], // dimensions
0050 [5, 1], // time [value, error]
0051 [0.001, 0.0001] // energyDeposit
0052 );
0053 component.hits.push(hit);
0054
0055 expect(component.timeRange).toEqual([5, 5]);
0056 });
0057
0058
0059 it('should return correct time range with multiple hits with valid times', () => {
0060 const hit1 = new BoxHit(
0061 [1, 2, 3],
0062 [10, 10, 1],
0063 [5, 1],
0064 [0.001, 0.0001]
0065 );
0066 const hit2 = new BoxHit(
0067 [4, 5, 6],
0068 [10, 10, 2],
0069 [3, 1],
0070 [0.002, 0.0002]
0071 );
0072 const hit3 = new BoxHit(
0073 [7, 8, 9],
0074 [10, 10, 3],
0075 [8, 1],
0076 [0.003, 0.0003]
0077 );
0078
0079 component.hits.push(hit1, hit2, hit3);
0080
0081 expect(component.timeRange).toEqual([3, 8]);
0082 });
0083
0084 it('should handle null time values correctly when first hit has valid time', () => {
0085 const hit1 = new BoxHit(
0086 [1, 2, 3],
0087 [10, 10, 1],
0088 [5, 1],
0089 [0.001, 0.0001]
0090 );
0091
0092 const hit3 = new BoxHit(
0093 [7, 8, 9],
0094 [10, 10, 3],
0095 [3, 1],
0096 [0.003, 0.0003]
0097 );
0098
0099 component.hits.push(hit1, hit3);
0100
0101 expect(component.timeRange).toEqual([3, 5]);
0102 });
0103
0104
0105
0106
0107 it('should return correct range when all times are the same', () => {
0108 const hit1 = new BoxHit(
0109 [1, 2, 3],
0110 [10, 10, 1],
0111 [5, 1],
0112 [0.001, 0.0001]
0113 );
0114 const hit2 = new BoxHit(
0115 [4, 5, 6],
0116 [10, 10, 2],
0117 [5, 1],
0118 [0.002, 0.0002]
0119 );
0120
0121 component.hits.push(hit1, hit2);
0122
0123 expect(component.timeRange).toEqual([5, 5]);
0124 });
0125 });
0126 });