1 /* Test of type-safe arrays that grow dynamically. 2 Copyright (C) 2021 Free Software Foundation, Inc. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2, or (at your option) 7 any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <https://www.gnu.org/licenses/>. */ 16 17 /* Written by Bruno Haible <bruno@clisp.org>, 2021. */ 18 19 #include <config.h> 20 21 #define DYNARRAY_STRUCT int_sequence 22 #define DYNARRAY_ELEMENT int 23 #define DYNARRAY_PREFIX intseq_ 24 #include "dynarray.h" 25 26 #include "macros.h" 27 28 #define N 100000 29 30 static int value_at(long long int i)31value_at (long long int i) 32 { 33 return (i % 13) + ((i * i) % 251); 34 } 35 36 int main()37main () 38 { 39 struct int_sequence s; 40 int i; 41 42 intseq_init (&s); 43 for (i = 0; i < N; i++) 44 intseq_add (&s, value_at (i)); 45 for (i = N - 1; i >= N / 2; i--) 46 { 47 ASSERT (* intseq_at (&s, i) == value_at (i)); 48 intseq_remove_last (&s); 49 } 50 intseq_free (&s); 51 52 return 0; 53 } 54