Skip to content

Commit

Permalink
テストをさらに移行
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Aug 9, 2023
1 parent 980cd91 commit d117e42
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
47 changes: 47 additions & 0 deletions packages/simulator/test/simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,51 @@ describe('Simulator', () => {
expect(equate(simulator.h(0, 1).state, new StateVector('++'))).toBe(true)
})
})

describe('phase', () => {
test("|0>.phase('π', 0) should be |0>", () => {
const simulator = new Simulator('0')
expect(equate(simulator.phase('π', 0).state, new StateVector('0'))).toBe(true)
})

test("|1>.phase('π', 0) should be -|1>", () => {
const simulator = new Simulator('1')
expect(equate(simulator.phase('π', 0).state.matrix, new StateVector('1').matrix.times(-1))).toBe(true)
})

test("|+>.phase('π', 0) should be |->", () => {
const simulator = new Simulator('+')
expect(equate(simulator.phase('π', 0).state, new StateVector('-'))).toBe(true)
})

test("|->.phase('π', 0) should be |+>", () => {
const simulator = new Simulator('-')
expect(equate(simulator.phase('π', 0).state, new StateVector('+'))).toBe(true)
})

test("|i>.phase('π', 0) should be |-i>", () => {
const simulator = new Simulator('i')
expect(equate(simulator.phase('π', 0).state, new StateVector('(-i)'))).toBe(true)
})

test("|-i>.phase('π', 0) should be |i>", () => {
const simulator = new Simulator('(-i)')
expect(equate(simulator.phase('π', 0).state, new StateVector('i'))).toBe(true)
})

test("|++>.phase('π', 0) should be |+->", () => {
const simulator = new Simulator('++')
expect(equate(simulator.phase('π', 0).state, new StateVector('+-'))).toBe(true)
})

test("|++>.phase('π', 1) should be |-+>", () => {
const simulator = new Simulator('++')
expect(equate(simulator.phase('π', 1).state, new StateVector('-+'))).toBe(true)
})

test("|++>.phase('π', 0, 1) should be |-->", () => {
const simulator = new Simulator('++')
expect(equate(simulator.phase('π', 0, 1).state, new StateVector('--'))).toBe(true)
})
})
})
47 changes: 0 additions & 47 deletions packages/simulator/test/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,6 @@ import {Matrix, Simulator, StateVector} from '../src'
import {Complex} from '@qni/common'

QUnit.module('Simulator', () => {
QUnit.module('.phase', () => {
QUnit.test("|0>.phase('π', 0) should be |0>", assert => {
const simulator = new Simulator('0')
assert.equates(simulator.phase('π', 0).state, new StateVector('0'))
})

QUnit.test("|1>.phase('π', 0) should be -|1>", assert => {
const simulator = new Simulator('1')
assert.approximatelyEquates(simulator.phase('π', 0).state.matrix, new StateVector('1').matrix.times(-1))
})

QUnit.test("|+>.phase('π', 0) should be |->", assert => {
const simulator = new Simulator('+')
assert.approximatelyEquates(simulator.phase('π', 0).state, new StateVector('-'))
})

QUnit.test("|->.phase('π', 0) should be |+>", assert => {
const simulator = new Simulator('-')
assert.approximatelyEquates(simulator.phase('π', 0).state, new StateVector('+'))
})

QUnit.test("|i>.phase('π', 0) should be |-i>", assert => {
const simulator = new Simulator('i')
assert.approximatelyEquates(simulator.phase('π', 0).state, new StateVector('(-i)'))
})

QUnit.test("|-i>.phase('π', 0) should be |i>", assert => {
const simulator = new Simulator('(-i)')
assert.approximatelyEquates(simulator.phase('π', 0).state, new StateVector('i'))
})

QUnit.test("|++>.phase('π', 0) should be |+->", assert => {
const simulator = new Simulator('++')
assert.approximatelyEquates(simulator.phase('π', 0).state, new StateVector('+-'))
})

QUnit.test("|++>.phase('π', 1) should be |-+>", assert => {
const simulator = new Simulator('++')
assert.approximatelyEquates(simulator.phase('π', 1).state, new StateVector('-+'))
})

QUnit.test("|++>.phase('π', 0, 1) should be |-->", assert => {
const simulator = new Simulator('++')
assert.approximatelyEquates(simulator.phase('π', 0, 1).state, new StateVector('--'))
})
})

QUnit.module('.rnot', () => {
QUnit.test("|0>.rnot(0) should be |0>.h(0).phase('π/2', 0).h(0)", assert => {
assert.approximatelyEquates(new Simulator('0').rnot(0).state, new Simulator('0').h(0).phase('π/2', 0).h(0).state)
Expand Down

0 comments on commit d117e42

Please sign in to comment.