1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "detector.h" 17 18 #include <iostream> 19 #include <cstdio> 20 #include <cstdlib> 21 #include <sys/stat.h> 22 23 using namespace std; 24 namespace DetectorTest { 25 const int HALF = 2; 26 const int START_INDEX = 3; 27 } 28 29 namespace { IsPrime(int n)30bool IsPrime(int n) 31 { 32 if (n <= 1) { 33 return false; 34 } 35 36 if (!(n % DetectorTest::HALF)) { 37 return n == DetectorTest::HALF; 38 } 39 40 for (int i = DetectorTest::START_INDEX;; i += DetectorTest::HALF) { 41 if (i > (n / i)) { 42 break; 43 } 44 if (!(n % i)) { 45 return false; 46 } 47 } 48 49 return true; 50 } 51 FileExist(const char* fileName)52bool FileExist(const char* fileName) 53 { 54 if (fileName == nullptr) { 55 return false; 56 } 57 struct stat myStat; 58 return (!stat(fileName, &myStat)); 59 } 60 } 61