1// Copyright 2021 The Cirq Developers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {expect} from 'chai';
16import {Line} from 'three';
17import {GridQubit} from './grid_qubit';
18import {QubitLabel} from './meshes';
19import {Symbol3D, SymbolInformation} from './types';
20
21describe('GridQubit with 5 default moments', () => {
22  const DEFAULT_ROW = 0;
23  const DEFAULT_COL = 0;
24  const DEFAULT_MOMENTS = 5;
25  const gridQubit = new GridQubit(DEFAULT_ROW, DEFAULT_COL, DEFAULT_MOMENTS);
26  const children = gridQubit.children;
27
28  it('is a three.js line object with length 5', () => {
29    const line = children.find(child => child.type === 'Line') as Line;
30    line.computeLineDistances();
31    const distancePoints = line.geometry.attributes.lineDistance.array;
32
33    expect(distancePoints[0]).to.equal(0);
34    expect(distancePoints[1]).to.equal(DEFAULT_MOMENTS);
35  });
36
37  it('has a three.js sprite label', () => {
38    const sprite = children.find(
39      child => child.type === 'Sprite'
40    ) as QubitLabel;
41    expect(sprite.text).to.equal(`(${DEFAULT_ROW}, ${DEFAULT_COL})`);
42  });
43
44  it('handles adding a basic Symbol3D object', () => {
45    const symbolInfo: SymbolInformation = {
46      wire_symbols: ['X'],
47      location_info: [{row: 0, col: 0}],
48      color_info: ['black'],
49      moment: 1,
50    };
51
52    const symbol = new Symbol3D(symbolInfo);
53    gridQubit.addSymbol(symbol);
54
55    const symbol3D = children.find(
56      child => child.constructor.name === 'Symbol3D'
57    )!;
58    expect(symbol3D.children[0].constructor.name).to.equal('X3DSymbol');
59  });
60});
61