Warning, /firebird/firebird-ng/src/app/painters/trajectory.painter.spec.ts is written in an unsupported language. File is not indexed.
0001 // trajectory.painter.spec.ts
0002 import { TrajectoryPainter } from './trajectory.painter';
0003 import { PointTrajectoryGroup } from '../model/point-trajectory.group';
0004 import { Object3D } from 'three';
0005 import { Line2 } from 'three/examples/jsm/lines/Line2';
0006 import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry';
0007
0008 describe('TrajectoryPainter', () => {
0009 let mockParentNode: any;
0010 let trajectoryGroup: PointTrajectoryGroup;
0011
0012 beforeEach(() => {
0013 // Create a simple mock parent node
0014 mockParentNode = {
0015 add: jasmine.createSpy('add'),
0016 remove: jasmine.createSpy('remove')
0017 };
0018
0019 // Create a real PointTrajectoryGroup with test data
0020 trajectoryGroup = new PointTrajectoryGroup('TestTrajectories');
0021 trajectoryGroup.paramColumns = ['pdg', 'charge'];
0022 trajectoryGroup.pointColumns = ['x', 'y', 'z', 't'];
0023
0024 // Add test trajectories
0025 trajectoryGroup.trajectories = [
0026 {
0027 // Track 1: t=10 to t=20
0028 points: [[0, 0, 0, 10], [10, 0, 0, 20]],
0029 params: [11, -1] // electron
0030 },
0031 {
0032 // Track 2: t=15 to t=35
0033 points: [[0, 10, 0, 15], [10, 10, 0, 25], [20, 10, 0, 35]],
0034 params: [22, 0] // gamma
0035 },
0036 {
0037 // Track 3: t=40 to t=50
0038 points: [[0, 20, 0, 40], [10, 20, 0, 50]],
0039 params: [2212, 1] // proton
0040 }
0041 ];
0042 });
0043
0044 describe('initLines', () => {
0045 // This test will use a custom subclass to inspect what initLines does
0046 it('should create the correct number of trajectories', () => {
0047
0048 // Create a test instance
0049 const testPainter = new TrajectoryPainter(mockParentNode, trajectoryGroup);
0050
0051 // Check if trajectories were created correctly
0052 expect(testPainter.trajectories.length).toBe(3);
0053 expect(mockParentNode.add).toHaveBeenCalled();
0054 });
0055 });
0056
0057 describe('paintNoTime', () => {
0058 it('should make all trajectories fully visible', () => {
0059 // Create a painter instance with real initialization
0060 const testPainter = new TrajectoryPainter(mockParentNode, trajectoryGroup);
0061
0062 // Reset visibility and instance count for testing
0063 testPainter.trajectories.forEach(track => {
0064 track.lineObj.visible = false;
0065 track.lineObj.geometry.instanceCount = 0;
0066 });
0067
0068 // Call paint with no time
0069 testPainter.paint(null);
0070
0071 // Verify all trajectories are visible with instanceCount = Infinity
0072 testPainter.trajectories.forEach(track => {
0073 expect(track.lineObj.visible).toBe(true);
0074 expect(track.lineObj.geometry.instanceCount).toBe(Infinity);
0075 });
0076 });
0077 });
0078
0079
0080 describe('fastPaint', () => {
0081 let painter: TrajectoryPainter;
0082
0083 beforeEach(() => {
0084 // Create a real painter instance
0085 painter = new TrajectoryPainter(mockParentNode, trajectoryGroup);
0086
0087 // Verify we have trajectories initialized
0088 expect(painter.trajectories.length).toBeGreaterThan(0);
0089 });
0090
0091 it('should hide tracks that have not started yet', () => {
0092 painter.paint(5); // Before any track starts
0093
0094 painter.trajectories.forEach(track => {
0095 expect(track.lineObj.visible).toBe(false);
0096 });
0097 });
0098
0099 it('should fully show tracks that have ended', () => {
0100 painter.paint(30); // After track 1 ends
0101
0102 // Track 1 should be fully visible
0103 expect(painter.trajectories[0].lineObj.visible).toBe(true);
0104 expect(painter.trajectories[0].lineObj.geometry.instanceCount).toBe(Infinity);
0105
0106 // Track 3 should be hidden (not yet started)
0107 expect(painter.trajectories[2].lineObj.visible).toBe(false);
0108 });
0109
0110 it('should partially show tracks based on time', () => {
0111 painter.paint(30); // In the middle of track 2
0112
0113 // Track 2 should be partially visible (2 points)
0114 expect(painter.trajectories[1].lineObj.visible).toBe(true);
0115 expect(painter.trajectories[1].lastPaintIndex).toBe(1);
0116 });
0117
0118 it('should handle time moving forward correctly', () => {
0119 // First time point
0120 painter.paint(20);
0121 expect(painter.trajectories[1].lastPaintIndex).toBe(0);
0122
0123 // Move forward
0124 painter.paint(30);
0125 expect(painter.trajectories[1].lastPaintIndex).toBe(1);
0126 });
0127
0128 it('should handle time moving backward correctly', () => {
0129 // First at later time
0130 painter.paint(40);
0131 expect(painter.trajectories[1].lastPaintIndex).toBe(2);
0132
0133 // Move backward
0134 painter.paint(20);
0135 expect(painter.trajectories[1].lastPaintIndex).toBe(0);
0136 });
0137
0138 it('should handle invalid lastPaintIndex', () => {
0139 // Set invalid index
0140 painter.trajectories[1].lastPaintIndex = 999;
0141
0142 // Should recover gracefully
0143 painter.paint(30);
0144
0145 // Should have valid index now
0146 expect(painter.trajectories[1].lastPaintIndex).toBeLessThan(
0147 painter.trajectories[1].points.length
0148 );
0149 });
0150 });
0151 });