/test/lib/storage/dictionary/bijective_dictionary_tester.e
Specman e | 247 lines | 196 code | 28 blank | 23 comment | 2 complexity | 8231fe3ba02bccdb9981e504ba748d8c 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 BIJECTIVE_DICTIONARY_TESTER[V_, K_] 5 6inherit 7 BIJECTIVE_DICTIONARY[V_, K_] 8 9insert 10 EIFFELTEST_TOOLS 11 undefine is_equal 12 end 13 14create {ANY} 15 test 16 17feature {ANY} 18 reference_at (k: K_): V_ 19 do 20 Result := tested.reference_at(k) 21 assert(Result = ref.reference_at(k)) 22 end 23 24 fast_reference_at (k: K_): V_ 25 do 26 Result := tested.fast_reference_at(k) 27 assert(Result = ref.fast_reference_at(k)) 28 end 29 30 internal_key (k: K_): K_ 31 do 32 Result := tested.internal_key(k) 33 assert(Result = ref.internal_key(k)) 34 end 35 36 add (v: V_; k: K_) 37 do 38 tested.add(v, k) 39 ref.add(v, k) 40 same_dictionaries 41 end 42 43 fast_has (k: K_): BOOLEAN 44 do 45 Result := tested.fast_has(k) 46 assert(Result = ref.fast_has(k)) 47 end 48 49 has (k: K_): BOOLEAN 50 do 51 Result := tested.has(k) 52 assert(Result = ref.has(k)) 53 end 54 55 remove (k: K_) 56 do 57 tested.remove(k) 58 ref.remove(k) 59 same_dictionaries 60 end 61 62 clear_count 63 do 64 tested.clear_count 65 ref.clear_count 66 same_dictionaries 67 end 68 69 clear_count_and_capacity 70 do 71 tested.clear_count_and_capacity 72 ref.clear_count_and_capacity 73 same_dictionaries 74 end 75 76 fast_has_value (v: V_): BOOLEAN 77 local 78 i: INTEGER 79 do 80 Result := tested.has_value(v) 81 from 82 i := ref.lower 83 until 84 i > ref.upper or else v = ref.item(i) 85 loop 86 i := i + 1 87 end 88 assert(Result = (i <= ref.upper)) 89 end 90 91 capacity: INTEGER 92 do 93 Result := tested.capacity.min(ref.capacity) 94 end 95 96 key_at (v: V_): K_ 97 local 98 i: INTEGER 99 do 100 Result := tested.key_at(v) 101 from 102 i := ref.lower 103 until 104 val_safe_equal(v, ref.item(i)) 105 loop 106 i := i + 1 107 end 108 assert(Result = ref.key(i)) 109 end 110 111 fast_at (k: K_): V_ 112 do 113 Result := tested.fast_at(k) 114 assert(Result = ref.fast_at(k)) 115 end 116 117 item (i: INTEGER): V_ 118 do 119 Result := tested.item(i) 120 -- No assertion here 121 end 122 123 fast_key_at (v: V_): K_ 124 local 125 i: INTEGER 126 do 127 Result := tested.fast_key_at(v) 128 from 129 i := ref.lower 130 until 131 v = ref.item(i) 132 loop 133 i := i + 1 134 end 135 assert(Result = ref.key(i)) 136 end 137 138 put (v: V_; k: K_) 139 do 140 tested.put(v, k) 141 ref.put(v, k) 142 same_dictionaries 143 end 144 145 at (k: K_): V_ 146 do 147 Result := tested.at(k) 148 assert(Result = ref.at(k)) 149 end 150 151 key (i: INTEGER): K_ 152 do 153 Result := tested.key(i) 154 -- No assertion here 155 end 156 157 count: INTEGER 158 do 159 Result := tested.count 160 assert(Result = ref.count) 161 same_dictionaries 162 end 163 164 has_value (v: V_): BOOLEAN 165 local 166 i: INTEGER 167 do 168 Result := tested.has_value(v) 169 from 170 i := ref.lower 171 until 172 i > ref.upper or else val_safe_equal(v, ref.item(i)) 173 loop 174 i := i + 1 175 end 176 assert(Result = (i <= ref.upper)) 177 end 178 179feature {} 180 test (tested_: like tested) 181 local 182 i: INTEGER 183 do 184 tested := tested_ 185 create ref.with_capacity(tested.capacity) 186 from 187 i := tested.lower 188 until 189 i > tested.upper 190 loop 191 ref.put(tested.item(i), tested.key(i)) 192 i := i + 1 193 end 194 end 195 196 same_dictionaries 197 local 198 i: INTEGER; v: V_; k: K_ 199 do 200 assert(ref.count = tested.count) 201 from 202 i := ref.lower 203 until 204 i > ref.upper 205 loop 206 v := ref.item(i) 207 k := ref.key(i) 208 assert(tested.fast_has(k)) 209 assert(tested.fast_at(k) = v) 210 i := i + 1 211 end 212 from 213 i := tested.lower 214 until 215 i > tested.upper 216 loop 217 v := tested.item(i) 218 k := tested.key(i) 219 assert(ref.fast_has(k)) 220 assert(ref.fast_at(k) = v) 221 i := i + 1 222 end 223 end 224 225 ref: ARRAY_DICTIONARY[V_, K_] 226 227 tested: BIJECTIVE_DICTIONARY[V_, K_] 228 229end -- class BIJECTIVE_DICTIONARY_TESTER 230-- 231-- ------------------------------------------------------------------------------------------------------------------------------ 232-- Copyright notice below. Please read. 233-- 234-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 235-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 236-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 237-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 238-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 239-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 240-- 241-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 242-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 243-- 244-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 245-- 246-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 247-- ------------------------------------------------------------------------------------------------------------------------------