Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/lib-root-geometry/root-geo-edit.spec.ts is written in an unsupported language. File is not indexed.

0001 // Import necessary modules and functions
0002 import {
0003   editGeoNodes,
0004   GeoNodeEditRule,
0005   EditActions,
0006 } from './root-geo-edit'; // Update with the actual path
0007 
0008 import {GeoAttBits, testGeoBit, toggleGeoBit} from "./root-geo-attribute-bits";
0009 
0010 describe('editGeoNodes', () => {
0011 
0012   // Mock data setup for a typical geometry node structure
0013   let topNode: any;
0014   let childNode: any;
0015   let childNode2: any;
0016   let childNode3: any;
0017 
0018   // Create test data
0019   // Root have fGeoAtt both for nodes and volumes
0020   // https://root.cern.ch/doc/master/classTGeoAtt.html
0021 
0022   beforeEach(() => {
0023     childNode = {
0024       fName: 'ChildNode',
0025       fVolume: {
0026         fNodes: { arr: [] },
0027         fGeoAtt:0
0028       },
0029       fMother: undefined,
0030       fGeoAtt:0
0031     };
0032 
0033     childNode2 = {
0034       fName: 'AnotherChildNode1',
0035       fVolume: {
0036         fNodes: { arr: [] },
0037         fGeoAtt:0
0038       },
0039       fMother: undefined,
0040       fGeoAtt:0
0041     };
0042 
0043     childNode3 = {
0044       fName: 'AnotherChildNode2',
0045       fVolume: {
0046         fNodes: { arr: [] },
0047         fGeoAtt:0
0048       },
0049       fMother: undefined,
0050       fGeoAtt:0
0051     };
0052 
0053     topNode = {
0054       fName: 'TopNode',
0055       fVolume: {
0056         fNodes: { arr: [childNode, childNode2, childNode3] },
0057         fGeoAtt:0
0058       },
0059       fMother: undefined,
0060       fGeoAtt:0
0061     };
0062 
0063     childNode.fMother = topNode.fVolume;
0064   });
0065 
0066   it('should remove a specified node', () => {
0067     const rules: GeoNodeEditRule[] = [{ pattern: '*/ChildNode', action: EditActions.Remove }];
0068     editGeoNodes(topNode, rules);
0069     expect(topNode.fVolume.fNodes.arr).not.toContain(childNode);
0070   });
0071 
0072   it('should remove a specified node', () => {
0073     const rules: GeoNodeEditRule[] = [{ pattern: '*/ChildNode', action: EditActions.Remove }];
0074     editGeoNodes(topNode, rules);
0075     expect(topNode.fVolume.fNodes.arr).not.toContain(childNode);
0076   });
0077 
0078   it('should remove siblings of a node', () => {
0079     const rules: GeoNodeEditRule[] = [{ pattern: '*/ChildNode', action: EditActions.RemoveSiblings }];
0080     editGeoNodes(topNode, rules);
0081     expect(topNode.fVolume.fNodes.arr).toContain(childNode);
0082     expect(topNode.fVolume.fNodes.arr).not.toContain(childNode2);
0083     expect(topNode.fVolume.fNodes.arr).not.toContain(childNode3);
0084   });
0085 
0086   it('should NOT remove a node with wrong pattern', () => {
0087     const rules: GeoNodeEditRule[] = [{ pattern: 'ChildNode', action: EditActions.Remove }];
0088     editGeoNodes(topNode, rules);
0089     expect(topNode.fVolume.fNodes.arr).toContain(childNode);
0090   });
0091 
0092   it('should remove all children of a node', () => {
0093     const rules: GeoNodeEditRule[] = [{ pattern: 'TopNode', action: EditActions.RemoveChildren }];
0094     editGeoNodes(topNode, rules);
0095     expect(topNode.fVolume.fNodes.arr).toEqual([]);
0096   });
0097 
0098   it('should set a GeoBit on a node', () => {
0099     const rules: GeoNodeEditRule[] = [{
0100       pattern: 'TopNode',
0101       action: EditActions.SetGeoBit,
0102       geoBit: GeoAttBits.kVisOverride
0103     }];
0104     editGeoNodes(topNode, rules);
0105     expect(testGeoBit(topNode.fVolume, GeoAttBits.kVisOverride)).toBe(true);
0106     expect(testGeoBit(childNode.fVolume, GeoAttBits.kVisOverride)).toBe(false);
0107   });
0108 
0109   it('should toggle a GeoBit on a node', () => {
0110     const rules = [ {
0111       pattern: 'TopNode',
0112       action: EditActions.ToggleGeoBit,
0113       geoBit: GeoAttBits.kVisOverride
0114     }];
0115     editGeoNodes(topNode, rules);
0116     expect(testGeoBit(topNode.fVolume, GeoAttBits.kVisOverride)).toBe(true);
0117     expect(testGeoBit(childNode.fVolume, GeoAttBits.kVisOverride)).toBe(false);
0118   });
0119 
0120   // Additional tests for other actions and more complex scenarios...
0121 });
0122