Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // 3. Neither the name of the copyright holder nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 27 | |
dan sinclair | 352f8c8 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 28 | #include "src/tint/lang/core/constant/splat.h" |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 29 | |
Ben Clayton | d368f2c | 2023-08-01 00:37:35 +0000 | [diff] [blame] | 30 | #include "src/tint/lang/core/constant/helper_test.h" |
dan sinclair | 352f8c8 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 31 | #include "src/tint/lang/core/constant/scalar.h" |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 32 | |
dan sinclair | 464b3b8 | 2023-08-09 14:14:28 +0000 | [diff] [blame] | 33 | namespace tint::core::constant { |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 34 | namespace { |
| 35 | |
dan sinclair | ce6dffe | 2023-08-14 21:01:40 +0000 | [diff] [blame] | 36 | using namespace tint::core::number_suffixes; // NOLINT |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 37 | |
| 38 | using ConstantTest_Value = TestHelper; |
| 39 | |
| 40 | TEST_F(ConstantTest_Value, Equal_Scalar_Scalar) { |
| 41 | EXPECT_TRUE(constants.Get(10_i)->Equal(constants.Get(10_i))); |
| 42 | EXPECT_FALSE(constants.Get(10_i)->Equal(constants.Get(20_i))); |
| 43 | EXPECT_FALSE(constants.Get(20_i)->Equal(constants.Get(10_i))); |
| 44 | |
| 45 | EXPECT_TRUE(constants.Get(10_u)->Equal(constants.Get(10_u))); |
| 46 | EXPECT_FALSE(constants.Get(10_u)->Equal(constants.Get(20_u))); |
| 47 | EXPECT_FALSE(constants.Get(20_u)->Equal(constants.Get(10_u))); |
| 48 | |
| 49 | EXPECT_TRUE(constants.Get(10_f)->Equal(constants.Get(10_f))); |
| 50 | EXPECT_FALSE(constants.Get(10_f)->Equal(constants.Get(20_f))); |
| 51 | EXPECT_FALSE(constants.Get(20_f)->Equal(constants.Get(10_f))); |
| 52 | } |
| 53 | |
| 54 | TEST_F(ConstantTest_Value, Equal_Splat_Splat) { |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 55 | auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 56 | |
| 57 | auto* vec3f_1_1_1 = constants.Splat(vec3f, constants.Get(1_f), 3); |
| 58 | auto* vec3f_2_2_2 = constants.Splat(vec3f, constants.Get(2_f), 3); |
| 59 | |
| 60 | EXPECT_TRUE(vec3f_1_1_1->Equal(vec3f_1_1_1)); |
| 61 | EXPECT_FALSE(vec3f_2_2_2->Equal(vec3f_1_1_1)); |
| 62 | EXPECT_FALSE(vec3f_1_1_1->Equal(vec3f_2_2_2)); |
| 63 | } |
| 64 | |
| 65 | TEST_F(ConstantTest_Value, Equal_Composite_Composite) { |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 66 | auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 67 | |
| 68 | auto* vec3f_1_1_2 = constants.Composite( |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 69 | vec3f, Vector{constants.Get(1_f), constants.Get(1_f), constants.Get(2_f)}); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 70 | auto* vec3f_1_2_1 = constants.Composite( |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 71 | vec3f, Vector{constants.Get(1_f), constants.Get(2_f), constants.Get(1_f)}); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 72 | |
| 73 | EXPECT_TRUE(vec3f_1_1_2->Equal(vec3f_1_1_2)); |
| 74 | EXPECT_FALSE(vec3f_1_2_1->Equal(vec3f_1_1_2)); |
| 75 | EXPECT_FALSE(vec3f_1_1_2->Equal(vec3f_1_2_1)); |
| 76 | } |
| 77 | |
| 78 | TEST_F(ConstantTest_Value, Equal_Splat_Composite) { |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 79 | auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 80 | |
| 81 | auto* vec3f_1_1_1 = constants.Splat(vec3f, constants.Get(1_f), 3); |
| 82 | auto* vec3f_1_2_1 = constants.Composite( |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 83 | vec3f, Vector{constants.Get(1_f), constants.Get(2_f), constants.Get(1_f)}); |
Ben Clayton | 8291959 | 2023-06-01 13:44:02 +0000 | [diff] [blame] | 84 | |
| 85 | EXPECT_TRUE(vec3f_1_1_1->Equal(vec3f_1_1_1)); |
| 86 | EXPECT_FALSE(vec3f_1_2_1->Equal(vec3f_1_1_1)); |
| 87 | EXPECT_FALSE(vec3f_1_1_1->Equal(vec3f_1_2_1)); |
| 88 | } |
| 89 | |
| 90 | } // namespace |
dan sinclair | 464b3b8 | 2023-08-09 14:14:28 +0000 | [diff] [blame] | 91 | } // namespace tint::core::constant |