#pragma rtGlobals=3 // Use modern global access method and strict wave access. #pragma IgorVersion = 6.1 #pragma ModuleName = PearlAreaProfilesTest #pragma version = 1.02 #include "pearl-area-profiles" #include "unit-testing" /// @file /// @brief test suite for pearl-area-profiles.ipf /// /// unit testing framework: http://www.igorexchange.com/project/unitTesting. /// run all test cases with RunTest("pearl-area-profiles-test.ipf"). /// if wave equalities fail, EnableDebugOutput() and read Igor help on equalWaves(). /// /// @author matthias muntwiler, matthias.muntwiler@psi.ch /// /// @copyright 2013-15 Paul Scherrer Institut @n /// Licensed under the Apache License, Version 2.0 (the "License"); @n /// you may not use this file except in compliance with the License. @n /// You may obtain a copy of the License at /// http://www.apache.org/licenses/LICENSE-2.0 /// @namespace PearlAreaProfilesTest /// @brief profile extraction for multi-dimensional datasets acquired from area detectors. /// /// PearlAreaProfilesTest is declared in @ref pearl-area-profiles-test.ipf. /// /// test the ad_profile_x() function static function test_ad_profile_x_w() make /n=(11,21) /d /free source setscale /p x 10, 1, "X", source setscale /p y 100, 100, "Y", source setscale d 0, 0, "D", source source = x + y make /n=11 /d /free expected setscale /p x 10, 1, "X", expected setscale d 0, 0, "D", expected expected = 30 + 3 * p + 500 + 600 + 700 make /n=1 /d /free result1, result0 variable p1, p2 p1 = 4 p2 = 6 ad_profile_x_w(source, p1, p2, result1, noavg=1) CHECK_EQUAL_WAVES(result1, expected, tol=1e-6) expected /= 3 ad_profile_x_w(source, p1, p2, result0, noavg=0) CHECK_EQUAL_WAVES(result0, expected, tol=1e-6) end /// test the ad_profile_y() function static function test_ad_profile_y_w() make /n=(11,21) /d /free source setscale /p x 10, 1, "X", source setscale /p y 100, 100, "Y", source setscale d 0, 0, "D", source source = x + y make /n=21 /d /free expected setscale /p x 100, 100, "Y", expected setscale d 0, 0, "D", expected expected = 3 * x + 14 + 15 + 16 make /n=1 /d /free result1, result0 variable p1, p2 p1 = 4 p2 = 6 ad_profile_y_w(source, p1, p2, result1, noavg=1) CHECK_EQUAL_WAVES(result1, expected) expected /= 3 ad_profile_y_w(source, p1, p2, result0, noavg=0) CHECK_EQUAL_WAVES(result0, expected) end /// test the ad_extract_slab_x() function static function test_ad_extract_slab_x() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z source[4][][] = 1 source[5][][] = 1 make /n=(ny,nz) /d /free expected setscale /i x -2, 2, "Y", expected setscale /i y -3, 3, "Z", expected setscale d 0, 0, "D", expected expected = 2 variable p1, p2 p1 = 4 p2 = 5 wave result = ad_extract_slab_x(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) expected = 1 wave result = ad_extract_slab_x(source, p1, p2, "", noavg=0) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = -inf p2 = 5 source = y + z expected = (x + y) * 6 wave result = ad_extract_slab_x(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = 4 p2 = +inf expected = (x + y) * (nx - 4) wave result = ad_extract_slab_x(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_slab_y() function static function test_ad_extract_slab_y() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z source[][4][] = 1 source[][5][] = 1 make /n=(nx,nz) /d /free expected setscale /i x -1, 1, "X", expected setscale /i y -3, 3, "Z", expected setscale d 0, 0, "D", expected expected = 2 variable p1, p2 p1 = 4 p2 = 5 wave result = ad_extract_slab_y(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) expected = 1 wave result = ad_extract_slab_y(source, p1, p2, "", noavg=0) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = -inf p2 = 5 source = x + z expected = (x + y) * 6 wave result = ad_extract_slab_y(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = 4 p2 = +inf expected = (x + y) * (ny - 4) wave result = ad_extract_slab_y(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_slab_z() function static function test_ad_extract_slab_z() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z source[][][4] = 1 source[][][5] = 1 make /n=(nx,ny) /d /free expected setscale /i x -1, 1, "X", expected setscale /i y -2, 2, "Y", expected setscale d 0, 0, "D", expected expected = 2 variable p1, p2 p1 = 4 p2 = 5 wave result = ad_extract_slab_z(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) expected = 1 wave result = ad_extract_slab_z(source, p1, p2, "", noavg=0) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = -inf p2 = 5 source = x + y expected = (x + y) * 6 wave result = ad_extract_slab_z(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) p1 = 4 p2 = +inf expected = (x + y) * (nz - 4) wave result = ad_extract_slab_z(source, p1, p2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_slab() function static function test_ad_extract_slab() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z variable x1, x2 variable y1, y2 variable z1, z2 make /n=(ny,nz) /d /free expected setscale /i x -2, 2, "Y", expected setscale /i y -3, 3, "Z", expected setscale d 0, 0, "D", expected x1 = 0 x2 = 0 y1 = nan y2 = nan z1 = nan z2 = nan expected = source[(nx-1)/2][p][q] wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) x1 = -inf x2 = inf expected = (x + y) * nx wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) make /n=(nx,nz) /d /free expected setscale /i x -1, 1, "X", expected setscale /i y -3, 3, "Z", expected setscale d 0, 0, "D", expected x1 = nan x2 = nan y1 = 0 y2 = 0 z1 = nan z2 = nan expected = source[p][(ny-1)/2][q] wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) y1 = -inf y2 = +inf expected = (x + y) * ny wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) make /n=(nx,ny) /d /free expected setscale /i x -1, 1, "X", expected setscale /i y -2, 2, "Y", expected setscale d 0, 0, "D", expected x1 = nan x2 = nan y1 = nan y2 = nan z1 = 0 z2 = 0 expected = source[p][q][(nz-1)/2] wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) z1 = -inf z2 = inf expected = (x + y) * nz wave result = ad_extract_slab(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_rod_x() function static function test_ad_extract_rod_x() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z source[][4][4] = 1 source[][4][5] = 1 source[][5][4] = 1 source[][5][5] = 1 make /n=(nx) /d /free expected setscale /i x -1, 1, "X", expected setscale d 0, 0, "D", expected expected = 4 variable q1, q2 variable r1, r2 q1 = 4 q2 = 5 r1 = 4 r2 = 5 wave result = ad_extract_rod_x(source, q1, q2, r1, r2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) expected = 1 wave result = ad_extract_rod_x(source, q1, q2, r1, r2, "", noavg=0) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_rod() function, X coordinate static function test_ad_extract_rod__x() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z variable x1, x2 variable y1, y2 variable z1, z2 make /n=(nx) /d /free expected setscale /i x -1, 1, "X", expected setscale d 0, 0, "D", expected x1 = nan x2 = nan y1 = 0 y2 = 0 z1 = 0 z2 = 0 expected = source[p][(ny-1)/2][(nz-1)/2] wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) y1 = -inf y2 = +inf z1 = -inf z2 = +inf expected = x * ny * nz wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_rod() function, Y coordinate static function test_ad_extract_rod__y() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z variable x1, x2 variable y1, y2 variable z1, z2 make /n=(ny) /d /free expected setscale /i x -2, 2, "Y", expected setscale d 0, 0, "D", expected x1 = 0 x2 = 0 y1 = nan y2 = nan z1 = 0 z2 = 0 expected = source[(nx-1)/2][p][(nz-1)/2] wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) x1 = -inf x2 = +inf z1 = -inf z2 = +inf expected = x * nx * nz wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end /// test the ad_extract_rod() function, Z coordinate static function test_ad_extract_rod__z() variable nx = 11 variable ny = 16 variable nz = 21 make /n=(nx,ny,nz) /d /free source setscale /i x -1, 1, "X", source setscale /i y -2, 2, "Y", source setscale /i z -3, 3, "Z", source setscale d 0, 0, "D", source source = x + y + z variable x1, x2 variable y1, y2 variable z1, z2 make /n=(nz) /d /free expected setscale /i x -3, 3, "Z", expected setscale d 0, 0, "D", expected x1 = 0 x2 = 0 y1 = 0 y2 = 0 z1 = nan z2 = nan expected = source[(nx-1)/2][(ny-1)/2][p] wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) x1 = -inf x2 = +inf y1 = -inf y2 = +inf expected = x * nx * ny wave result = ad_extract_rod(source, x1, x2, y1, y2, z1, z2, "", noavg=1) CHECK_EQUAL_WAVES(result, expected, tol=0.001) end