From 9244fcdbf5355a56260f1195edf0c4ec43accb7a Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Wed, 17 Jan 2024 14:45:00 -0500 Subject: [PATCH] Add more testing --- Signed-off-by: Michael Ferguson --- .../standard/AutoMath/sqrtnegparam.chpl | 4 ++ .../standard/AutoMath/sqrtnegparam.compopts | 1 + .../standard/AutoMath/sqrtnegparam.good | 4 ++ .../library/standard/AutoMath/sqrtparams.chpl | 69 +++++++++++++++++++ .../library/standard/AutoMath/sqrtparams.good | 23 +++++++ 5 files changed, 101 insertions(+) create mode 100644 test/library/standard/AutoMath/sqrtnegparam.chpl create mode 100644 test/library/standard/AutoMath/sqrtnegparam.compopts create mode 100644 test/library/standard/AutoMath/sqrtnegparam.good create mode 100644 test/library/standard/AutoMath/sqrtparams.chpl create mode 100644 test/library/standard/AutoMath/sqrtparams.good diff --git a/test/library/standard/AutoMath/sqrtnegparam.chpl b/test/library/standard/AutoMath/sqrtnegparam.chpl new file mode 100644 index 000000000000..86e9227d14ee --- /dev/null +++ b/test/library/standard/AutoMath/sqrtnegparam.chpl @@ -0,0 +1,4 @@ +sqrt(-1); +sqrt(-1.0); +sqrt(-1.0:real(64)); +sqrt(-1.0:real(32)); diff --git a/test/library/standard/AutoMath/sqrtnegparam.compopts b/test/library/standard/AutoMath/sqrtnegparam.compopts new file mode 100644 index 000000000000..417d69aab10f --- /dev/null +++ b/test/library/standard/AutoMath/sqrtnegparam.compopts @@ -0,0 +1 @@ +--ignore-errors diff --git a/test/library/standard/AutoMath/sqrtnegparam.good b/test/library/standard/AutoMath/sqrtnegparam.good new file mode 100644 index 000000000000..2d54c1a03108 --- /dev/null +++ b/test/library/standard/AutoMath/sqrtnegparam.good @@ -0,0 +1,4 @@ +sqrtnegparam.chpl:1: error: sqrt of a negative number -- cast to complex if a complex result is desired +sqrtnegparam.chpl:2: error: sqrt of a negative number -- cast to complex if a complex result is desired +sqrtnegparam.chpl:3: error: sqrt of a negative number -- cast to complex if a complex result is desired +sqrtnegparam.chpl:4: error: sqrt of a negative number -- cast to complex if a complex result is desired diff --git a/test/library/standard/AutoMath/sqrtparams.chpl b/test/library/standard/AutoMath/sqrtparams.chpl new file mode 100644 index 000000000000..3b3a77d164e4 --- /dev/null +++ b/test/library/standard/AutoMath/sqrtparams.chpl @@ -0,0 +1,69 @@ +writeln("uint cases"); +param u8one:uint(8) = 1; testsqrt(u8one); +param u16one:uint(16) = 1; testsqrt(u16one); +param u32one:uint(32) = 1; testsqrt(u32one); +param u64one:uint(64) = 1; testsqrt(u64one); +assert(sqrt(4:uint) == 2); + +writeln("int cases"); +param i8one:int(8) = 1; testsqrt(i8one); +param i16one:int(16) = 1; testsqrt(i16one); +param i32one:int(32) = 1; testsqrt(i32one); +param i64one:int(64) = 1; testsqrt(i64one); +assert(sqrt(4) == 2); + +writeln("real cases"); +param r32one:real(32) = 1.0; testsqrt(r32one); +param r64one:real(64) = 1.0; testsqrt(r64one); +assert(sqrt(4.0) == 2.0); +// note: sqrt( negative real ) gives an error +// but it can work if you cast to complex + +writeln("imag cases"); +param m32one:imag(32) = 2.0i; testsqrt2(m32one); +param m32negOne:imag(32) = -2.0i; testsqrt2(m32negOne); +param m64one:imag(64) = 2.0i; testsqrt2(m64one); +param m64negOne:imag(64) = -2.0i; testsqrt2(m64negOne); + +writeln("complex cases"); +param c64one:complex(64) = 1.0; testsqrt(c64one); +param c64negOne:complex(64) = -2.0i; testsqrt2(c64negOne); +param c128one:complex(128) = 2.0i; testsqrt2(c128one); +param c128negOne:complex(128) = -1.0; testsqrtN1(c128negOne); +assert(sqrt(4.0:complex) == 2.0:complex); + +proc testsqrt(param x) { + param p = sqrt(x); + compilerWarning("x = " + x:string + ":" + x.type:string + " sqrt = " + + p:string + ":" + p.type:string); + assert(p == 1.0); + // also check non-param version, just for good measure + var v = x; + assert(sqrt(v) == 1.0); +} + +proc testsqrtN1(param x) { + param p = sqrt(x); + compilerWarning("x = " + x:string + ":" + x.type:string + " sqrt = " + + p:string + ":" + p.type:string); + assert(p == 1.0i); + // also check non-param version, just for good measure + var v = x; + assert(sqrt(v) == 1.0i); +} + + +proc testsqrt2(param x) { + param p = sqrt(x); + compilerWarning("x = " + x:string + ":" + x.type:string + " sqrt = " + + p:string + ":" + p.type:string); + assert(abs(p.re) == 1.0); + assert(abs(p.im) == 1.0); + // also check non-param version, just for good measure + const v = x; // using lots of temporaries to avoid a compilation error + const c = sqrt(v); + const cIm = c.im; + const cRe = c.re; + assert(abs(cIm) == 1.0); + assert(abs(cRe) == 1.0); +} diff --git a/test/library/standard/AutoMath/sqrtparams.good b/test/library/standard/AutoMath/sqrtparams.good new file mode 100644 index 000000000000..9c7f6ff0f01e --- /dev/null +++ b/test/library/standard/AutoMath/sqrtparams.good @@ -0,0 +1,23 @@ +sqrtparams.chpl:2: warning: x = 1:uint(8) sqrt = 1.0:real(32) +sqrtparams.chpl:3: warning: x = 1:uint(16) sqrt = 1.0:real(32) +sqrtparams.chpl:4: warning: x = 1:uint(32) sqrt = 1.0:real(32) +sqrtparams.chpl:5: warning: x = 1:uint(64) sqrt = 1.0:real(64) +sqrtparams.chpl:9: warning: x = 1:int(8) sqrt = 1.0:real(32) +sqrtparams.chpl:10: warning: x = 1:int(16) sqrt = 1.0:real(32) +sqrtparams.chpl:11: warning: x = 1:int(32) sqrt = 1.0:real(32) +sqrtparams.chpl:12: warning: x = 1:int(64) sqrt = 1.0:real(64) +sqrtparams.chpl:16: warning: x = 1.0:real(32) sqrt = 1.0:real(32) +sqrtparams.chpl:17: warning: x = 1.0:real(64) sqrt = 1.0:real(64) +sqrtparams.chpl:23: warning: x = 2.0i:imag(32) sqrt = 1.0 + 1.0i:complex(64) +sqrtparams.chpl:24: warning: x = -2.0i:imag(32) sqrt = 1.0 - 1.0i:complex(64) +sqrtparams.chpl:25: warning: x = 2.0i:imag(64) sqrt = 1.0 + 1.0i:complex(128) +sqrtparams.chpl:26: warning: x = -2.0i:imag(64) sqrt = 1.0 - 1.0i:complex(128) +sqrtparams.chpl:29: warning: x = 1.0 + 0.0i:complex(64) sqrt = 1.0 + 0.0i:complex(64) +sqrtparams.chpl:30: warning: x = 0.0 - 2.0i:complex(64) sqrt = 1.0 - 1.0i:complex(64) +sqrtparams.chpl:31: warning: x = 0.0 + 2.0i:complex(128) sqrt = 1.0 + 1.0i:complex(128) +sqrtparams.chpl:32: warning: x = -1.0 + 0.0i:complex(128) sqrt = 0.0 + 1.0i:complex(128) +uint cases +int cases +real cases +imag cases +complex cases