/test/lib/storage/collection/test_index_of2.e
Specman e | 146 lines | 117 code | 4 blank | 25 comment | 0 complexity | 216d5fa8a8151045a1fd43d0ed58ee66 MD5 | raw file
1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries. 2-- See the Copyright notice at the end of this file. 3-- 4class TEST_INDEX_OF2 5 6insert 7 EIFFELTEST_TOOLS 8 9create {} 10 make 11 12feature {ANY} 13 make 14 local 15 collection: COLLECTION[CHARACTER] 16 do 17 collection := {FAST_ARRAY[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> } 18 assert(collection.index_of('a', 0) = 0) 19 assert(collection.index_of('a', 1) = 2) 20 assert(collection.index_of('a', 2) = 2) 21 assert(collection.index_of('a', 3) = 5) 22 assert(collection.fast_index_of('a', 0) = 0) 23 assert(collection.fast_index_of('a', 1) = 2) 24 assert(collection.fast_index_of('a', 2) = 2) 25 assert(collection.fast_index_of('a', 3) = 5) 26 assert(collection.fast_last_index_of('b') = 4) 27 assert(collection.last_index_of('b') = 4) 28 assert(collection.fast_last_index_of('a') = 2) 29 assert(collection.last_index_of('a') = 2) 30 assert(collection.fast_reverse_index_of('b', 3) = 3) 31 assert(collection.reverse_index_of('b', 3) = 3) 32 assert(collection.fast_reverse_index_of('a', 0) = 0) 33 assert(collection.reverse_index_of('a', 0) = 0) 34 assert(collection.fast_last_index_of('c') = -1) 35 assert(collection.last_index_of('c') = -1) 36 assert(collection.fast_reverse_index_of('c', 0) = -1) 37 assert(collection.reverse_index_of('c', 0) = -1) 38 -- 39 collection := {ARRAY[CHARACTER] 0, << 'a', 'b', 'a', 'b', 'b' >> } 40 assert(collection.index_of('a', 0) = 0) 41 assert(collection.index_of('a', 1) = 2) 42 assert(collection.index_of('a', 2) = 2) 43 assert(collection.index_of('a', 3) = 5) 44 assert(collection.fast_index_of('a', 0) = 0) 45 assert(collection.fast_index_of('a', 1) = 2) 46 assert(collection.fast_index_of('a', 2) = 2) 47 assert(collection.fast_index_of('a', 3) = 5) 48 assert(collection.fast_last_index_of('b') = 4) 49 assert(collection.last_index_of('b') = 4) 50 assert(collection.fast_last_index_of('a') = 2) 51 assert(collection.last_index_of('a') = 2) 52 assert(collection.fast_reverse_index_of('b', 3) = 3) 53 assert(collection.reverse_index_of('b', 3) = 3) 54 assert(collection.fast_reverse_index_of('a', 0) = 0) 55 assert(collection.reverse_index_of('a', 0) = 0) 56 assert(collection.fast_last_index_of('c') = -1) 57 assert(collection.last_index_of('c') = -1) 58 assert(collection.fast_reverse_index_of('c', 0) = -1) 59 assert(collection.reverse_index_of('c', 0) = -1) 60 -- 61 collection := {RING_ARRAY[CHARACTER] 0, << 'a', 'b', 'a', 'b', 'b' >> } 62 assert(collection.index_of('a', 0) = 0) 63 assert(collection.index_of('a', 1) = 2) 64 assert(collection.index_of('a', 2) = 2) 65 assert(collection.index_of('a', 3) = 5) 66 assert(collection.fast_index_of('a', 0) = 0) 67 assert(collection.fast_index_of('a', 1) = 2) 68 assert(collection.fast_index_of('a', 2) = 2) 69 assert(collection.fast_index_of('a', 3) = 5) 70 assert(collection.fast_last_index_of('b') = 4) 71 assert(collection.last_index_of('b') = 4) 72 assert(collection.fast_last_index_of('a') = 2) 73 assert(collection.last_index_of('a') = 2) 74 assert(collection.fast_reverse_index_of('b', 3) = 3) 75 assert(collection.reverse_index_of('b', 3) = 3) 76 assert(collection.fast_reverse_index_of('a', 0) = 0) 77 assert(collection.reverse_index_of('a', 0) = 0) 78 assert(collection.fast_last_index_of('c') = -1) 79 assert(collection.last_index_of('c') = -1) 80 assert(collection.fast_reverse_index_of('c', 0) = -1) 81 assert(collection.reverse_index_of('c', 0) = -1) 82 -- 83 collection := {LINKED_LIST[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> } 84 assert(collection.index_of('a', 1) = 1) 85 assert(collection.index_of('a', 2) = 3) 86 assert(collection.index_of('a', 3) = 3) 87 assert(collection.index_of('a', 4) = 6) 88 assert(collection.fast_index_of('a', 1) = 1) 89 assert(collection.fast_index_of('a', 2) = 3) 90 assert(collection.fast_index_of('a', 3) = 3) 91 assert(collection.fast_index_of('a', 4) = 6) 92 assert(collection.fast_last_index_of('b') = 5) 93 assert(collection.last_index_of('b') = 5) 94 assert(collection.fast_last_index_of('a') = 3) 95 assert(collection.last_index_of('a') = 3) 96 assert(collection.fast_reverse_index_of('b', 4) = 4) 97 assert(collection.reverse_index_of('b', 4) = 4) 98 assert(collection.fast_reverse_index_of('a', 1) = 1) 99 assert(collection.reverse_index_of('a', 1) = 1) 100 assert(collection.fast_last_index_of('c') = 0) 101 assert(collection.last_index_of('c') = 0) 102 assert(collection.fast_reverse_index_of('c', 1) = 0) 103 assert(collection.reverse_index_of('c', 1) = 0) 104 -- 105 collection := {TWO_WAY_LINKED_LIST[CHARACTER] << 'a', 'b', 'a', 'b', 'b' >> } 106 assert(collection.index_of('a', 1) = 1) 107 assert(collection.index_of('a', 2) = 3) 108 assert(collection.index_of('a', 3) = 3) 109 assert(collection.index_of('a', 4) = 6) 110 assert(collection.fast_index_of('a', 1) = 1) 111 assert(collection.fast_index_of('a', 2) = 3) 112 assert(collection.fast_index_of('a', 3) = 3) 113 assert(collection.fast_index_of('a', 4) = 6) 114 assert(collection.fast_last_index_of('b') = 5) 115 assert(collection.last_index_of('b') = 5) 116 assert(collection.fast_last_index_of('a') = 3) 117 assert(collection.last_index_of('a') = 3) 118 assert(collection.fast_reverse_index_of('b', 4) = 4) 119 assert(collection.reverse_index_of('b', 4) = 4) 120 assert(collection.fast_reverse_index_of('a', 1) = 1) 121 assert(collection.reverse_index_of('a', 1) = 1) 122 assert(collection.fast_last_index_of('c') = 0) 123 assert(collection.last_index_of('c') = 0) 124 assert(collection.fast_reverse_index_of('c', 1) = 0) 125 assert(collection.reverse_index_of('c', 1) = 0) 126 end 127 128end -- class TEST_INDEX_OF2 129-- 130-- ------------------------------------------------------------------------------------------------------------------------------ 131-- Copyright notice below. Please read. 132-- 133-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 134-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 135-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 136-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 137-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 138-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 139-- 140-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 141-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 142-- 143-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 144-- 145-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 146-- ------------------------------------------------------------------------------------------------------------------------------