|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * Image processing operations for SciJava Ops. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2014 - 2024 SciJava developers. |
| 6 | + * %% |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer. |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * #L% |
| 28 | + */ |
| 29 | + |
| 30 | +package org.scijava.ops.image.filter.fftSize; |
| 31 | + |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | + |
| 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 35 | + |
| 36 | +/** |
| 37 | + * Tests {@link NextSmoothNumber}. |
| 38 | + * |
| 39 | + * @author Curtis Rueden |
| 40 | + */ |
| 41 | +public class NextSmoothNumberTest { |
| 42 | + |
| 43 | + /** Tests {@link NextSmoothNumber#nextSmooth(int)}. */ |
| 44 | + @Test |
| 45 | + public void testNextSmooth1D() { |
| 46 | + final int[] inputs = { |
| 47 | + 42, 128, 209, 432, 561, 591, 665, 686, 713, 729, |
| 48 | + 757, 832, 1018, 1218, 1250, 1328, 1392, 1539, 1779, 1874, |
| 49 | + 1951, 1989, 2154, 2219, 2324, 2326, 2439, 2440, 2495, 2812, |
| 50 | + 2902, 2919, 3289, 3417, 3490, 3612, 4009, 4084, 4139, 4180, |
| 51 | + 4183, 4201, 4440, 4568, 4594, 4838, 4842, 4845, 4878, 4989, |
| 52 | + 5016, 5035, 5109, 5148, 5215, 5367, 5469, 5699, 5971, 6039, |
| 53 | + 6101, 6109, 6174, 6187, 6314, 6342, 6359, 6585, 6661, 6827, |
| 54 | + 6851, 6930, 7277, 7392, 7409, 7620, 7635, 7726, 7820, 7886, |
| 55 | + 8138, 8775, 8798, 8820, 8853, 8862, 8885, 8987, 9020, 9038, |
| 56 | + 9069, 9081, 9130, 9148, 9546, 9607, 9650, 9885, 9923, 9981 |
| 57 | + }; |
| 58 | + final int[] expected = { |
| 59 | + 42, 128, 210, 432, 567, 600, 672, 686, 720, 729, |
| 60 | + 768, 840, 1024, 1225, 1250, 1344, 1400, 1568, 1792, 1875, |
| 61 | + 1960, 2000, 2160, 2240, 2352, 2352, 2450, 2450, 2500, 2835, |
| 62 | + 2916, 2940, 3360, 3430, 3500, 3645, 4032, 4096, 4200, 4200, |
| 63 | + 4200, 4320, 4480, 4608, 4608, 4860, 4860, 4860, 4900, 5000, |
| 64 | + 5040, 5040, 5120, 5184, 5250, 5376, 5488, 5760, 6000, 6048, |
| 65 | + 6125, 6125, 6174, 6250, 6400, 6400, 6400, 6615, 6720, 6860, |
| 66 | + 6860, 7000, 7290, 7500, 7500, 7680, 7680, 7776, 7840, 7938, |
| 67 | + 8192, 8820, 8820, 8820, 8960, 8960, 8960, 9000, 9072, 9072, |
| 68 | + 9072, 9216, 9216, 9216, 9600, 9720, 9720, 10000, 10000, 10000 |
| 69 | + }; |
| 70 | + for (int i = 0; i < inputs.length; i++) { |
| 71 | + final int actual = NextSmoothNumber.nextSmooth(inputs[i]); |
| 72 | + assertEquals(expected[i], actual); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /** Tests {@link NextSmoothNumber#nextSmooth(int, int, int)}. */ |
| 77 | + @Test |
| 78 | + public void testNextSmooth3D() { |
| 79 | + final int[] x = { |
| 80 | + 1809, 6681, 4701, 2330, 6623, 2637, 2230, 3958, 1374, 3298, |
| 81 | + 5720, 1375, 358, 8774, 8326, 6972, 7910, 3632, 3228, 2595, |
| 82 | + 7880, 3717, 4878, 7961, 435, 1378, 2558, 5327, 4823, 9292, |
| 83 | + 7539, 8962, 5656, 1646, 7069, 5303, 9173, 7478, 5852, 2905, |
| 84 | + 2426, 7301, 6535, 5383, 4041, 9962, 9008, 6550, 1040, 4145, |
| 85 | + 7949, 5159, 5675, 9109, 8618, 1630, 4913, 5943, 1971, 8664, |
| 86 | + 9460, 5874, 1702, 7326, 3289, 2837, 1389, 5427, 6016, 9236, |
| 87 | + 6226, 1071, 6709, 3316, 2979, 31, 7548, 6297, 6670, 8178, |
| 88 | + 3171, 213, 7279, 3882, 1592, 4983, 9468, 9172, 563, 6198, |
| 89 | + 3787, 348, 4471, 5953, 4562, 2634, 3017, 829, 8628, 2602 |
| 90 | + }; |
| 91 | + final int[] y = { |
| 92 | + 5770, 7708, 3112, 9152, 2137, 3957, 4198, 7004, 8913, 6933, |
| 93 | + 7133, 3864, 7889, 5170, 5136, 1876, 2074, 369, 6875, 82, |
| 94 | + 3740, 6588, 2804, 6159, 8938, 2710, 4385, 586, 7394, 8161, |
| 95 | + 1740, 7974, 3109, 2627, 6540, 9458, 6326, 1007, 6345, 3296, |
| 96 | + 9978, 2535, 1397, 9147, 3715, 935, 9642, 7978, 1234, 4340, |
| 97 | + 2683, 2521, 6255, 4219, 4323, 1168, 8480, 6526, 8124, 2916, |
| 98 | + 5035, 304, 2677, 1234, 2224, 3162, 5132, 4226, 3552, 2798, |
| 99 | + 3771, 688, 3819, 4352, 8442, 7855, 4914, 6475, 2873, 4287, |
| 100 | + 6145, 1961, 2753, 2742, 5167, 741, 5470, 1363, 5452, 5522, |
| 101 | + 2003, 9334, 8815, 7494, 4626, 4244, 8019, 2984, 9342, 5102 |
| 102 | + }; |
| 103 | + final int[] z = { |
| 104 | + 355, 8360, 6134, 9892, 6849, 6409, 9526, 8724, 3153, 3248, |
| 105 | + 2873, 9951, 4212, 9991, 3733, 1701, 8164, 7357, 8035, 583, |
| 106 | + 1986, 3635, 2238, 2183, 938, 606, 1869, 5157, 7099, 6836, |
| 107 | + 3288, 5083, 877, 8584, 3390, 5663, 3540, 9883, 6476, 7547, |
| 108 | + 602, 7064, 1649, 4338, 5537, 1090, 3398, 649, 1582, 2005, |
| 109 | + 4083, 4183, 4777, 9375, 5733, 8035, 5946, 5971, 6387, 7953, |
| 110 | + 9526, 2577, 3831, 7488, 8415, 6892, 6033, 8347, 2627, 2193, |
| 111 | + 5279, 3202, 2787, 2535, 9200, 9469, 3677, 6145, 8656, 9269, |
| 112 | + 9788, 1460, 3637, 7703, 2771, 718, 3935, 3293, 6721, 9517, |
| 113 | + 1495, 51, 4646, 1616, 5157, 9467, 8076, 4533, 6013, 4293 |
| 114 | + }; |
| 115 | + final int[] expected = { |
| 116 | + 5832, 7776, 3125, 9216, 2160, 3969, 4200, 7056, 8960, 7000, |
| 117 | + 7168, 3888, 7938, 5184, 5145, 1890, 2100, 375, 6912, 84, |
| 118 | + 3750, 6615, 2835, 6174, 8960, 2744, 4410, 588, 7500, 8192, |
| 119 | + 1750, 8000, 3125, 2646, 6561, 9600, 6400, 1008, 6400, 3360, |
| 120 | + 10000, 2560, 1400, 9216, 3750, 945, 9720, 8000, 1250, 4374, |
| 121 | + 2688, 2560, 6272, 4320, 4374, 1176, 8505, 6561, 8192, 2916, |
| 122 | + 5040, 315, 2688, 1250, 2240, 3200, 5145, 4320, 3584, 2800, |
| 123 | + 3780, 700, 3840, 4374, 8505, 7875, 5000, 6480, 2880, 4320, |
| 124 | + 6174, 2000, 2800, 2744, 5184, 750, 5488, 1372, 5488, 5600, |
| 125 | + 2016, 9375, 8820, 7500, 4704, 4320, 8064, 3000, 9375, 5103 |
| 126 | + }; |
| 127 | + for (int i = 0; i < x.length; i++) { |
| 128 | + final int actual = NextSmoothNumber.nextSmooth(x[i], y[i], z[i]); |
| 129 | + assertEquals(expected[i], actual); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
0 commit comments