@@ -40,3 +40,119 @@ fn check_operations_are_equal() {
4040 ) ,
4141 ) ;
4242}
43+
44+ #[ test]
45+ fn check_start_stop_counting_operation_called_3_times ( ) {
46+ test_expression (
47+ "{
48+ import Microsoft.Quantum.Diagnostics.StartCountingOperation;
49+ import Microsoft.Quantum.Diagnostics.StopCountingOperation;
50+
51+ operation op1() : Unit {}
52+ operation op2() : Unit { op1(); }
53+ StartCountingOperation(op1);
54+ StartCountingOperation(op2);
55+ op1(); op1(); op2();
56+ (StopCountingOperation(op1), StopCountingOperation(op2))
57+ }" ,
58+ & Value :: Tuple ( [ Value :: Int ( 3 ) , Value :: Int ( 1 ) ] . into ( ) ) ,
59+ ) ;
60+ }
61+
62+ #[ test]
63+ fn check_start_stop_counting_operation_called_0_times ( ) {
64+ test_expression (
65+ "{
66+ import Microsoft.Quantum.Diagnostics.StartCountingOperation;
67+ import Microsoft.Quantum.Diagnostics.StopCountingOperation;
68+
69+ operation op1() : Unit {}
70+ operation op2() : Unit { op1(); }
71+ StartCountingOperation(op1);
72+ StartCountingOperation(op2);
73+ (StopCountingOperation(op1), StopCountingOperation(op2))
74+ }" ,
75+ & Value :: Tuple ( [ Value :: Int ( 0 ) , Value :: Int ( 0 ) ] . into ( ) ) ,
76+ ) ;
77+ }
78+
79+ #[ test]
80+ fn check_stop_counting_operation_without_start ( ) {
81+ test_expression (
82+ "{
83+ import Microsoft.Quantum.Diagnostics.StopCountingOperation;
84+
85+ operation op1() : Unit {}
86+ StopCountingOperation(op1)
87+ }" ,
88+ & Value :: Int ( -1 ) ,
89+ ) ;
90+ }
91+
92+ #[ test]
93+ fn check_counting_operation_differentiates_between_body_adj_ctl ( ) {
94+ test_expression (
95+ "{
96+ import Microsoft.Quantum.Diagnostics.StartCountingOperation;
97+ import Microsoft.Quantum.Diagnostics.StopCountingOperation;
98+
99+ operation op1() : Unit is Adj + Ctl {}
100+ StartCountingOperation(op1);
101+ StartCountingOperation(Adjoint op1);
102+ StartCountingOperation(Controlled op1);
103+ op1();
104+ Adjoint op1(); Adjoint op1();
105+ Controlled op1([], ()); Controlled op1([], ()); Controlled op1([], ());
106+ (StopCountingOperation(op1), StopCountingOperation(Adjoint op1), StopCountingOperation(Controlled op1))
107+ }" ,
108+ & Value :: Tuple ( [ Value :: Int ( 1 ) , Value :: Int ( 2 ) , Value :: Int ( 3 ) ] . into ( ) ) ,
109+ ) ;
110+ }
111+
112+ #[ test]
113+ fn check_start_stop_counting_function_called_3_times ( ) {
114+ test_expression (
115+ "{
116+ import Microsoft.Quantum.Diagnostics.StartCountingFunction;
117+ import Microsoft.Quantum.Diagnostics.StopCountingFunction;
118+
119+ function f1() : Unit {}
120+ function f2() : Unit { f1(); }
121+ StartCountingFunction(f1);
122+ StartCountingFunction(f2);
123+ f1(); f1(); f2();
124+ (StopCountingFunction(f1), StopCountingFunction(f2))
125+ }" ,
126+ & Value :: Tuple ( [ Value :: Int ( 3 ) , Value :: Int ( 1 ) ] . into ( ) ) ,
127+ ) ;
128+ }
129+
130+ #[ test]
131+ fn check_start_stop_counting_function_called_0_times ( ) {
132+ test_expression (
133+ "{
134+ import Microsoft.Quantum.Diagnostics.StartCountingFunction;
135+ import Microsoft.Quantum.Diagnostics.StopCountingFunction;
136+
137+ function f1() : Unit {}
138+ function f2() : Unit { f1(); }
139+ StartCountingFunction(f1);
140+ StartCountingFunction(f2);
141+ (StopCountingFunction(f1), StopCountingFunction(f2))
142+ }" ,
143+ & Value :: Tuple ( [ Value :: Int ( 0 ) , Value :: Int ( 0 ) ] . into ( ) ) ,
144+ ) ;
145+ }
146+
147+ #[ test]
148+ fn check_stop_counting_function_without_start ( ) {
149+ test_expression (
150+ "{
151+ import Microsoft.Quantum.Diagnostics.StopCountingFunction;
152+
153+ function f1() : Unit {}
154+ StopCountingFunction(f1)
155+ }" ,
156+ & Value :: Int ( -1 ) ,
157+ ) ;
158+ }
0 commit comments