File indexing completed on 2024-04-14 15:50:45
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #include <qtcurve-utils/utils.h> 0023 #include <assert.h> 0024 0025 static int ordered_int[1024]; 0026 0027 static int 0028 compare_int(const void *_left, const void *_right) 0029 { 0030 const int *left = (const int*)_left; 0031 const int *right = (const int*)_right; 0032 return (*left) - (*right); 0033 } 0034 0035 int 0036 main() 0037 { 0038 ordered_int[0] = 0; 0039 for (int i = 1;i < 1024;i++) { 0040 ordered_int[i] = ordered_int[i - 1] + i + (i * i * i - i * i + i) % 100; 0041 } 0042 for (int i = -100;i < ordered_int[1023] + 100;i++) { 0043 int *p = (int*)qtcBSearch(&i, ordered_int, 1024, 0044 sizeof(int), compare_int); 0045 assert(p >= ordered_int && p <= ordered_int + 1024); 0046 if (p == ordered_int) { 0047 assert(i <= ordered_int[0]); 0048 } else if (p == ordered_int + 1024) { 0049 assert(i > ordered_int[1023]); 0050 } else { 0051 assert(i <= *p && i > *(p - 1)); 0052 } 0053 } 0054 return 0; 0055 }