* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#include <cmath>
#include <random>
#include "gtest/gtest.h"
#include "tikicpulib.h"
#include "test_api_utils.h"
#include "logical_not.h"
using namespace AscendC;
inline uint8_t LogicalNotSrcGenUInt8(const int index) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 1);
int randNum = dis(gen);
return randNum != 0;
}
inline uint8_t LogicalNotExpectGenUInt8(const uint8_t x) {
return !x;
}
inline bool LogicalNotCompareGenUInt8(const uint8_t expect, const uint8_t actual) {
return expect == actual;
}
class TestApiLogicalNot8 : public testing::Test, public testing::WithParamInterface<size_t> {};
TEST_P(TestApiLogicalNot8, Calc) {
int size = this->GetParam();
UnaryTest<uint8_t, half>(size, LogicalNot<uint8_t>, LogicalNotExpectGenUInt8, LogicalNotSrcGenUInt8,
LogicalNotCompareGenUInt8);
}
INSTANTIATE_TEST_SUITE_P(DiffLength, TestApiLogicalNot8,
::testing::Values(
ONE_BLK_SIZE / sizeof(uint8_t),
ONE_REPEAT_BYTE_SIZE / sizeof(uint8_t),
MAX_REPEAT_NUM *ONE_REPEAT_BYTE_SIZE / sizeof(uint8_t),
(ONE_BLK_SIZE - sizeof(uint8_t)) / sizeof(uint8_t),
(ONE_REPEAT_BYTE_SIZE - ONE_BLK_SIZE) / sizeof(uint8_t),
(MAX_REPEAT_NUM - 1) * ONE_REPEAT_BYTE_SIZE / sizeof(uint8_t),
((MAX_REPEAT_NUM - 1) * ONE_REPEAT_BYTE_SIZE + (ONE_REPEAT_BYTE_SIZE - ONE_BLK_SIZE) +
(ONE_BLK_SIZE - sizeof(uint8_t))) /
sizeof(uint8_t)));
inline int64_t LogicalNotSrcGenInt64(const int index) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 1);
int randNum = dis(gen);
return randNum;
}
inline int64_t LogicalNotExpectGenInt64(const int64_t x) {
return !x;
}
inline bool LogicalNotCompareGenInt64(const int64_t expect, const int64_t actual) {
return expect == actual;
}
class TestApiLogicalNotInt64 : public testing::Test, public testing::WithParamInterface<size_t> {};
TEST_P(TestApiLogicalNotInt64, Calc) {
int size = this->GetParam();
UnaryTest<int64_t, half>(size, LogicalNot<int64_t>, LogicalNotExpectGenInt64, LogicalNotSrcGenInt64,
LogicalNotCompareGenInt64);
}
INSTANTIATE_TEST_SUITE_P(DiffLength, TestApiLogicalNotInt64,
::testing::Values(
ONE_BLK_SIZE / sizeof(int64_t),
ONE_REPEAT_BYTE_SIZE / sizeof(int64_t),
MAX_REPEAT_NUM *ONE_REPEAT_BYTE_SIZE / sizeof(int64_t),
(ONE_BLK_SIZE - sizeof(int64_t)) / sizeof(int64_t),
(ONE_REPEAT_BYTE_SIZE - ONE_BLK_SIZE) / sizeof(int64_t),
(MAX_REPEAT_NUM - 1) * ONE_REPEAT_BYTE_SIZE / sizeof(int64_t),
((MAX_REPEAT_NUM - 1) * ONE_REPEAT_BYTE_SIZE + (ONE_REPEAT_BYTE_SIZE - ONE_BLK_SIZE) +
(ONE_BLK_SIZE - sizeof(int64_t))) /sizeof(int64_t)));