blob: ad0c297219ff853f6a04aad16cff8fef1bf03e84 [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2023 The Dawn & Tint Authors
Ben Clayton82919592023-06-01 13:44:02 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
Ben Clayton82919592023-06-01 13:44:02 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
Ben Clayton82919592023-06-01 13:44:02 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 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 Clayton82919592023-06-01 13:44:02 +000027
dan sinclair352f8c82023-07-21 00:40:07 +000028#include "src/tint/lang/core/constant/splat.h"
Ben Clayton82919592023-06-01 13:44:02 +000029
Ben Claytond368f2c2023-08-01 00:37:35 +000030#include "src/tint/lang/core/constant/helper_test.h"
dan sinclair352f8c82023-07-21 00:40:07 +000031#include "src/tint/lang/core/constant/scalar.h"
Ben Clayton82919592023-06-01 13:44:02 +000032
dan sinclair464b3b82023-08-09 14:14:28 +000033namespace tint::core::constant {
Ben Clayton82919592023-06-01 13:44:02 +000034namespace {
35
dan sinclairce6dffe2023-08-14 21:01:40 +000036using namespace tint::core::number_suffixes; // NOLINT
Ben Clayton82919592023-06-01 13:44:02 +000037
38using ConstantTest_Value = TestHelper;
39
40TEST_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
54TEST_F(ConstantTest_Value, Equal_Splat_Splat) {
dan sinclaircedcdf32023-08-10 02:39:48 +000055 auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
Ben Clayton82919592023-06-01 13:44:02 +000056
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
65TEST_F(ConstantTest_Value, Equal_Composite_Composite) {
dan sinclaircedcdf32023-08-10 02:39:48 +000066 auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
Ben Clayton82919592023-06-01 13:44:02 +000067
68 auto* vec3f_1_1_2 = constants.Composite(
dan sinclairbae54e72023-07-28 15:01:54 +000069 vec3f, Vector{constants.Get(1_f), constants.Get(1_f), constants.Get(2_f)});
Ben Clayton82919592023-06-01 13:44:02 +000070 auto* vec3f_1_2_1 = constants.Composite(
dan sinclairbae54e72023-07-28 15:01:54 +000071 vec3f, Vector{constants.Get(1_f), constants.Get(2_f), constants.Get(1_f)});
Ben Clayton82919592023-06-01 13:44:02 +000072
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
78TEST_F(ConstantTest_Value, Equal_Splat_Composite) {
dan sinclaircedcdf32023-08-10 02:39:48 +000079 auto* vec3f = create<core::type::Vector>(create<core::type::F32>(), 3u);
Ben Clayton82919592023-06-01 13:44:02 +000080
81 auto* vec3f_1_1_1 = constants.Splat(vec3f, constants.Get(1_f), 3);
82 auto* vec3f_1_2_1 = constants.Composite(
dan sinclairbae54e72023-07-28 15:01:54 +000083 vec3f, Vector{constants.Get(1_f), constants.Get(2_f), constants.Get(1_f)});
Ben Clayton82919592023-06-01 13:44:02 +000084
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 sinclair464b3b82023-08-09 14:14:28 +000091} // namespace tint::core::constant