microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-wasm-logging-issue

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

katas/content/complex_arithmetic/complex_powers_real/Verification.qs

35lines · modecode

1namespace Kata.Verification {
2 import Std.Convert.*;
3 import Std.Math.*;
4 import Std.Random.*;
5
6 function ComplexExpReal_Reference(r : Double, x : Complex) : Complex {
7 if AbsD(r) < 1e-9 {
8 return Complex(0., 0.);
9 }
10 let real = r^x.Real * Cos(x.Imag * Log(r));
11 let imaginary = r^x.Real * Sin(x.Imag * Log(r));
12 return Complex(real, imaginary);
13 }
14
15 @EntryPoint()
16 operation CheckSolution() : Bool {
17 for ind in 0..24 {
18 let x = DrawRandomComplex();
19 let r = ind == 0 ? 0.0 | DrawRandomDouble(0., 10.);
20
21 let expected = ComplexExpReal_Reference(r, x);
22 let actual = Kata.ComplexExpReal(r, x);
23
24 if not ComplexEqual(expected, actual) {
25 let precision = 3;
26 Message("Incorrect");
27 Message($"For x = {ComplexAsString(x)} and r = {DoubleAsStringWithPrecision(r, precision)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}.");
28 return false;
29 }
30 }
31
32 Message("Correct!");
33 return true;
34 }
35}
36