Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions source/samples_test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{

fn main() {
create_tests_for_files("algorithms");
create_tests_for_files("algorithms/Ising");
create_tests_for_files("getting_started");
create_tests_for_files("language");
create_tests_for_files_compile_only("estimation");
Expand All @@ -22,8 +23,9 @@ fn create_tests_for_files(folder: &str) {
// Iterate through the folder and create a test for each qs file
let mut paths =
read_dir(format!("../../samples/{folder}")).expect("folder should exist and be readable");
let folder_name = folder.replace('/', "_");
let out_dir = "./src/tests";
let dest_path = Path::new(&out_dir).join(format!("{folder}_generated.rs"));
let dest_path = Path::new(&out_dir).join(format!("{folder_name}_generated.rs"));
let mut f = File::create(dest_path).expect("files should be creatable in ./src/tests");

writeln!(
Expand All @@ -35,7 +37,7 @@ fn create_tests_for_files(folder: &str) {
//! This build-generated module contains tests for the samples in the `/samples/{folder}` folder.
//! DO NOT MANUALLY EDIT THIS FILE. To regenerate this file, run `cargo check` or `cargo test` in the `samples_test` directory.

use super::{folder}::*;
use super::{folder_name}::*;
use super::{{compile_and_run, compile_and_run_debug, circuit, qirgen}};
use qsc::SourceMap;"#,
)
Expand Down Expand Up @@ -77,7 +79,7 @@ fn {file_stem}_src() -> SourceMap {{
#[test]
fn run_{file_stem}() {{
let output = compile_and_run({file_stem}_src());
// This constant must be defined in `samples_test/src/tests/{folder}.rs` and
// This constant must be defined in `samples_test/src/tests/{folder_name}.rs` and
// must contain the output of the sample {file_name}
{file_stem_upper}_EXPECT.assert_eq(&output);
}}
Expand All @@ -86,7 +88,7 @@ fn run_{file_stem}() {{
#[test]
fn debug_{file_stem}() {{
let output = compile_and_run_debug({file_stem}_src());
// This constant must be defined in `samples_test/src/tests/{folder}.rs` and
// This constant must be defined in `samples_test/src/tests/{folder_name}.rs` and
// must contain the output of the sample {file_name}
{file_stem_upper}_EXPECT_DEBUG.assert_eq(&output);
}}
Expand All @@ -95,7 +97,7 @@ fn debug_{file_stem}() {{
#[test]
fn circuit_{file_stem}() {{
let circuit = circuit({file_stem}_src());
// This constant must be defined in `samples_test/src/tests/{folder}.rs` and
// This constant must be defined in `samples_test/src/tests/{folder_name}.rs` and
// must contain the circuit for the sample {file_name}
{file_stem_upper}_EXPECT_CIRCUIT.assert_eq(&circuit);
}}
Expand All @@ -104,7 +106,7 @@ fn circuit_{file_stem}() {{
#[test]
fn qirgen_{file_stem}() {{
let qir = qirgen({file_stem}_src());
// This constant must be defined in `samples_test/src/tests/{folder}.rs` and
// This constant must be defined in `samples_test/src/tests/{folder_name}.rs` and
// must contain the QIR for the sample {file_name}
{file_stem_upper}_EXPECT_QIR.assert_eq(&qir);
}}"#
Expand Down
7 changes: 5 additions & 2 deletions source/samples_test/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![allow(non_snake_case)]

mod algorithms;
#[rustfmt::skip]
mod algorithms_generated;
mod algorithms_Ising;
#[rustfmt::skip]
mod algorithms_Ising_generated;
mod getting_started;
#[rustfmt::skip]
mod getting_started_generated;
Expand All @@ -14,9 +19,7 @@ mod language;
mod language_generated;
#[rustfmt::skip]
mod project_generated;
#[allow(non_snake_case)]
mod OpenQASM;
#[allow(non_snake_case)]
#[rustfmt::skip]
mod OpenQASM_generated;

Expand Down
26 changes: 26 additions & 0 deletions source/samples_test/src/tests/algorithms_Ising.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

use expect_test::{Expect, expect};

// Each file in the samples/algorithms/Ising folder is compiled and run as two tests and should
// have matching expect strings in this file. If new samples are added, this file will
// fail to compile until the new expect strings are added.
pub const SIMPLE2DISINGORDER2_EXPECT: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, One, Zero, One]"];
pub const SIMPLE2DISINGORDER2_EXPECT_DEBUG: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, One, Zero, One]"];
pub const SIMPLE2DISINGORDER2_EXPECT_CIRCUIT: Expect = expect!["generated circuit of length 24940"];
pub const SIMPLE2DISINGORDER2_EXPECT_QIR: Expect = expect!["generated QIR of length 20849"];
pub const SIMPLE1DISINGORDER1_EXPECT: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, Zero, Zero, Zero]"];
pub const SIMPLE1DISINGORDER1_EXPECT_DEBUG: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, Zero, Zero, Zero]"];
pub const SIMPLE1DISINGORDER1_EXPECT_CIRCUIT: Expect = expect!["generated circuit of length 12317"];
pub const SIMPLE1DISINGORDER1_EXPECT_QIR: Expect = expect!["generated QIR of length 18408"];
pub const SIMPLE2DISINGORDER1_EXPECT: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, One, One, Zero]"];
pub const SIMPLE2DISINGORDER1_EXPECT_DEBUG: Expect =
expect!["[Zero, Zero, Zero, One, One, Zero, One, One, Zero]"];
pub const SIMPLE2DISINGORDER1_EXPECT_CIRCUIT: Expect = expect!["generated circuit of length 24085"];
pub const SIMPLE2DISINGORDER1_EXPECT_QIR: Expect = expect!["generated QIR of length 16214"];
Loading